COM Automation
Navigation: User Guide ➔ COM Automation
| Command Scripts | COM Automation | Python Automation | VBA Automation | C++ Automation | Testing if SysCAD is open |
|---|
Related links: Running Cmd Prompt in Administrator Mode
Introduction
A set of COM Automation commands can be used to externally control SysCAD. This replaces or is an alternative to the Command Scripts functionality available in SysCAD with a much richer and interactive set of programming commands.
When SysCAD is installed a number of tlb files are installed and registered. These can be used to include the SysCAD Automation interface in your software development, for example with the use of Excel VBA (Visual Basic for Applications) macro's. Most software development languages such as VBA, VB, Python, C#, C++, etc. all support COM Automation. The SysCAD Automation interface can be used in a number of basic or advanced applications. A "systems integrator" can use this and other SysCAD API's to implement a wide range of simple and/or complex solutions where SysCAD is integrated with various software for use in design or operations.
The most commonly used basic commands allow you to:
- start SysCAD
- open projects
- set tags
- start the solver
- retrieve tag values
- generate reports
- close projects
Setting up SysCAD COM
The SysCAD COM interfaces should be installed and registered as part of a full SysCAD installation. Full administrator rights are required for this to be installed correctly.
The windows registry can only have one entry for the COM objects, so care should be taken if you have multiple SysCAD Builds in different folders. In the SysCAD bin folder there are a number of regall command scripts, the differences are in user feedback and/or methods of running as administrator. The RegAll.cmd version is the "silent" install and does not give error or success messages during registration. RegAll_Verbose.cmd doesn't use the silent install option (/s for regsvr32). RegAll_Direct.cmd doesn't attempt to run the script with elevated permissions.
You can use the UnRegAll_Direct.cmd to unregister the COM / OPC objects. Full administrator rights are required for this to be completed correctly.
Important notes when running command script:
- All copies of SysCAD must be closed.
- All applications that may have the SysCAD COM interface open must be closed. (For example if you have VBA macros in Excel that reference SysCAD, close Excel.)
- You need appropriate Administrator rights to update the registry. You need to run this as Administrator. Please see Running Cmd Prompt in Administrator Mode for more information.
The command script calls regsvr32 for the SysCAD COM objects, therefore you need the correct privileges to execute regsvr32.exe. The command script is performing the following (these can be entered directly in an administrator cmd window):
- regsvr32 ScdIF93.dll
- regsvr32 ScdSlv93.dll
- SysCAD93.exe /regcomserver
- regsvr32 SysCADMarshal93_ps.dll
- SysCAD93.exe /regopcserver
- ScdIODB.exe /regserver
- SysCADMarshal93.exe /regserver
- SysCAD93.exe /unregopcserver
- SysCAD93.exe /unregCOMserver
- SysCAD93.exe /unregserver
COM Registration on Windows11 (trouble shooting)
For Windows11, you will need to run RegAll_Verbose.cmd (or RegAll.cmd) as Administrator. If the steps above have failed (e.g. because of working folder or UAC) try the following:
- Press the Windows key or click the Start button.
- Type cmd
- Right click on Command Prompt app and select "Run as Administrator" from the pop up list.
- Alternatively, press < Ctrl + Shift + Enter >
- If UAC is enabled, you will be prompted with the User Account Control dialog. After completing this, the command prompt (cmd.exe) window will be opened in Administrator mode.
- In the command window, change to the SysCAD programs folder (i.e. where SysCAD.exe, RegAll.cmd, RegAll_Verbose.cmd, etc. are located. (e.g. "cd \syscadNNN\bin").
- Type RegAll_Verbose and push Enter. (i.e. running RegAll_Verbose.cmd (or RegAll.cmd) as administrator from the correct folder).
Open the application that uses SysCAD COM again. In this software where you select the references to COM objects, check that the full paths for the COM objects are correct.
For Windows 10, please see Running Cmd Prompt in Administrator Mode for more information.
Limitations
SysCAD COM Automation is designed primarily for batch scenarios or applications that fully control SysCAD. In this setup, the code or macro assumes SysCAD is not already running. It starts SysCAD, opens the required project, performs all actions, and then closes the application. This is the recommended and supported approach.
⚠️ Important: SysCAD COM Automation does not support multiple simultaneous COM sessions. Running multiple instances of SysCAD concurrently, all driven by COM, is not supported. For such use cases, command scripts combined with alternative data exchange methods (such as SetTagList and GetTagList models or text files) may offer a viable solution for managing multiple asynchronous SysCAD instances without relying on COM automation.
While it is technically possible to use COM to hook into an already open instance of SysCAD and interact with an active project, this approach requires great care and is not formally supported, use at your own risk.
NOTE: The COM Automation will try to access the report files using the "exact" path name. Therefore, if user places this file in a synced drive, the actual the path of the file could be altered, and therefore prevents the reports from working. If the COM automation is not working for you, check if the file is stored in a sync drive such as OneDrive, if so, move it out of the sync drive onto the local drive and try again.
VBA Automation Example
To use the SysCAD COM interface in VBA Macros:
- Open the "Microsoft Visual Basic" editor.
- For the VBAProject in the "References" dialog (usually under the Tools menu) select the references
- "SysCAD 9.3 Application Library" and "SysCAD 9.3 Solver Library" when using SysCAD 9.3.
- The corresponding DLL and TLB files are installed with SysCAD.
- If you have multiple copies of SysCAD installed, be sure that the correct version at the correct location is being used. See description above (Setting up SysCAD COM) for using RegAll.cmd to correct this.
An Excel VBA Macro example is shown here. See VBA Automation example.
For information on implementing code to test for an open copy of SysCAD see Testing if SysCAD is open in VBA (COM Automation).
Troubleshooting
Some notes:
- Care must be taken to call functions in an allowed and logical sequence. Perform tests as necessary.
- All SysCAD COM objects referenced should be cleared on exit. Typically in reverse order as shown in VBA Automation example.
- When running SysCAD from COM and SysCAD crashes while exiting, it may be that the project is not closed. Must call CloseProject before "Set App = Nothing" as shown in VBA Automation example.
Python Automation Examples
Some Python examples are shown here: Python Automation - Getting Started
C++ Automation Examples
A C++ example is shown here: C++ Automation Example
Distributed Example Excel VBA File
An example Excel Report using COM automation for sensitivity analysis is distributed with the Standard SysCAD install, the file can be found on
..\SysCADxxx\Examples\01 Reports\Sensitivity Analysis.xlsm
This file can be used to run a set of scenario cases and view some results. (Please note that this file is currently set up to run up to 100 cases, but user can extend this value by modifying the workbook and VBA code)
