PDA

View Full Version : Get object by modifier


sergo.pogosyan
04-01-2009, 01:52 PM
I'm writing simple scripted modifier and need to store information about the node this modifier is assigned to in some persistent variable.
#node parameter doesn't work because "The nodes stored in these parameter cannot create a circular dependency" as reference states. I've tried to assign argument from "on attachedToNode " event handler to local variable, but local variable is not saving in max file.

In scripted modifier there is "this" variable pointing to that modifier. It may seems very simple task, to get node from the modifier object, but I had no luck.

Is there any function or method to get node info from modifier object?

Thank you,
Sergo.

Piflik
04-01-2009, 02:23 PM
You can loop through all the objects and the modifiers and get the node(s):

theObject = for o in objects where (for m in o.modifiers where m.type == theModifier collect m).count > 0 collect o

sergo.pogosyan
04-01-2009, 03:09 PM
Yes, this may be the workaround, but I think it's too complex.
It's something strange, when your in modifier code it must be simple to access underlying node!

JHN
04-01-2009, 03:10 PM
What you really want to do is assign the node by weak reference. So your modifier has a #maxObject param in the Pblock like

nMySelf type:#maxObject

Now you can in the attach event assign the node to the nMyself param by

nodeTransformMonitor node:theObjectYouWant forwardTransformChangeMsgs:false


If you want to access it in the modifier you simply have to call
nMySelf.node

This tool avoids the circular depency.

-Johan

JHN
04-01-2009, 03:14 PM
Yes, this may be the workaround, but I think it's too complex.
It's something strange, when your in modifier code it must be simple to access underlying node!
Although I agree, how would that handle the case when a modifier is instanced to 2 or more objects. I think that's the reason why there's now self, this, or parent variable returning the baseObject. Weak references are the way to go, and I use them all the time.

-Johan

LoneRobot
04-01-2009, 03:31 PM
Weak references are the way to go, and I use them all the time.

-Johan

I absolutely agree, this alone has made a huge amount of difference to what you can do, especially with custom attributes. Prior to this I would use $.modifiers[1] in the attribute. nasty!

there is an article on PEN's site here (http://www.paulneale.com/tutorials/Scripting/weakReferences/weakReferences.htm) - and other examples here (http://www.lonerobot.com/NodeVisibility.html)

sergo.pogosyan
04-01-2009, 03:33 PM
Thank you, Johan!

Weak reference is something new for me. I'll try it.

sergo.pogosyan
04-02-2009, 11:46 AM
Thank you guys!
Weak reference is what I want. It works perfectly!

CGTalk Moderation
04-02-2009, 11:46 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.