Notifications
Clear all

[Closed] Getting merged objects from callback

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

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

/*


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

*/

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
(@timhawker)
Joined: 11 months ago

Posts: 0

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.

Interesting different approaches, thanks.