Evaluate the AutomationView desktop suite free for 30 days. No credit card required. Claim trial key →
arrow_back Back to Articles

Inside AutomationView: Using Python to Procedurally Generate Complex SFC Sequences

calendar_month
person Carvalho Raphael

Inside AutomationView: Using Python to Procedurally Generate Complex SFC Sequences

AutomationView
%%{init: {'theme':'dark', 'themeVariables': { 'background': '#001c38' }}}%%
flowchart LR
    A["Python Script"]:::blue --> B["AutomationView API"]:::green
    B --> C["Generated SFC / Grafcet"]:::red
    classDef blue fill:#2563eb,stroke:#1e40af,color:#ffffff
    classDef green fill:#16a34a,stroke:#166534,color:#ffffff
    classDef red fill:#dc2626,stroke:#991b1b,color:#ffffff
AutomationView Icon AutomationView

Generating large, highly parameterized SFC (Sequential Function Chart) sequences by hand can quickly become a bottleneck in PLC engineering. Inside AutomationView: Using Python to Procedurally Generate Complex SFC Sequences explores how to eliminate manual drafting by utilizing the AutomationView Python API to script logic programmatically.

The Paradox of Manual Sequence Design

Modern machine builders often face a frustrating paradox: despite building highly modular, scalable hardware architectures, their PLC sequence design remains entirely manual. Engineers spend hours clicking and dragging identical SFC steps, transitions, and actions to handle repetitive tasks across multiple stations or zones. This manual entry not only wastes time but also introduces critical human errors, making testing and validation significantly harder.

With AutomationView, the paradigm shifts entirely. Instead of drawing sequences manually, control engineers can write Python scripts to procedurally generate complex logic structures. This allows for parametric sequence creation—if you need to add ten more sorting stations, you simply change a loop variable in your Python script rather than redrawing hundreds of steps.

How the AutomationView Python API Works

The core concept is to treat the AutomationView Python SFC as a set of programmable objects. Every step, transition, parallel branch, and action block is accessible via the API. When the script runs, AutomationView constructs the visual SFC on the canvas dynamically.

flowchart TD
    start_node["Define Parameters (Stations, Zones)"]:::blue --> loop_node["Iterate Over Zones in Python"]:::green
    loop_node --> create_step["Create SFC Step & Action"]:::red
    create_step --> create_trans["Create SFC Transition"]:::red
    create_trans --> loop_node
    loop_node --> deploy_node["Deploy to PLC"]:::blue
    classDef blue fill:#2563eb,stroke:#1e40af,color:#ffffff
    classDef green fill:#16a34a,stroke:#166534,color:#ffffff
    classDef red fill:#dc2626,stroke:#991b1b,color:#ffffff

Step 1: Instantiating the Sequence

First, you create a new sequence object and define the entry point. The API provides methods to append steps sequentially or branch them in parallel depending on the required machine logic.

Step 2: Defining Transitions and Conditions

Transitions are assigned boolean logic conditions. Instead of typing these conditions manually, the Python script can build the expression strings based on the current iteration of the hardware array, mapping sensors directly to their respective steps.

Comparing Manual vs. Procedural Generation

Understanding the impact requires a direct comparison of the two approaches across key metrics during a machine design phase.

Metric Manual SFC Design Python Procedural Generation
Time to Scale Linear (More stations = More manual drawing) O(1) (Change a variable, instant generation)
Error Rate High (Prone to copy-paste mistakes) Low (Uniformly generated logic)
Code Review Difficult (Visual inspection required) Easy (Review the Python logic directly)
Maintainability Low (Hard to refactor large visual charts) High (Refactor the Python class structure)

Bridging Python and IEC 61131-3

The beauty of this integration is that you aren’t forced to deploy Python to the actual PLC. AutomationView takes the procedurally generated structure and compiles it down into standard IEC 61131-3 code. This ensures complete compliance with industrial standards while providing modern, high-level software engineering workflows.

Conclusion

Procedural generation of PLC logic is not just a time-saver; it represents a fundamental shift towards true software-defined automation. By leveraging the AutomationView Python API, automation teams can bring modern software development techniques into the industrial sphere, drastically reducing time-to-market for complex, highly modular machinery.

FAQ

Can I still visually edit a generated sequence?

Yes. Once the Python script builds the SFC in AutomationView, it becomes a standard visual sequence that can be manually adjusted or debugged using the step-through features.

Do I need advanced Python skills to use this feature?

A basic understanding of loops, variables, and objects is sufficient. AutomationView provides templates to help you get started quickly.

Ready to modernize your sequence design? Explore the AutomationView Store for the latest plugins and features.

Share this article

Stay Updated with AutomationView

Get the latest articles and news delivered directly to your inbox.

Log in to Subscribe

You must be registered and logged in to manage subscriptions.

Recommended for you

How to Automate PLC Documentation Generation from AutomationView SFCs

AutomationView
%%{init: {'theme':'dark', 'themeVariables': { 'background': '#001c38' }}}%%
flowchart LR
    A["AutomationView SFC"]:::blue --> B["Python Extraction Engine"]:::green
    B --> C["Automated Documentation"]:::red
    classDef blue fill:#2563eb,stroke:#fff,stroke-width:2px,color:#fff
    classDef green fill:#16a34a,stroke:#fff,stroke-width:2px,color:#fff
    classDef red fill:#dc2626,stroke:#fff,stroke-width:2px,color:#fff
AutomationView Icon AutomationView
calendar_month

How to Automate PLC Documentation Generation from AutomationView SFCs

Key Takeaways: Manual PLC documentation generation is prone to errors and quickly becomes out-of-sync with production code. AutomationView allows engineers to auto-generate comprehensive specs directly from SFC (Sequential Function Chart) and Grafcet logic. Integrating Python-based extraction tools ensures a single source of truth for both code and technical documentation. The Challenge of Keeping PLC Specs […]

Read Article arrow_forward

Inside AutomationView Fault Injection: A Technical Guide to Validating PLC Edge Cases

AutomationView
%%{init: {'theme':'dark', 'themeVariables': { 'background': '#001c38' }}}%%
flowchart LR
    A["PLC Sequence"]:::blue -->|Inject Fault| B["AutomationView Simulator"]:::green
    B -->|Analyze Response| C["Error Handling Logic"]:::red
    classDef blue fill:#2563eb,stroke:#1d4ed8,stroke-width:2px,color:#ffffff
    classDef green fill:#16a34a,stroke:#15803d,stroke-width:2px,color:#ffffff
    classDef red fill:#dc2626,stroke:#b91c1c,stroke-width:2px,color:#ffffff
AutomationView Icon AutomationView
calendar_month

Inside AutomationView Fault Injection: A Technical Guide to Validating PLC Edge Cases

In industrial control systems, a single unchecked edge case can result in catastrophic mechanical failure or prolonged downtime. Validating that a Programmable Logic Controller (PLC) responds correctly to sensor failures, communication drops, and unexpected logic states is notoriously difficult in live production environments. AutomationView Fault Injection allows control engineers to deliberately introduce errors within a […]

Read Article arrow_forward

Integrating AutomationView for Headless PLC Simulation via Docker

AutomationView
%%{init: {'theme':'dark', 'themeVariables': { 'background': '#001c38' }}}%%
flowchart LR
    A[Git Push] --> B[CI/CD Pipeline]
    B --> C[Docker: AutomationView]
    C --> D[Headless PLC Simulation]
    D --> E[Test Report]
    style C fill:#0f4c81,stroke:#fff,stroke-width:2px,color:#fff
AutomationView Icon AutomationView
calendar_month

Integrating AutomationView for Headless PLC Simulation via Docker

Key Takeaways: Running AutomationView in a headless Docker container removes hardware dependencies for CI/CD testing. Headless PLC simulation accelerates regression testing by spinning up isolated virtual runtimes. Integrating Python-based `pytest` scripts with containerized OPC UA endpoints ensures deterministic validation. The Shift Toward Virtualized Control Logic Testing Validating complex Sequential Function Charts (SFCs) on physical hardware […]

Read Article arrow_forward