COM Automation

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: User Guide -> COM Automation

Related link: Running Cmd Prompt in Administrator Mode, VBA Automation example, Python Automation Examples

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:

  1. All copies of SysCAD must be closed.
  2. 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.)
  3. 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
And when using OPC with SysCAD Dynamic the following are also required:
  • regsvr32 SysCADMarshal93_ps.dll
  • SysCAD93.exe /regopcserver
  • ScdIODB.exe /regserver
  • SysCADMarshal93.exe /regserver
To unregister the OPC, COM or both servers:
  • SysCAD93.exe /unregopcserver
  • SysCAD93.exe /unregCOMserver
  • SysCAD93.exe /unregserver

COM Registration on Windows10 (trouble shooting)

For Windows10, you will need to run RegAll_Verbose.cmd (or RegAll.cmd) as Administrator. If the steps above have failed (eg because of working folder or UAC) try the following:

  • Activate App Search.
  • In the Search Apps field, type cmd, the App Command Prompt should be listed.
  • Right click on Command Prompt app and select "Run as Administrator" from the pop up list. See Running Cmd Prompt in Administrator Mode for more information.
  • 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 (ie where SysCAD.exe, RegAll.cmd, RegAll_Verbose.cmd, etc are located. (eg "cd \syscadNNN\bin").
  • Type RegAll_Verbose and push Enter. (i.e. running RegAll_Verbose.cmd (or RegAll.cmd) as administrator from the correct folder).
ComWindows10 Cmd.png

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.

COM Registration on Windows8 (trouble shooting)

For Windows8, you will need to run RegAll_Verbose.cmd (or RegAll.cmd) as Administrator. If the steps above have failed (eg because of working folder or UAC) try the following:

  • Activate App Search.
  • In the Search Apps field, type cmd, the App Command Prompt should be listed.
  • For Windows 8.0 Right click on Command Prompt app and select "Run as Administrator" from the list of actions icons on the bottom. See Running Cmd Prompt in Administrator Mode for more information.
  • For Windows 8.1 Right click on Command Prompt app and select "Run as Administrator" from the pop up list. See Running Cmd Prompt in Administrator Mode for more information.
  • 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 (ie where SysCAD.exe, RegAll.cmd, RegAll_Verbose.cmd, etc are located. (eg "cd \syscad138\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.

Limitations

The SysCAD COM Automation is designed and intended for batch scenarios or applications that completely "drive" SysCAD. Therefore the code or macro is written such that it is assumed that SysCAD is not open and the code starts SysCAD, opens projects, performs all the actions and closes. This is the recommended and supported approach.

SysCAD COM Automation does not support multiple simultaneous COM automation sessions. So running multiple instances of SysCAD instances simultaneously all driven by COM is not supported. The use of Command Scripts for multiple asynchronous instances of SysCAD can be a viable alternative in some applications.

It is possible to use COM to try hook into an open copy of SysCAD and communicate with a project that is already open. This is possible, but great care should be taken with this approach. This use is not formally supported (ie user beware).

VBA Automation Example

To use the SysCAD COM interface in VBA Macros:

  1. Open the "Microsoft Visual Basic" editor.
  2. 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:

  1. Care must be taken to call functions in an allowed and logical sequence. Perform tests as necessary.
  2. All SysCAD COM objects referenced should be cleared on exit. Typically in reverse order as shown in VBA Automation example.
  3. 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 Examples

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(SysCAD9.3).xlsm OR

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 upto 100 cases, but user can extend this value by modifying the workbook and VBA code)