The OLE Automation capability in MAXScript allows 3ds Max to act as an OLE Automation server for applications such as, Visual Basic, Excel, Paradox, and others. With it, you can publish MAXScript functions that can be called from OLE Automation clients like VB and Excel to generate models or animations, return data from the current scene, and so on. There is an example provided in the script samples that defines a set of simple business graphing MAXScript functions and an Excel spreadsheet with some Excel VB-scripted menus, which pass a selection of cells across to these MAXScript functions to generate an animated bar chart.
This facility has the following features and limitations:
It exposes a single server object to which you can attach a list of MAXScript functions that appear as the methods of that object to an OLE Automation client.
It is registered as a separate process, local server supporting multiple use of its exposed object.
It does not support in-place activation or object linking and embedding, and provides no containers for other OLE objects.
It supports only the IDispatch form of interface with no accessible type information. Clients need to declare their reference to the 3ds Max server object as an untyped generic object.
It supports the following method argument and result data types:
The equivalent MAXScript value for empty is undefined
.
OLE Objects (interfaces)
You need to have 3ds Max running and MAXScript activated before OLE Clients can access 3ds Max. MAXScript is activated (and the startup.ms
script run) when you first access its Utility panel rollout. Alternatively, you can use launch script facilities described in Running Scripts from the Command Line to establish an OLE server interface as soon as 3ds Max runs.
You must register 3ds Max with Windows as an OLE server using the registration script supplied with this release. See the instructions in Setting Up MAXScript OLE Automation for details.
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 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' that 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.