Notifications
Clear all

[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.

7 Replies

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
 JHN

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!

1 Reply
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

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

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 – and other examples here

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!