OLE Automation

OLE Server

OLE Automation capability is provided in MAXScript that allows 3ds max to act as an OLE Automation server for applications such as Visual Basic, Excel, Paradox, etc. With it, you can publish MAXScript functions that can then be called from OLE Automation clients like VB and Excel to generate models or animations or return data from the current scene, etc. There is an example supplied in the script samples that defines a set of simple business graphing MAXScript functions and an Excel spreadsheet with some Excel VB-scripted menus that will pass a selection of cells across to these MAXScript functions to generate an animated bar chart.

This facility has the following features and limitations:

integers

reals (floats)

currency (floats)

string

boolean

empty (an empty spreadsheet cell, for example)

the equivalent MAXScript value for empty is undefined

OLE Objects (interfaces)

OLE Client

With the MAXScript OLE Automation Client system, you can use MAXScript to create OLE Automation (now called Active-X) objects within 3ds max and control the associated OLE Automation Servers servers with MAXScript, such as making an Excel spreadsheet and inserting 3ds max object information directly into cells there.

The function createOLEObject() is used for establishing a connection to OLE Auto Servers. The return value of createOLEObject() is an instance of the OLEObject class. For example,

xl = createOLEObject "Excel.Sheet"

opens a connection to Excel and creates a sheet object and puts it in the variable xl. The single argument to this function is an OLE progID string. You can then access properties and call methods on the new OLE object. For example,

xl.application.name

will return

"Microsoft Excel"

xl.application.visible = true

will make Excel visible on the desktop. You get properties on OLE objects with the dot '.' notation, just as you do in MAXScript. You also refer to OLE object methods as properties of the OLE object. For example, the Sheet has a method 'cells' which takes a cell coordinate and returns a Cell OLE object.

xlc = xl.application.cells 1 1

puts the top-left-hand cell into xlc. Set its value like this:

xlc.value = 123.45

The server application that was attached with createOLEObject() is released and terminated when the created MAXScript OLE object is eventually garbage-collected. You can explicitly disconnect from an OLE server application with the releaseOLEObject() function. The form is:

releaseOLEObject <ole_object>

The OLE object becomes disabled once releaseOLEObject() has been called on it and further attempts to use it results in a descriptive error message.

You can explicitly disconnect from all active OLE server applications with the releaseAllOLEObjects() function. Its form is:

releaseAllOLEObjects()

After calling this function, all existing OLE objects become disabled and any attempt to use them further will generate a runtime error.