Scripts can be run within Cimatron E to perform specific tasks. You can write your scripts in either vbscript or javascript.
The Script Engine has the ability to handle events such as entering the script, leaving the script, and adding objects to scripts (the objects are created in Cimatron E and can be used in the script).
Classes
How to use Cimatron E scripts
Example Script
General Interaction
Select the appropriate script from the open file dialog:

|
CScriptRunner |
A class that can run a script file (the filename
is required as a parameter). |
|
CScriptEngine |
The main class in the Script Engine mechanism. The class implements
2 COM interfaces: IActiveScriptSite
and IActiveScriptSiteWindow which
deal with running scripts. The CScriptEngine can hold a pointer to a CScriptSink
(which is provided by the user of the script engine) object that enables
you to handle events such as OnEnterScript and OnLeaveScript. |
|
CScriptSink |
An abstract class that enables you to handle script events (such as
OnEnterScript and OnLeaveScript). |
How to use Cimatron E scripts:
Running Scripts with CScriptRunner:
void MyClass::RunScript()
{
CString aFileName = “script.esc”;
CScriptRunner aScriptRunner;
aScriptRunner.RunScript(aFileName);
}
Running Scripts without CScriptRunner (through the CScriptEngine):
// pszScript is the script as a string
CString szEngineName = “vbscript”;
// Load the scripting engine
CScriptEngine aScriptEngine;
HRESULT hr;
hr = aScriptEngine.Create(T2COLE(szEngineName));
// Execute the script
hr = aScriptEngine.Execute(T2COLE(pszScript));
hr = aScriptEngine.Close();
Handling Events:
Create a Sink class derived from CScriptSink:
class CMySink : public CScriptSink
{
CMySink::CMySink() {}
void OnEnterScript()
{
//
do something
AfxMessageBox(_T("Entering
Script !"));
}
void OnLeaveScript()
{
//
do something
AfxMessageBox(_T("Leaving
Script !"));
}
};
Attach your sink object to the engine before running the script:
CScriptSinkTest* pSink = new CScriptSinkTest();
CScriptEngine aScriptEngine;
aScriptEngine.SetScriptSink(pSink);
…
Adding objects to the script:
Attach your sink object to the engine before running the script:
CScriptEngine aScriptEngine;
HRESULT hr;
hr = aScriptEngine.Create(T2COLE(szEngineName));
// Add Item
CComPtr<IDispatch> spdispScriptHelpers;
hr = spdispScriptHelpers.CoCreateInstance(CLSID_ScriptHelpers);
hr = engine.AddObject(OLESTR("myobj"), spdispScriptHelpers,
SCRIPTITEM_ISVISIBLE | SCRIPTITEM_GLOBALMEMBERS);
“spdispScriptHelpers” is a pointer to an
object that can be added.
“myobj” – is the name of the object which can be used in the script.
The following is an example of a script that executes a command:
language=vbscript
dim app,doc,model
set app = CreateObject("CimatronE.Application")
Dim PoolCmd,Cmd
Set PoolCmd = App.GetPoolCommands
If Not (PoolCmd Is Nothing) Then
Set Cmd = PoolCmd.GetCommand("File1", "New")
if not cmd is nothing then
Cmd.Execute
end if
End If