Notifications
Clear all

[Closed] run script when callback is performered

i have an issue with callbacks, below you see a small example that works.

When the object is moved, rotated or scaled it wil run this script.


when transform $obj changes HandleAt:#RedrawViews id:#obj_ID do
(
print “test_obj”

)

The problem I have is when a new object is made in the scene. i want this object to be aplied to the callback too.
But when you have a callback, it seems that all the object have to already excist in the scene, otherwise it will give an error.

Does anyone has an idea how i can solve this or perhaps knows a different method?

7 Replies
 deleteAllChangeHandlers() 
when transform $* changes HandleAt:#RedrawViews id:#obj_ID obj do

(

print "test"

print obj.name

)


Is it what you want?
Either you maybe will have to redefine your callBack each time you want to change object list

Hello lanimal,

thank you very much for your quick reply. With the change you made all the objects react with this script. But when i add a new object, this object does not react with the script.

Is it possible to redefine the callback? like you said in you message.

write callback as string and execute when object added using parmaters. Sorry i dont hve time to writr it out for you but im sure u get the idea

In this case you will have to rewrite your callBack each time you add an object.
build your callBack string and execute it

Store your callBack code somewhere and rewrite object list string
just a small code helpful for building object array

 
ctrls = $*
CtrlsArr = "#("
for c in 1 to ctrls.count do
( 
CtrlsArr += ("$"+Ctrls[c].node.name+".transform.controller")
if c != Ctrls.count then (CtrlsArr += ",") else (CtrlsArr += ")")
)

good luck

Hello helpfull people :-), thank you for the input

From what i understand is that i need to use the callbacks.addscript then

i will do some more reading about this tonight in de addscript helpfile, but if i am right the idea is :

1 ) a new object is created in the current scene. this has to be seen by de first callback like this

callbacks.addscript #nodeCreated “whenCreated()

  1. then it goes to a function whencreated() where i add all the objects in a object array.

  2. from here it should be paste to the when changes callback

when transform object_array changes HandleAt:#RedrawViews id:#obj_ID do print “test”

I should probaly find out how i can put the when changes callback also in a string, because the when changes callback always checks for the first time you start up your script if an object is in the scene.

If i am completly wrong, just let me know.

Hi,

I found the solution for the problem. thank you floatingworld and lanimal for the tips and advice

The code is standing below :

clearlistener()

callbacks.removeScripts id:#adding_objects
global ctrls = “#()”
collect_items ()
print CtrlsArr

txt = “when transform ctrls changes HandleAt:#RedrawViews id:#obj_ID obj do print obj.name

callbacks.addScript #nodeCreated txt id:#adding_objects

fn collect_items =
(
ctrls = $*
CtrlsArr = “#(”
for c in 1 to ctrls.count do
(
CtrlsArr += (“$”+Ctrls[c].name)
if c != Ctrls.count then (CtrlsArr += “,”) else (CtrlsArr += “)”)
)
)

here is an alternative way how to catch node’s transform change…


try
(
	Transform_NodeEventCallback.enabled = off
	Transform_NodeEventCallback = undefined
)
catch()

fn Transform_Control event nodes = 
(
	for n in nodes where isvalidnode (node = getanimbyhandle nodes[1]) do
	(
		format "node >> %
" node.name
	)
)
Transform_NodeEventCallback = NodeEventCallback mouseUp:off controllerOtherEvent:Transform_Control
Transform_NodeEventCallback.enabled = on

the bad thing is that this event fires not only on transform change. the good thing is that there are no many other cases.