How to identify LookAt in rotation list or as the only rotation controller

How to identify LookAt in rotation list or as the only rotation controller

PropChad
Advocate Advocate
1,257 Views
8 Replies
Message 1 of 9

How to identify LookAt in rotation list or as the only rotation controller

PropChad
Advocate
Advocate

I'm a novice at Maxscript and programming in general, and trying to create a script that would change the settings for multiple objects that already have a LookAt Constraint applied. Failing so far.

 

Issue I'm running into is that if you apply a LookAt Constraint to objects by Animation > Constraints > LookAt Constraint, it gets put into the Rotation List as a layer, so I could change things by

 

for i in $selection do

(
i.rotation.controller.LookAt_Constraint.controller.upnode_ctrl = 1
)

 

 

Now if one assigns the LookAt Constraint from the motion panel, directly to Rotation, I no longer have the list and I have to change things by the following.

 

for i in $selection do

(
i.rotation.controller.upnode_ctrl = 1
)

 

So the question is, what's the best way to make changes to multiple objects that may have the LookAt Constraint in different positions of the Rotation controller, and also ignore those that do not even have the LookAt Constraint if they are accidentally part of the selection?

0 Likes
Accepted solutions (1)
1,258 Views
8 Replies
Replies (8)
Message 2 of 9

denisT.MaxDoctor
Advisor
Advisor

we can do something like:

fn getNodeRelatedLookAt target =
(
	getclassinstances LookAt_Constraint target:target
)

where getclassinstances is a recursive function... so it finds a LookAt instance in both Rotation and Rotation List controllers

 

getNodeRelatedLookAt <node>
-- or
getNodeRelatedLookAt <node>.controller

 

the result in both cases is an array... so we can set an upnode as :

cc = getNodeRelatedLookAt ...
cc.upnode_ctrl = 1

 

0 Likes
Message 3 of 9

PropChad
Advocate
Advocate

Thanks for the response, and sorry for the late reply.

 

I tried piecing together your code and I can't seem to get it right. Like I said, I'm a beginner at this, I think it went over my head. 😕

 

If I copy and paste together your code, I get a syntax error, expected <factor>. I'm assuming I need to fill in <node> with something?

0 Likes
Message 4 of 9

denisT.MaxDoctor
Advisor
Advisor

@PropChad wrote:

If I copy and paste together your code, I get a syntax error, expected <factor>. I'm assuming I need to fill in <node> with something?


you need to replace <node> with the actual node that uses the LookAt controller (or use the variable that stores the pointer to the node)..

 

for example:

 

 

b = box name:"the_box"
c = LookAt_Constraint()
b.rotation.controller = c

fn getNodeRelatedLookAt target =
(
	getclassinstances LookAt_Constraint target:target
)

(getNodeRelatedLookAt b)[1] == c
(getNodeRelatedLookAt $the_box.controller)[1] == c

 

 

getNodeRelatedLookAt returns an array of all associated LookAt constraints ... if not present, the array is empty.

0 Likes
Message 5 of 9

PropChad
Advocate
Advocate

Cool. That works with a single object, but how does one make this loop through 50 objects to apply that setting? Arrays are foreign to me. So we created one to store all objects with a LookAt constraint, but are only allowing the one specified to change? If I do something like:

 

a = getclassinstances LookAt_Constraint
for i in a do

(
     a.upnode_ctrl = 1
)

 

it will update all LookAt constraints in the scene with that setting, instead of what is selected, which of course is not wanted.

 

Below does just object that  is specified no matter what is selected. So somehow I need to update b for every object in a selection?

 

b = $ChainA_WagonA_5
c = LookAt_Constraint()
b.rotation.controller = c


fn getNodeRelatedLookAt target =
(
getclassinstances LookAt_Constraint target:target
)

(getNodeRelatedLookAt b) [1] == c
-- or
(getNodeRelatedLookAt b.controller)[1] == c


c.upnode_ctrl = 0

 

Thanks

0 Likes
Message 6 of 9

denisT.MaxDoctor
Advisor
Advisor
for node in selection do 
(
	for c in getNodeRelatedLookAt node do c.upnode_ctrl = 0
)
0 Likes
Message 7 of 9

PropChad
Advocate
Advocate

So close to working. If I leave b = an object in the scene, whether it is part of the selection or not, it works. If I comment out that first line and change b to $ in the below code, it works only if the selection has the LookAt in the Rotation, or Rotation List, but not both.

 

Stranger is, when it does work in either scenario...if an object that is selected to update the LookAt is targeting another object and/or an Upnode that also has a LookAt constraint, it changes those as well, and any other one down the line. Think of a chain link, they are all looking at the next one in front of it. From the only one that is picked, until the last one in the LookAt hierarchy, they all will change. It's like it is spreading to anything that it is targeting. 

 

b = $cylinder002
c = LookAt_Constraint()
b.rotation.controller = c


fn getNodeRelatedLookAt target =
(
getclassinstances LookAt_Constraint target:target
)

 

(getNodeRelatedLookAt b) [1] == c
-- or
(getNodeRelatedLookAt b.controller)[1] == c

 

for node in selection do

(
for c in getNodeRelatedLookAt node do c.upnode_ctrl = 1
)

 

 

 

The below code works and doesn't spread, except it assigns a LookAt to an object if it is mistakenly part of the selection. It's like I need a hybrid of both codes. 😕

 

fn getNodeRelatedLookAt target =
(
getclassinstances LookAt_Constraint target:target
)

 

for b in $ do
(
c = LookAt_Constraint()
b.rotation.controller = c


(getNodeRelatedLookAt b) [1] == c
-- or
(getNodeRelatedLookAt b.controller)[1] == c

 

c.upnode_ctrl = 1
)

0 Likes
Message 8 of 9

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

@PropChad wrote:

So close to working. If I leave b = an object in the scene, whether it is part of the selection or not, it works. If I comment out that first line and change b to $ in the below code, it works only if the selection has the LookAt in the Rotation, or Rotation List, but not both.

 

Stranger is, when it does work in either scenario...if an object that is selected to update the LookAt is targeting another object and/or an Upnode that also has a LookAt constraint, it changes those as well, and any other one down the line. Think of a chain link, they are all looking at the next one in front of it. From the only one that is picked, until the last one in the LookAt hierarchy, they all will change. It's like it is spreading to anything that it is targeting. 

 

...


oh ... long time to explain the problem. But in a nutshell, we only need to enumerate Animatable Tree of the object instead of the entire reference hierarchy to eliminate recursive reference dependencies. Is it clear enough? No? Sorry .. but in a different way you need to attend my classes 😉

 

well... 

Instead of the using the built-in getClassInstances we should use our function:

 

 

fn enumerateAnimTree obj class: result:#() =
(
	if isController obj and (class == unsupplied or iskindof obj class) do appendifunique result obj

	for ref in refs.dependson obj where iscontroller ref do 
	(
		result = enumerateAnimTree ref result:result class:class 
	)
	result
)

 

 

 

where we can specify class of the searching controllers.

 

the entire "LookAt controller setup" for the specified nodes will look like this:

 

 

 

for node in selection do 
(
	cc = enumerateAnimTree node class:LookAt_Constraint
	if cc.count > 0 do cc.upnode_ctrl = 0
)

 

 

  

 

0 Likes
Message 9 of 9

PropChad
Advocate
Advocate

Yes! I think this is working!

 

I would like to think I'd enjoy your classes, but in reality I probably need a proper "hello world" course first. 😄 Pretty much all of this flew right over my head. I will dissect this along with the other scripts I'm trying to modify and hopefully be able to grasp more.

 

Thanks so much for you time and patience.

0 Likes