pyplantsim documentation
Add your content using reStructuredText syntax. See the
reStructuredText
documentation for details.
- class pyplantsim.plantsim.Plantsim(version=PlantsimVersion.V_MJ_22_MI_1, visible=True, trusted=False, license=PlantsimLicense.VIEWER, suppress_3d=False, show_msg_box=False, event_polling_interval=0.05, disable_log_message=False, simulation_finished_callback=None, simtalk_msg_callback=None, fire_simtalk_msg_callback=None, simulation_error_callback=None)
Bases:
objectWrapper class for the Siemens Tecnomatix Plant Simulation COM interface.
- Variables:
_dispatch_id (str) – COM dispatch identifier for the RemoteControl interface.
_event_controller (PlantsimPath) – Path to the event controller.
_version (PlantsimVersion or str) – Plant Simulation version to be used.
_visible (bool) – Whether the instance window is visible.
_trusted (bool) – Whether the instance has access to the computer.
_license (PlantsimLicense or str) – License to be used.
_suppress_3d (bool) – Suppresses the start of the 3D view.
_show_msg_box (bool) – Whether to show a message box.
_network_path (str) – Network path.
_event_thread – Event thread object.
_event_handler (PlantSimEvents) – Handler for Plant Simulation events.
_event_polling_interval (float) – Interval for polling events.
_datetime_format (str) – Format for datetime strings.
_model_loaded (bool) – Whether a model has been loaded.
_model_path (str) – Path to the loaded model.
_running (bool) – Simulation status.
_simulation_error (Optional[dict]) – Simulation error details.
_simulation_finished_event (threading.Event) – Event triggered when the simulation finishes.
_error_handler (Optional[str]) – The path to the installed error handler.
_user_simulation_finished_cb (Optional[Callable[[], None]]) – Callback for when the simulation finishes.
_user_simtalk_msg_cb (Optional[Callable[[str], None]]) – Callback for SimTalk messages.
_user_fire_simtalk_msg_cb (Optional[Callable[[str], None]]) – Callback to fire SimTalk messages.
_user_simulation_error_cb (Optional[Callable[[SimulationException], None]]) – Callback for simulation errors.
- close_console_log_file()
Close routing to the output file.
- Return type:
None
- close_model()
Close the active model.
- Return type:
None
- execute_sim_talk(source_code, *parameters)
Execute SimTalk in the current instance and return the result.
- Parameters:
source_code (str) – The code to be executed.
parameters (any) – Parameters to pass to SimTalk.
- Returns:
Result of SimTalk execution.
- Return type:
any
- exists_path(path)
Check if the given path exists in the loaded model.
- Parameters:
path (Union[PlantsimPath, str]) – Path to check.
- Returns:
True if path exists, False otherwise.
- Return type:
bool
- Raises:
Exception – If no model is loaded.
- get_abs_sim_time()
Get the current simulation absolute time.
- Returns:
Current simulation time.
- Return type:
datetime
- Raises:
Exception – If EventController is not set.
- get_call_cycles()
- Return type:
List[CallCycle]
- get_current_process_id()
Get the ID of the current instance process.
- Returns:
Process ID.
- Return type:
int
- get_end_time()
Extract the end time of the event controller.
- Returns:
Simulation end time as timedelta.
- Return type:
timedelta
- Raises:
Exception – If EventController is not set.
- get_ids_of_names()
Get IDs of names for dispatch interface. Further documentation: https://docs.microsoft.com/en-us/windows/win32/api/oaidl/nf-oaidl-idispatch-getidsofnames
- Returns:
IDs of names.
- get_jte_export()
Get the 3D JTE export for a simulation object.
- Returns:
3D JTE export.
- get_model_language()
Get the model language.
- Returns:
Language code (0=German, 1=English, 3=Chinese).
- Return type:
int
- get_start_date()
Extract the start date from the event controller.
- Returns:
Start datetime.
- Return type:
datetime
- Raises:
Exception – If EventController is not set.
- get_table(path)
Get a DataFrame based on a Plant Simulation table object.
- Parameters:
path (str) – Path to the table.
- Returns:
DataFrame representing the table.
- Return type:
pd.DataFrame
- get_table_column_data_type(table, column)
Get the data type of a table column.
- Parameters:
table (PlantsimPath) – Table path.
column (int) – Column index.
- Returns:
Data type as string.
- Return type:
str
- get_type_info()
Get type information for the instance.
- Returns:
Type info.
- get_type_info_count()
Get the type information count.
- Returns:
Type info count.
- get_value(path)
Get the value of an attribute of a Plant Simulation object.
- Parameters:
path (str) – Path to the attribute.
- Returns:
Attribute value.
- Return type:
Any
- has_simulation_error()
Check if a simulation error has occurred.
- Returns:
True if there is an error, False otherwise.
- install_error_handler()
Install an error handler in the model file under basis.ErrorHandler. Searches for any method object and duplicates that.
- Raises:
Exception – If error handler could not be created.
- invoke()
Invoke method on the COM instance.
- property license: PlantsimLicense | str
License of the current instance.
- Returns:
License type.
- Return type:
Union[PlantsimLicense, str]
- load_model(filepath, password=None, close_other=False)
Load a model into the current instance.
- Parameters:
filepath (str) – Full path to the model file (.spp).
password (str, optional) – Password for encrypted models.
close_other (bool, optional) – Close other models before loading.
- Raises:
Exception – If file does not exist or another model is loaded.
- Return type:
None
- load_model_without_state()
Load a model without restoring state.
- property model_loaded: bool
Whether the instance has a model loaded.
- Returns:
True if model is loaded, False otherwise.
- Return type:
bool
- property model_path: str | None
Path to the current model file.
- Returns:
Model path or None.
- Return type:
Union[str, None]
- property network_path: PlantsimPath | None
Current active network path.
- Returns:
Network path or None.
- Return type:
Union[str, None]
- new_model(close_other=False)
Create a new simulation model in the current instance.
- Parameters:
close_other (bool, optional) – Close other models before creating new one.
- Return type:
None
- open_console_log_file(filepath)
Route the Console output to a file.
- Parameters:
filepath (str) – Path to the log file.
- Return type:
None
- query_interface()
Query the COM interface.
- quit()
Quit the current Plant Simulation instance.
- Raises:
Exception – If instance is already closed.
- Return type:
None
- quit_after_time(time)
Quit the current instance after a specified time.
- Parameters:
time (int) – Time in seconds after which instance quits.
- Return type:
None
- read_call_cycles(max_num_cycles=None)
- Return type:
List[CallCycle]
- register_on_fire_simtalk_message(callback)
Set callback for FireSimTalkMessage event.
- Parameters:
callback (Optional[Callable[[str], None]]) – Callback function.
- register_on_simtalk_message(callback)
Set callback for OnSimTalkMessage event.
- Parameters:
callback (Optional[Callable[[str], None]]) – Callback function.
- register_on_simulation_error(callback)
Set callback for simulation errors.
- Parameters:
callback (Optional[Callable[[SimulationException], None]]) – Callback function.
- register_on_simulation_finished(callback)
Set callback for OnSimulationFinished event.
- Parameters:
callback (Optional[Callable[[], None]]) – Callback function.
- release()
Release the COM instance.
- remove_error_handler()
Remove the installed error handler from basis.ErrorHandler.
- Raises:
Exception – If no error handler is installed or removal fails.
- reset_simulation()
Reset the simulation.
- Raises:
Exception – If EventController is not set.
- Return type:
None
- restart()
Restart the Plant Simulation instance and restore previous state.
- Raises:
NotImplementedError – Restart is not implemented.
- Return type:
None
- run_simulation(without_animation=True, on_init=None, on_endsim=None, on_simulation_error=None, on_progress=None, cancel_event=None)
Run a full simulation and return after the run is over. This method suggests, that the EventController has a EndDate
- Parameters:
without_animation (bool, optional) – Run without animation.
on_init (Optional[Callable[[Plantsim], None]]) – Callback before simulation starts.
on_endsim (Optional[Callable[[Plantsim], None]]) – Callback after simulation ends.
on_simulation_error (Optional[Callable[[Plantsim, SimulationException], None]]) – Callback on simulation error.
on_progress (Optional[Callable[[Plantsim, float], None]]) – Progress callback (receives percent complete).
cancel_event (Optional[threading.Event]) – Event to cancel the run.
- Raises:
SimulationException – If a simulation error occurs.
- Return type:
None
- save_model(folder_path, file_name)
Save the current model under the given name in the given folder.
- Parameters:
folder_path (str) – Path to the folder.
file_name (str) – Name of the model.
- Return type:
None
- set_crash_stack_file()
Set the crash stack file for error logging.
- set_event_controller(path=None)
Set the path of the Event Controller.
- Parameters:
path (str, optional) – Path to the EventController object. If not given, uses default.
- Return type:
None
- set_license(license, force=False)
Set the license for the instance.
- Parameters:
license (PlantsimLicense) – License type.
force (bool, optional) – Force update even if value is already set.
- Return type:
None
- set_network(path, set_event_controller=False, install_error_handler=False)
Set the active network.
- Parameters:
path (PlantsimPath) – Network path.
set_event_controller (bool, optional) – Whether to set the event controller.
install_error_handler (bool, optional) – Whether to install the error handler.
- Return type:
None
- set_seed(seed)
Set the random seed on the event controller.
- Parameters:
seed (int) – Seed value (-2147483647 to 2147483647).
- Raises:
Exception – If EventController is not set or seed is out of range.
- Return type:
None
- set_show_message_box(show, force=False)
Set whether the instance should show a message box.
- Parameters:
show (bool) – Show message box.
force (bool, optional) – Force update even if value is already set.
- Return type:
None
- set_stop_simulation_on_error()
Set option to stop simulation on error.
- set_suppress_start_of_3d(suppress, force=False)
Set whether to suppress the start of 3D.
- Parameters:
suppress (bool) – Suppress 3D view.
force (bool, optional) – Force update even if value is already set.
- Return type:
None
- set_table(path, df)
Set a Plant Simulation table based on a DataFrame.
- Parameters:
path (str) – Path to the table.
df (pd.DataFrame) – DataFrame containing the values to write.
- Return type:
None
- set_trust_models(trusted, force=False)
Set whether the instance has access to the computer.
- Parameters:
trusted (bool) – Trusted mode.
force (bool, optional) – Force update even if value is already set.
- Return type:
None
- set_value(path, value)
Set a value to a given attribute.
- Parameters:
path (str) – Path to the attribute.
value (any) – The new value to assign.
- Return type:
None
- set_version(version)
Set the Plant Simulation version.
- Parameters:
version (Union[PlantsimVersion, str]) – Plant Simulation version or string.
- set_visible(visible, force=False)
Set whether the instance window is visible.
- Parameters:
visible (bool) – Window visibility.
force (bool, optional) – Force update even if value is already set.
- Return type:
None
- property show_msg_box: bool
Whether the instance is showing a message box.
- Returns:
True if message box is shown, False otherwise.
- Return type:
bool
- property simulation_running: bool
Whether the simulation is currently running.
- Returns:
True if running, False otherwise.
- Return type:
bool
- start()
Start the Plant Simulation instance.
- Raises:
Exception – If Plant Simulation is already running.
- Returns:
The PlantSim instance.
- Return type:
- start_simulation(without_animation=False)
Start the simulation.
- Parameters:
without_animation (bool, optional) – Run without animation.
- Raises:
Exception – If EventController is not set.
- Return type:
None
- stop()
Stop the Plant Simulation instance and clean up resources.
- Return type:
None
- stop_simulation()
Stop the simulation.
- Raises:
Exception – If EventController is not set.
- Return type:
None
- property suppress_3d: bool
Whether suppression of 3D is enabled.
- Returns:
True if suppressed, False otherwise.
- Return type:
bool
- tranfer_model()
Transfer the model to another instance.
- property trusted: bool
Whether the instance is trusted.
- Returns:
True if trusted, False otherwise.
- Return type:
bool
- property version: Version
Version of the current instance.
- Returns:
Plant Simulation version.
- Return type:
Union[Version, str]
- property visible: bool
Whether the instance is visible.
- Returns:
True if visible, False otherwise.
- Return type:
bool