Notifications
Clear all

[Closed] "When transform…" issues

Hey there,
I tried making and auto ik snap system as a checkbutton in a custom attribute. Basically I wrote a function that snaps the rotation of some objects to some others. The function works fine, but when I make it the function happen whenever a certain object is moved using the “when transform $blah changes do” command, it only half works.
As I first start to move the “blah” object the snap happens but I can only move that object on one axis. The “blah” object’s position correctly updates only when I begin to move it again.
In the online help, this example is given:

   [left]when transform $box01 changes do
 $box02.pos = $box01.pos + delta
   [/left]
   

but when I evaluate it, it doesn’t recognise the “delta” variable and without it, it doesn’t evaluate correctly (the $box02 position doesn’t match $box01’s).
Should I be defining a “delta” variable for it to work correctly? Is putting a “when transform” statement inside a custom attribute going to give me grief? What’s the best way to do this?
:¬)

2 Replies

delta should be defined as a Point3 value you want to use as offset.

Then again, the MAXScript Reference says the following:

[left]Caution:
[/left]
[left]The change handler system is based on 3ds Max’s internal notification system which essentially drives all animation and interactivity within 3ds Max. There are cases when the core sends many, many signals for the same change, so setting up change handlers on many objects that do vast amounts of computing can significantly slow down the system. Strictly speaking, change handlers are supposed to be used to just set “dirty flags” in a lightweight, order-independent way, and then use Redraw Views or Time Change callbacks to actually cause the triggered processing. You should attempt to use change handlers judiciously,

[/left]
[left]and not, for example, as a simple way to get scripted controllers.

[/left]
[left]If you do find that a desired setup is being flooded with unnecessary signals, you should use the handleAt: to delay the actual processing of the event handler script until a redrawViews or timeChange event occurs.
[/left]

This was written in R2 days, but is still valid today. If you want to update stuff interactively, use a real scripted controller to monitor node changes.

Thanks for the reply Bobo, but the objects that I want to snap to others I still want to be able to transform after the fact. If I use a script controller on the transforms, I won’t be able to do that. Should I be using a script controller assigned to a CA controller to do the snapping instead of using the CA script itself?
Also, how can I turn off that specific change handler (if I end up using it) when it randomly generates an id after I enable it?