Notifications
Clear all

[Closed] Persistent change notification

I’m working on a tool at the moment which changes a parameter which isn’t a subAnim so I can’t use wire-parameters.

I’ve tried using a ‘when transform changes’ context, which works, but only for the session of max I ran the tool in. I need it to be persistent, and only trigger when the object’s transform is changed.

At the moment the tool is mostly in one CusAttribute, apart from two when constructs which monitor when the object moves and when it’s deleted.

What’s the ‘correct’ way to manage these notifications?

6 Replies

let’s translate it to a coding language… do you have a node in a specific file which has to be monitored by any transformation or an attempt of deletion?

there are two choices… one is when the file travels without your tools (plugins, scripts, etc.). and the second is when the file lives in your environment (framework, supported with your tools)

what is your case?

The former, it’s going to be a public script rather than one just in our own pipeline.

Basic abstraction of my code right now which works, but when you re-open the file of course it doesn’t.


deleteallchangehandlers id:#DWLightExtensions
for obj in selection where superclassof obj == Light do
(
   when transform obj change id:#DWLightExtensions theLight do
   (
      print theLight.pos
   )
   when obj deleted id:#DWLightExtensions obj do
   (
      print "oops someone deleted me"
   )
)

More notable notes…

This script also adds a custom attribute to these light objects…

So I guess I could have a postOpen callback function which re-applies the when change handlers… but that seems dirty…

Simplifying it further. When an object moves, I need to adjust a value. The value has no subAnim track, so no paramwire.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

i would make the node’s scale controller as Scale list and add to available controller Scale script… It will execute on any node transformation.

what about postload CA event?
Never did nothing similar before so any corrections are welcomed.


lightCA = attributes lightCA attribID:#(0x3d98e77f, 0x72d8859)
(
        
    local whenChanged, whenDeleted, whenTargetChanged, whenTargetDeleted, owner
    
    parameters main (
        
        target type:#node
                
    )
    
    fn deleteWhenHandlers = (
        
        deleteallchangehandlers id:#customLightTarget
        whenChanged = whenDeleted = whenTargetChanged = whenTargetDeleted = undefined
        gc light:true
        
    )
    
    fn reApply = (

        for d in (custAttributes.getDefInstances (custAttributes.getDef this)) where d == this do (
                                
            owner = refs.dependentNodes (custAttributes.getOwner d) firstonly:true 

            if whenChanged == undefined and owner != undefined and target != undefined do (

                whenChanged = when transform target change id:#customLightTarget do (
               
                    owner.multiplier = 100.0 / (distance target owner)
                    
                )
                
                whenTargetChanged = when transform owner change id:#customLightTarget do (
               
                    owner.multiplier = 100.0 / (distance target owner)
                    
                )
                
            )
            
            if whenDeleted == undefined and owner != undefined and target != undefined do (

                whenDeleted = when owner deleted id:#customLightTarget owner do (
               
                    format "% is just deleted...
" owner
                    deleteWhenHandlers()
                    this.owner = undefined
                    
                )

                whenTargetDeleted = when target deleted id:#customLightTarget target do (
               
                    format "% is just deleted...
" target
                    deleteWhenHandlers()
                    this.target = undefined
                    
                )                    
                
            )
                    
        )
        
    )

    on postload do (

        reApply()
        
    )

)

delete objects

t  = Omnilight()
tt = point pos:[100,0,0] centermarker:on cross:off wirecolor:yellow
custAttributes.add t lightCA baseobject:true
t.lightCA.target = tt
t.reApply()

ttt = Teapot pos:[150,0,0]