getClassInstances

The getClassInstances method returns an array of all instances of specified class that exist in the scene.

The syntax is:

getClassInstances <MAXClass> target:<MAXObject> asTrackViewPick:<bool>

If target: is specified, only the subAnim hierarchy for that target is searched, otherwise the entire scene is searched.

If asTrackViewPick:true is specified, each use of a class instance is returned as a TrackViewPick value. If asTrackViewPick:false is specified or not supplied, each class instance is returned.

 

Note:

This method was previously available in the Avguard DLX 3rd party MAXScript extension.

 

Example:

--Create two spheres, and an instance of one of the spheres:

resetMaxFile #noPrompt

s1 = sphere()

s2 = sphere pos:[100,0,0]

s3 = instance s1

s3.pos = [-100,0,0]

 

Result:

OK

$Sphere:Sphere01 @ [0.000000,0.000000,0.000000]

$Sphere:Sphere02 @ [100.000000,0.000000,0.000000]

$Sphere:Sphere03 @ [0.000000,0.000000,0.000000]

[-100,0,0]

 

Now execute

tvps=getClassInstances sphere asTrackViewPick:true

for tvp in tvps do

(

print tvp.anim

print tvp.client

print tvp.subNum

print tvp.name

print tvp.client[tvp.subNum]

)

 

Result

#(TrackViewPick:"Object (Sphere)", TrackViewPick:"Object (Sphere)", TrackViewPick:"Object (Sphere)")

Sphere

$Sphere:Sphere01 @ [0.000000,0.000000,0.000000]

4

"Object (Sphere)"

SubAnim:Object__Sphere

Sphere

$Sphere:Sphere02 @ [100.000000,0.000000,0.000000]

4

"Object (Sphere)"

SubAnim:Object__Sphere

Sphere

$Sphere:Sphere03 @ [-100.000000,0.000000,0.000000]

4

"Object (Sphere)"

SubAnim:Object__Sphere

OK

 

Now execute

objs=getClassInstances sphere

for obj in objs do

print (refs.dependents obj) #nomap

 

Result

#(Sphere, Sphere)

#($Sphere:Sphere03 @ [-100.000000,0.000000,0.000000], $Sphere:Sphere01 @ [0.000000,0.000000,0.000000], ReferenceTarget:Animatable)

#($Sphere:Sphere02 @ [100.000000,0.000000,0.000000])

OK

Conclusion:

Since one of the spheres is instanced, 3 TrackViewPick values are returned, but only 2 class instances are returned.

 

See also

Interface: InstanceMgr

Class and Object Inspector Functions

showInterfaces Inspector Function

GetInterfaces Interface Inspector

showInterface Inspector Function