diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 952f704..2d12380 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ table = Table(plantsim, 'TableName') print(table) ``` +An example, together with a simple simulation model, can be found in [example](example/). ## Setup diff --git a/example/README.md b/example/README.md new file mode 100755 index 0000000..a6cc9d6 --- /dev/null +++ b/example/README.md @@ -0,0 +1,28 @@ +# Example + +![](network.png) + +This directory provides an example of a simple simulation to show how variables could be set, +the simulation could be controlled and results in variables and tables could be fetched. + +The simulation model was created in PlantSimulation 16.1.6. + +## Simulation model +This is a simple example of simulation model. +It's a simple source - processing - sink process, +where you can adapt the processingTime of the +station by updating the variable procTime. +On every item reaching the sink, an entry +is added to the ResultTable and ResultTable1. +Additionally, the totalSinks are counted, even +though they are equal to Senke.StatAnzahlEin. +But this is just a simple example to see how this +value can be accessed by the script. + +The variable procTimeT is currently unsued, only +for showing how to set a time value by using a +simtalk lambda function in the script. + +## Usage +Ensure you've installed the ``plantsim``-package before executing the examples, e.g. using pip. +Afterwards just run the example.py. \ No newline at end of file diff --git a/example/example.py b/example/example.py new file mode 100755 index 0000000..e17c3a0 --- /dev/null +++ b/example/example.py @@ -0,0 +1,39 @@ +import os +import time + +from plantsim.plantsim import Plantsim +from plantsim.table import Table + + +plantsim = Plantsim(version='16.1', license_type='Research')#, visible=False) +plantsim.load_model(os.getcwd() + '\model.spp') + +plantsim.set_path_context('.Modelle.Modell') + +plantsim.set_value('procTime', '30:00.00000') +# if you want to set the time as a real time you can do this by executing a +# simtalk lambda function +#plantsim.execute_simtalk("procTimeT := str_to_time(\"45:00.0\")") + +# do the simulation run +plantsim.set_event_controller() +plantsim.reset_simulation() +plantsim.start_simulation() + +# wait until the simulation has finished +while plantsim.is_simulation_running(): + time.sleep(0.1) + +# get main kpi +print("Counted sinks in totalSinks:", plantsim.get_value('totalSinks')) +print("Statistic value (parts in) of sink:", plantsim.get_value('Senke.StatAnzahlEin')) + +# print table with indexes +table = Table(plantsim, 'ResultTable') +print(table) + +# print table without index +table1 = Table(plantsim, 'ResultTable1') +print(table1) + +plantsim.quit() \ No newline at end of file diff --git a/example/model.spp b/example/model.spp new file mode 100755 index 0000000..cc3363f Binary files /dev/null and b/example/model.spp differ diff --git a/example/network.png b/example/network.png new file mode 100755 index 0000000..f64d0f7 Binary files /dev/null and b/example/network.png differ