Previous topic TOC

Use COM objects

Next topic

createObject The ThreeDimSim program can create COM objects, and use these in a script. An automation object can be created by the createObject function, and used just like other objects. In the following example an Excel workbook is created and modified by the script:
// create an automation object
var workbook = createObject("Excel.Sheet");
print(workbook.Author);  // use a property
workbook.Activate();     // call a method

workbook.Author = "The Author";  // set a property

workbook.Application.visible = true;
workbook.ActiveSheet.Cells(1,1).Value = "ThreeDimSim";
workbook.ActiveSheet.Cells(1,2).Value = "cell 1,2";
workbook.ActiveSheet.Cells(2,1).Value = "cell 2,1";

workbook.SaveAs("c:/Test.xls"); // save the new workbook

It is also possible to use an existing object, and for example read its data:

// get an automation object  
var workbook = getObject("c:/Test.xls" );
// get contents
var cell_11 = workbook.ActiveSheet.Cells(1,1).Value;
// print cell 1,1 in outputtab
// release workbook
workbook = 0;    
ThreeDimSim can act as a COM server itself, allowing other programs to access the running  scene. This is done by exposing the eval function. More details can be found in the help documentation