[Closed] Get object by modifier
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.
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
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
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
Thank you, Johan!
Weak reference is something new for me. I’ll try it.
Thank you guys!
Weak reference is what I want. It works perfectly!