Notifications
Clear all

[Closed] Getting the path of An instanced controller

Hi everyone it’s my first time to post something in the CG-society and I hope to don’t bother anyone! anyway here is the question.
I have an float controller (like z_position) which is instanced to a Custom Attribute parameter in “Pen_attribute_Holder”. the problem is , whenEver I try to access the path of the controller with “exprForMAXObject” function, instead of the path from my object, it returns the path of its instance in attribute_holder:
$MyPENHolder.modifiers[#PEN_Attribute_Holder_2].param.Z_position.controller
instead of :
$MyObject.pos.controller.Position_XYZ.controller.Z_position.controller

I also tryed to put my float controller into a variable then access its client using “( refs.dependents myCtrl )[1]” , but every index in this array returns then PEN_attribute_holder path in the modifiers stag.

please help me!
thanks for reading my issue

14 Replies
2 Replies
(@denist)
Joined: 11 months ago

Posts: 0

exprForMAXObject returns path for last assigned instance. So to get the path that you are looking for you have to reassign the controller. Like:


 c = $MyObject.pos.controller.Position_XYZ.controller.Z_position.controller
 $MyObject.pos.controller.Position_XYZ.controller.Z_position.controller = copy c
 $MyObject.pos.controller.Position_XYZ.controller.Z_position.controller = c
 

ps. remove wrong space char in my code

(@arminanim)
Joined: 11 months ago

Posts: 0

Oh it did work Great! thank you ! BIG smile

 JHN

From where do you want to access this controller. The refs dependents would be my choice too, but then just loop over the array and exclude the attribute holder. But it depends a bit on where you want to acces the instance from, if it’s from the attribute holder then simply exclude the attributes with a simple for loop and a “where ref != this.yourtrack.controller” (pseudo code).

thank you for answering sir, but it didnt work that way,because I need a path, but “exprForMAXObject” always return a path across the pen_attribute_holder even for all content of refs.dependents array. How can I ever get the exact path of my controller, not its instance ?

 JHN

The problem is that the original controller is also an instance of the float controller class, so a instance of that instance is the same controller, there’s no way to know what the original controller was and what the instance is, there’s no master/slave principle that applies here.

Another approach is to loop through all float controllers in the scene getClassInstances and then check with a simple if c1 == c2 if the controller is an instance of the controller you could find.

Or you could provide an example file and I could have a less hypothetical go at it

-Johan

so it seems I’m going to change some master things in my Script. thank you so much Mr. Johan for helping and I promise that if I didn’t solve it I will bother you again 🙁

double-check it with saving and reloading saved max file. Max should not screw this up but who knows.

5 Replies
(@arminanim)
Joined: 11 months ago

Posts: 0

Ow no ! after closing and reloading, the wrong path returned !.. I traped in hole again !

(@denist)
Joined: 11 months ago

Posts: 0

that’s what I was worrying about. The MAX restores the order of subAnims creation. So you have to recreate whole Position controller (not just Z_Poisition controller).

(@arminanim)
Joined: 11 months ago

Posts: 0

in this case the xyz controller will lose its wire children I think

(@denist)
Joined: 11 months ago

Posts: 0

You think right. You have to re-wire children of the controller. But let me think a little more. Maybe I will be back with another solution.

(@arminanim)
Joined: 11 months ago

Posts: 0

if I could , I would but the matter is, that I don’t know what is wired to my controller. thank you so much anyway

 JHN

   (
   	animated_props = #()
   	fn getSubAnims theObject theController =
   	(
   		
   		if try(theObject.controller == theController)catch(false) do 
   		(
   			append animated_props theObject 
   		)
   		for i = 1 to theObject.numSubs do 
   			getSubAnims theObject[i] theController
   	)
   
   	theController = selection[1].pos.controller[1].controller
   	for o in refs.dependentNodes theController do
   		getSubAnims o theController
   
   	for p in animated_props do
   	(
   		for i = 1 to p.parent.numSubs where p.parent[i].controller == theController do
   		(
   			print ((exprForMAXObject p.parent) + "[" + (i as string ) + "].controller")
   		)			
   	)
   )
   

It’s a bit messy and could use some cleanup, but I don’t have time now.
This scans the objects that are dependent to the controller and tries to locate them via the subAnims. Once found it will find the parent of the controller and the controllers subanim index, then it manually builds an expression for it based on that info.

-Johan

edit1 : Based on a example from the mxs help file to recurse over animated subanims.
edit2 : There’s a problem with controller on the baseObject. These are directly accesible from the object level so they introduce ambiguity. An extra check is needed. I’ll have a look.
edit3 : It also doesn’t loop over custAttributes yet as they are not seen as a subanim… so no good.

thanks Mr johan its useful. gotta adapt it to my script. my problem was solved temporary with Mr.DenisT solution by reseting the instanced controller but I was thinking to use your script somehow to find wire-children of a controller which is my next step. thanks to both of you for sugesting me new ways and solutions. Im getting addicted to this forum