Xref Objects

Topic: version 4 MAXScript New Features/Xref Objects

An updated function published interface for Xref Objects. See Interface: objXRefs

Explicit References

A file being xref'd that has a script controller whose script has explicit references ($sphere01, etc.) to objects in the incoming xref file have a potential problem for the script writer. The problem is, the objects in the xref file are invisible to the scripter, and so a script will fail. This is actually a general problem with xrefs, you cannot have scripts of any kind in the file (scripts controllers, param wires, callback scripts, etc.) that depend on explicit scene object references.

The persistent global solution is the only one that is viable at this time. There are two general solutions: 1) associate an owning-scene context with controller scripts, etc., when they come in via xref and use that to anchor pathname searches and other scene-relative references, and 2) have an accessible 'evaluation context' for controllers sent as part of the GetValue() call, so we can know what object's parameter the current GetValue() call is being made for and can therefore get rid of many of the uses of explicit pathnames in the scripts.

Currently, MAXScript now fully loads any persistent globals in xref'd and merged files, but does NOT make them persistent in the current scene. As an example of a setup showing how this can be used, imagine a file with 3 spheres that will be xref'd. You need to establish persistent globals for all the scene objects to be referrenced in controller scripts, like this:

persistent global s1 = $sphere01, s2 = $sphere02, s3 = $sphere03

this has to be run sometime while the to-be-xrefed scene is the currently open scene. Then in the controller scripts, you'd say something like:

global s1, s2

dependsOn s1 s2

(s1.pos + s2.pos) / 2


Note this uses 'global' not 'persistent global', so you don't go making them persistent again when they get xref'd into some other scene.

See also