The following template is a suggested starting point for using the Synergy API with VBScript bindings.
It is good practice to put explanatory comments at the top of your scripts. To ensure a specific version of Synergy is called, the first line must be:
'%RunPerInstance
The following lines and their function is outlined.
Option Explicit
The Option Explicit expression is useful to reduce programming errors. Variables that are used before they are declared will cause an error when this line is included in the script.
SetLocale("en-us")
The SetLocale option forces the non-English systems to interpret numerical values as they are in the US. If this setting is not included, then numerical values will be interpreted in the system's native language. This is a problem where commas are used instead of full stops (such as in Germany).
Dim SynergyGetter, Synergy On Error Resume Next Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%")) On Error GoTo 0 If (Not IsEmpty(SynergyGetter)) Then Set Synergy = SynergyGetter.GetSASynergy Else Set Synergy = CreateObject("synergy.Synergy") End If
These lines create an OLE automation object which starts Synergy (the Autodesk Moldflow user interface). The Dim (variable declaration) line, which declares the Synergy variable, is not required if the Option Explicit line is not used. However, it is good practice to always declare variables.
Synergy.SetUnits "METRIC"
"ENGLISH" can be used as an alternative to "METRIC" to use US units by default.
'%RunPerInstance '@ '@ DESCRIPTION '@ '@ '@ SYNTAX '@ TheFirstLines '@ '@ PARAMETERS '@ none '@ '@ DEPENDENCIES/LIMITATIONS '@ none '@ '@ History '@ Created DRA 9/8/2006 '@@ Option Explicit SetLocale("en-us") Dim SynergyGetter On Error Resume Next Set SynergyGetter = GetObject(CreateObject("WScript.Shell").ExpandEnvironmentStrings("%SAInstance%")) On Error GoTo 0 If (Not IsEmpty(SynergyGetter)) Then Set Syn = SynergyGetter.GetSASynergy Else Set Syn = CreateObject("synergy.Synergy") End If Synergy.SetUnits "METRIC" ' ' Put remainder of code here. ' MsgBox "Script Complete" Wscript.Quit