Simio - Python Scripted Step
In Simio, you can set up a scripted step in Definitions to allow using the scripted step in processes.
Before that, set up you python installation and editor e.g. VS Code first.
Then in Simio, File -> Setting -> Scripting -> IDE, point to IDE, e.g. C:\Program Files\Microsoft VS Code\Code.exe
In Definitions, create a Scripted Step, then click Edit User Scripts in the ribbon, it will open VS Code automatically.
It seems to automatically create a python venv under User/AppData/Local/Temp/Simio/PythonScripts/ProjectName/.venv/Scripts/python.exe
This venv has all the required Simio libraries installed and compatible.
If you choose your own python venv, VS CODE likely say it's invalid interpreter.
So for extra libraries needed, just go into the default venv provided by Simio and install, e.g. from VS Code terminal, run pip install
On editing the Scripted Step, the default method has been populated:
from SimioAPI import *
from SimioAPI.Extensions import *
# called when a process token executes the step.
def Execute(propertyReaders: IPropertyReaders, context: IStepExecutionContext) -> ExitType:
context.ExecutionInformation.TraceInformation("Step: MyStep1 executed")
return ExitType.FirstExit
propertyReaders read/reference to the properties of the Scripted Step, i.e. when drag a Scripted Step into process, on the right panel it shows the step's properties.
Typically, for input and output to the Scripted Step, you need to specify them in the Scripted Step's properties under Definitions.
E.g. you need to pass ship_capacity variable in, and write ship schedules back to a output table,
then you define ship_capacity and ship_schedule in the Scripted Step.
When drag the scripted step in a process, the two properties will show in the right panel and mark as red, until you map those variables,
to existing variables e.g. spaceship_tonnes and spacex_schedules. Note scripted step can only write to state variables/columns of output table, not ordinary table.
Also a good thing is, your input output variable (parameter) is named independently and only map in the process, to model variables that can change over time.
the context parameter contains almost everything about the model.
However, to get data in and out, the syntax is always a bit confusing and there is no good Chatgpt or document references.
Below is an example of read and write tables.
def read_row(context, table_reference, row_index):
return table_reference.GetRow(row_index, context)
def read_cell_property(context, table_reference, row_index, column_name):
row = read_row(context, table_reference, row_index)
return row.Properties.GetProperty(column_name).GetStringValue(context)
def read_cell_state(context, table_reference, row_index, column_name):
row = read_row(context, table_reference, row_index)
return row.States[column_name].StateValue
# called when a process token executes the step.
def Execute(propertyReaders: IPropertyReaders, context: IStepExecutionContext) -> ExitType:
context.ExecutionInformation.TraceInformation("Step: MyStep1 executed")
tbl_product = getTableReference("ship_capacity", propertyReaders, context)
tbl_output = getTableReference("OrderTable", propertyReaders, context)
row_index = 0
tonnes = read_cell_state(context, tbl_product, row_index, 'Tonnes')
new_row = tbl_output.AddRow(context)
new_states = new_row.States
new_states["schedule"].StateValue = 'launch in december'
return ExitType.FirstExit
There are more examples from Simio in https://github.com/SimioLLC/PythonExamplesInSimio
Save the script, then you can run simio now.
Note again, the scripted step requires inputs as the step's properties and mapped in the process.
the output must be states, and output table