PDA

View Full Version : How to get the targets of a Lookat_constraint


jonahhawk
12-31-2008, 03:56 AM
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:

LookAt_Constraint interfaces:

Interface: constraints

Methods:

<integer>getNumTargets()

Returns the number of target nodes in the target list.

<node>getNode <index>targetNumber

Returns the indexed target node.

<float>getWeight <index>targetNumber

Returns the weight of the indexed target if the targetNumber is relevant, 0.0 otherwise.

<boolean>setWeight <index>targetNumber <float>weight

Sets the weight of the indexed node specified by targetNumber. Returns True on success, False otherwise.

<boolean>appendTarget <node>target <float>weight

Appends the specified node to the list and sets its weight to the specified value. Returns True on success, False otherwise.

<boolean>deleteTarget <index>targetNumber

Deletes the indexed target. Returns True on success, False otherwise.

Bobo
12-31-2008, 04:07 AM
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

jonahhawk
12-31-2008, 08:00 AM
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
)

CGTalk Moderation
12-31-2008, 08:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.