SIMUL8 COM

SIMUL8's API (OLE Automation/COM/ActiveX interface).

This is a standard Windows COM interface that allows any application that can use COM to drive SIMUL8 without user intervention.

There are two different levels of COM functionality available with SIMUL8:

1. SIMUL8 Basic Edition

A COM interface that allows basic operation of SIMUL8 including opening and running simulations, running trials, extracting results etc. Both .S8 and .XML simulation files are supported.

2. SIMUL8 Professional Edition COM Interface

All of 1 plus the functionality to change simulation programmatically (for example by creating and linking simulation objects in the same way as can be done from SIMUL8's own internal Visual Logic.

(Note that SIMUL8 also supports an older style DDE/DLL interface that continues to work for back compatibility with old implementations.

How to use SIMUL8 COM

The remainder of this document is a step by step guide to using SIMUL8 Basic's COM interface.

The remainder of this document is a step by step guide to using SIMUL8 Basic's COM interface. This details instructions on driving SIMUL8 through VBA and Python. No recommendation should be implied from its use here, and SIMUL8 Corporation's Support team is not available to handle Visual Basic or Python questions! - but we will help you with this example and the COM interface, and with the use of SIMUL8 COM Interface in conjunction with various languages if requested.

VBA and SIMUL8 COM

This assumes no previous knowledge of COM or VBA but does assume some understanding of the use of Excel.

The example used here is included with this build (examples\api\com\example1.xls) but we recommend you build it yourself because there are key steps to learn in checking boxes in VBA.

In this example we use a standard S8 file and we assume you have installed SIMUL8 in the default directory. However XML files can be used with the advantage that their content can be changed under program control (by reading and writing the file to, for example, change values of variables).

Initial Set up
  • Open Excel with a blank spreadsheet
  • Ensure that the Development Tab is added to your Ribbon. You can do this through File> Options> Customise Ribbon and check “Developer” on the Main Tabs Section.
  • Ensure that macros are enabled. You can do this through File> Options> Trust Center> Trust Center Settings and select “Enable all Macros”
  • From the Insert button drop-down, in the Controls section, select an ActiveX Controls Button and drag a rectangle on the spreadsheet to create a Button (don't cover column A because we will use it later).
  • Double click the new button and you will see VBA open and place some empty code on the screen
  • In the menu on the VBA window click Tools>References
  • Find and check SIMUL8 Library
  • Click OK. Excel's VBA can now help and prompt you to get the syntax right when using SIMUL8's COM/ActiveX interface.
  • In the code window move the cursor up above the Private Sub line and type:
      Private WithEvents MYSIMUL8 As SIMUL8.S8Simulation

Let’s firstly create a button to open up SIMUL8.

  • Inside the code for the button click type:
      Set MYSIMUL8 = GetObject("", "SIMUL8.S8Simulation")

Note that the Set keyword is NOT optional here (in most VBA it is optional - but NOT here!)

  • ALT-TAB to the main part of EXCEL.
  • Save the Excel file as an .xlsm.
  • Close the Excel file
  • Click the button and SIMUL8 will start. DO NOT attempt to close SIMUL8 from the SIMUL8 Screen (Because it is not in control, Excel is)
  • ALT-TAB back to Excel
  • Use Tools>Macros>Visual Basic Editor to redisplay the VBA screen and click the RESET button. This stops your macros and closes SIMUL8 (we will next create a button to do this neatly.)
  • Navigate back to the Developer tab in Excel, and use the Insert button again to put a second button on the screen, double click it and enter this code:
  Private Sub CommandButton2_Click()
     MYSIMUL8.Open "c:\program files\simul8\examples\others\demo2.s8"
     MYSIMUL8.RunSim 2400
  End Sub
  • Put a 3rd button on the screen with this code, to close down SIMUL8 when we want to:
  Private Sub CommandButton3_Click()
     Set MYSIMUL8 = Nothing
  End Sub 

Again, the SET keyword is important.

  • Switch out of Design Mode so you can use the buttons
  • Click each button in turn to Open SIMUL8, Open a simulation and run it, Close SIMUL8.
  • Next we will add an 'Event' to your VBA so you know when the simulation run has finished and you can display some results
  • Go back to the VBA screen and select MYSIMUL8 in the left had drop down box.
  • In the right drop down box select S8SimulationEndRun


  • This code will appear:
  Private Sub MYSIMUL8_S8SimulationEndRun() 
  End Sub
  • Add these 3 extra lines between Private Sub MYSIMUL8_S8SimulationEndRun() and End Sub
Private Sub MYSIMUL8_S8SimulationEndRun() 
For n = 1 To MYSIMUL8.ResultsCount
  Worksheets("Sheet1").Cells(n, 1).Value = MYSIMUL8.Results(n).Value
Next n
End Sub

At the end of the run SIMUL8 will tell Excel the run has finished. Excel them loops through all the results on the KPI Summary and adds the results into the cells in column 1 on sheet 1

  • Go back to Excel, click button 1, then 2, then wait for SIMUL8 to finish the run. The results will appear once the run is complete.
  • Now click button 3 to close SIMUL8.
  • Try out the other methods and properties listed in the SIMUL8 COM Object simulation reference over the page.

Finally, one helpful hint

If you don't want to see SIMUL8 running put the line: MYSIMUL8.Visible = False after the Set MYSIMUL8 = GetObject(””, “SIMUL8.S8Simulation”) line

Python and SIMUL8 COM

Initial Set up

To use Python with SIMUL8, there are a few settings and packages that a user will need to install.

  • Install the 32-Bit version of Python: Since SIMUL8 is a 32-bit application, the 32-bit version of Python must be installed. Python 64-bit will not be able to recognise SIMUL8 as a COM application.
  • Install Win32Com: Users must also install Win32Com to be able to query COM applications. For seasoned Python users, this is simply a PIP installation of pywin32. Documentation on how to install Python packages can be found in Python’s own docs as well as other online resources. You will need to import this using these commands:
#initial setup win32com
Import win32com
#import client to use dispatching methods
from wind32com import client
  • Initiate makepy.py File: The Makepy.py file is a Win32Com specific file which registers and creates COM modules out of COM-enabled applications. Users have two choices when it comes to initiating this file:
  1. They can navigate to the file in their file browser, double click on the file and it will bring up the Application Library. From here, users can scroll to find “SIMUL8 Library” and then click OK. This will generate the SIMUL8 module to be used. This file will normally be found somewhere like: C:\Users\{username}\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\win32com\client or wherever the user has Python installed.
  2. The other option is that they can open their Python shell of choice (e.g. Python IDLE) and use the following commands:


This will open the same Application Library where users can click on “SIMUL8 Library”.

Python Commands

The following commands can be used for opening up SIMUL8, opening a specific file, running the simulation, and exiting SIMUL8. This was done using Python IDLE which we recommend using.

#this command opens up SIMUL8
S8 = win32com.client.Dispatch(“SIMUL8.S8Simulation ”)
#this command opens up a specific SIMUL8 file - the ‘r’ stands for 
# -raw strings which is useful when dealing with file paths
S8.Open(r”C:\Users\{username}\Documents\PythonTest.s8)
#this runs the simulation for a certain amount of time 
S8.RunSim(1000)
#this command closes SIMUL8 down
S8.Quit()