Capturing object names using NodeEventCallback when nameChanged: and geometryChanged:

Capturing object names using NodeEventCallback when nameChanged: and geometryChanged:

kenc
Advocate Advocate
172 Views
5 Replies
Message 1 of 6

Capturing object names using NodeEventCallback when nameChanged: and geometryChanged:

kenc
Advocate
Advocate

Hi all

 

I am writing a script using NodeEventCallback to save an object's nameChanged: and geometryChanged: to 2 arrays.

ObjChangedName and ObjChangedGeom

 

When the script is run, it does append to the arrays but as a ID or handle. What I need is the object name to populate a multilistbox rollout.

 

global Obj, ObjChangedName = #(), ObjChangedGeom = #()
try
(
callbackItem = undefined
gc light:true
)
catch
(
)
fn CallbackFunc1 NodeEvent1 Obj =
(
appendIfUnique ObjChangedName Obj
)
fn CallbackFunc2 NodeEvent2 Obj =
(
appendIfUnique ObjChangedGeom Obj
)

callbackItem = NodeEventCallback mouseUp:true delay:1000 nameChanged:CallbackFunc1 geometryChanged:CallbackFunc2 Obj

 

When run this the content of the 2 arrays are

 

ObjChangedName is #(#(50770), #(50813))

ObjChangedGeom is #(#(50813))

 

What I need is the object names.

 

I also noticed that the geometryChanged: event does respond to move/rotate/position changes

 

I guess this is a 2 part question post.

 

I'd appreciate any help please.

0 Likes
Accepted solutions (1)
173 Views
5 Replies
Replies (5)
Message 2 of 6

A娘
Advocate
Advocate

you didn't need put your script , put detail of the purpose

0 Likes
Message 3 of 6

MartinBeh
Advisor
Advisor
Accepted solution

Just guessing (no time to read the docs): Are those numbers the object "handles"?

Edit: They are not the normal handles but AnimHandles. The docs say:

"The callback functions always take two parameters: the first is the event name that triggered the function call, the second is a list of node AnimHandles"

 

So you would need to use

GetAnimByHandle <integer>

to retrieve the scene objects.

 

So one of your functions could look like this:

fn CallbackFunc1 NodeEvent1 Obj =
(
	for o in obj do (appendIfUnique ObjChangedName (GetAnimByHandle o))
)

 

Some more minor remarks

  • I don't think you need to declare Obj as global, and also there seems to be no need to add it as last argument to NodeEventCallback
  • Maybe you might want to look into the 'when' change handler instead of the NodeEventCallback, it also allows to catch both geometry and name changes and might be easier to work with
Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 4 of 6

sc95VR4MA
Explorer
Explorer

I normally use something like this:

 

yourObject = getNodeByName (The Object Name Reference Here)

Select yourObject 

 

--Then do whatever to the object.

0 Likes
Message 5 of 6

kenc
Advocate
Advocate

@A娘 

 

I'm not sure where this script is going to be used yet. My boss asked that I try to detect when objects are modified.

0 Likes
Message 6 of 6

kenc
Advocate
Advocate

@MartinBeh 

 

fn CallbackFunc1 NodeEvent1 Obj =

  (

       for o in obj do (appendIfUnique ObjChangedName (GetAnimByHandle o))

  )

 

This does work, thank you.

But, I was just given the word to stop development on this, unfortunately.

Since your code snippet did work for me, I will mark your post Accept Solution.

 

Thank you again. 

0 Likes