PDA

View Full Version : Getting the path of An instanced controller


ArminAnim
12-20-2010, 06:03 AM
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

JHN
12-20-2010, 09:57 AM
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).

ArminAnim
12-20-2010, 11:02 AM
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
12-20-2010, 01:29 PM
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

ArminAnim
12-20-2010, 01:40 PM
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 :sad:

denisT
12-20-2010, 05:46 PM
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

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
12-20-2010, 05:59 PM
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

Oh it did work Great! thank you ! BIG smile :)

denisT
12-20-2010, 06:06 PM
Oh it did work Great! thank you ! BIG smile :)

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

ArminAnim
12-20-2010, 06:39 PM
double-check it with saving and reloading saved max file. Max should not screw this up but who knows.
Ow no ! after closing and reloading, the wrong path returned !... I traped in hole again !

denisT
12-20-2010, 07:34 PM
Ow no ! after closing and reloading, the wrong path returned !... I traped in hole again !

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
12-20-2010, 07:42 PM
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).
in this case the xyz controller will lose its wire children I think

denisT
12-20-2010, 07:50 PM
in this case the xyz controller will lose its wire children I think
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
12-20-2010, 07:53 PM
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.
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
12-20-2010, 08:42 PM
(
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.

ArminAnim
12-21-2010, 10:22 AM
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 :D

CGTalk Moderation
12-21-2010, 10:22 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.