Notifications
Clear all

[Closed] How to get the targets of a Lookat_constraint

How do I select the target(or targets) of a Lookat_Constraint?

Or better yet, how do I understand this section of the help file. I understand .properties when I see them in the help. But the <rules> of methods aren’t clear to me. I just don’t script enough…
From the Max Help:

[left][color=white]LookAt_Constraint interfaces:[/color]
[/left]
[left]Interface: constraints
[/left]
[left]Methods:
[/left]
[left]<integer>[b]getNumTargets/b
[/left]
[left]Returns the number of target nodes in the target list.
[/left]
[left]<node>getNode <index>targetNumber
[/left]
[left]Returns the indexed target node.
[/left]
[left]<float>getWeight <index>targetNumber
[/left]
[left]Returns the weight of the indexed target if the targetNumber is relevant, 0.0 otherwise.
[/left]
[left]<boolean>setWeight <index>targetNumber <float>weight
[/left]
[left]Sets the weight of the indexed node specified by targetNumber. Returns True on success, False otherwise.
[/left]
[left]<boolean>appendTarget <node>target <float>weight
[/left]
[left]Appends the specified node to the list and sets its weight to the specified value. Returns True on success, False otherwise.
[/left]
[left]<boolean>deleteTarget <index>targetNumber
[/left]
[left]Deletes the indexed target. Returns True on success, False otherwise.
[/left]

2 Replies

The <rules> just tell you the type of the arguments (or, if in front of the method, the return value type).

Let’s assume you have a Teapot01 with a LookAt Constraint in the Rotation track looking at 3 Spheres.

theObj = $Teapot01 –this is the host object
$Teapot:Teapot01 @ [-53.237698,71.865959,0.000000]

theController = theObj.rotation.controller –this is the rotation (LookAt) Constraint
Controller:LookAt_Constraint

–Now loop from 1 to the number of targets in the constraint and collect
–each node into an array called theTargets:
theTargets = for i = 1 to theController.getNumTargets() collect theController.getNode i
#($Sphere:Sphere01 @ [-77.946899,-10.454015,0.000000], $Sphere:Sphere02 @ [-43.879711,-0.831173,0.000000], $Sphere:Sphere03 @ [17.187794,69.950142,0.000000])

select theTargets –now all you have to do is select them
OK

WOOT!!

Thanks Bobo.:):)

I’ll be glad when this project is over so I can switch to 2009 and the new script editor and help system. Still on good ol’ Max 9 for now.

So here are my meager additions for anyone who is interested.

macroscript SelectLookAtTarget 
category: "MyTools"
(
	theObjects = selection
	allTargets = #()
	for o in theObjects where classof o.rotation.controller == LookAt_Constraint do
	(
		theController = o.rotation.controller
		theTargets = for i = 1 to theController.getNumTargets() collect theController.getNode i
		join allTargets theTargets
	)
	select allTargets
)