Notifications
Clear all
[Closed] Getting merged objects from callback
Oct 26, 2011 5:14 pm
Hi
Just wondering if there’s a callback for getting an array of objects being file merged into the current scene? I coulnd’t see anything specific in the help, unless I missed something.
I’m about to do a comparison of the scene before and after, just wondering if there was an easier way?
thx
5 Replies
Oct 26, 2011 5:14 pm
I’d do something like this, but probably put it in a struct to avoid lots of globals:
global theNodeEventCallback
global merging = false
global newNodes
function newNodes s e = (
if merging do (
for obj in e do (
print (getAnimByHandle obj)
)
)
)
callbacks.addScript #filePreMerge "merging = true" id:#test
callbacks.addScript #filePostMerge "merging = false" id:#test
theNodeEventCallback = nodeEventCallback added:newNodes
/*
To remove the callbacks:
callbacks.removeScripts id:#test
theNodeEventCallback = undefined --make reference of node callback undefined
gc light:true --run a garbage collection to completely remove node callback
/*
Oct 26, 2011 5:14 pm
Ah, it appears that the filePostMerge callback is fired before the nodeEventCallback.
This code works, and the nodeEventCallback is only enabled when merging.
global theNodeEventCallback
global newNodes
function newNodes s e = (
for obj in e do (
print (getAnimByHandle obj)
)
theNodeEventCallback.enabled = false
)
callbacks.addScript #filePreMerge "theNodeEventCallback.enabled = true" id:#test
theNodeEventCallback = nodeEventCallback added:newNodes
theNodeEventCallback.enabled = false
/*
To remove the callbacks:
callbacks.removeScripts id:#test
theNodeEventCallback = undefined --make reference of node callback undefined
gc light:true --run a garbage collection to completely remove node callback
*/
Oct 26, 2011 5:14 pm
here is my version:
global mergeResult
fn preMergeControl = (mergeResult = objects.count)
fn postMergeControl = (mergeResult = for k = mergeResult + 1 to objects.count collect objects[k])
callbacks.removeScripts id:#merge_control
callbacks.addScript #filePreMerge "preMergeControl()" id:#merge_control
callbacks.addScript #filePostMerge "postMergeControl()" id:#merge_control
1 Reply
Ah of course, any new layers/objects added to the scene will always be at the end of the layer/object array respectively. Cheers for that I’m sure it’ll come in useful.