SysCAD COM Interface Class
Jump to navigation
Jump to search
Basic COM Functionality in a python class
Save the code in a file syscadif.py This needs to be either in the working directory, or somewhere on the PYTHONPATH (so that you can import the module from any script) Alteratively, add to the import module path as in the code below. Then import the module and create an instance of the SysCADCom class:
import sys
sys.path.append(r"C:\SysCAD139\BaseFilesUser\Scripts") ## syscadif.py is saved in a subdirectory of BaseFilesUser
import syscadif
sc = syscadif.SysCADCom()
After a project is loaded, you can get and set tags, and run the model or scenarios. For convenience, operators __getitem__ and __setitem__ are provided which allow using a similar syntax to PGM: Copy Tag for PGM can be used to grab the tag string with enclosing brackets.
sc.setTag("SLURRY_IN.QmReqd (t/h)", 50.0)
sc["SLURRY_IN.QmReqd (t/h)"] =50.0 ## equivalent
sc.run()
prod = sc.getTag("P_007.Qo.QM.Au(s) (oz/d)")
prod = sc["P_007.Qo.QM.Au(s) (oz/d)"] ## equivalent
## Setting a single tag for three different scenarios: Flow in P_01 and P_03 for feeds of 1, 3, and 5 tph
sc.RunScenarios([1,3,5], "Feed1.QmRqd (tph)", ["P_01.Qm (tph)", "P_03.Qm (tph)"])
# Four different scenarios, setting two tags
sc.RunScenarios([[2,4], [3,5], [4, 7], [5, 8]], ## List of value lists
["Feed1.QmRqd (tph)","Feed2.QmRqd (tph)"],
["P_01.Qm (tph)", "P_03.Qm (tph)"])
Creating an instance of the SysCADCom class will fire up SysCAD (or attach if SysCAD is already running). To see the code below click on the Expand link: