[Closed] Persistent Values Set after filePostMerge Callback?
Hi Guys,
I’ve been having a play with persistent global values as it seems like a way of obtaining data on a file > merge. The only problem is that no matter what callback I try, the persistent value is not showing up. But, after the merge if I shift-enter on the value, the data IS there.
Am I doing something wrong here? Is there a callback I can use that will get the persistent data after a file > merge?
/*
--In max file this was executed:
sphere()
persistent global persistentDataVal = "THIS IS A PERSISTENT STRING"
*/
callbacks.RemoveScripts id:#test
unregisterRedrawViewsCallback redrawViewsFn
function postMerge = (
print "postMerge"
print persistentDataVal
)
callbacks.addScript #filePostMerge "postMerge()" id:#test
function postMergeProcess = (
print "postMergeProcess"
print persistentDataVal
)
callbacks.addScript #filePostMergeProcess "postMergeProcess()" id:#test
function redrawViewsFn = (
print "redrawViews"
print persistentDataVal
)
registerRedrawViewsCallback redrawViewsFn
This is the code I run before merging in the attached max file. I’ve tried filePostMerge, filePostMergeProcessed (Doesn’t seem to fire at all), and viewportRedraw. All of them are showing the value as undefined when they are fired…
Any help is really appreciated!
Never mind, figured it out… It’s amazing what 5 minutes away from the computer screen does.
Turns out you have to send the value to the function, as shown in the code below:
function postMerge val = (
print "postMerge"
print persistentDataVal -- will be undefined
print val --will be the persistent value
)
callbacks.addScript #filePostMerge "postMerge persistentDataVal" id:#test
did you have a chance to look at the mxs help topics – globalVars Structure and Persistents Structure.
it’s very helpful.
Hmm interesting… Thanks for the link to the two related structs. I’d never thought about accessing and setting global values that way before.
I don’t have a copy of 3ds Max handy at the moment, but according to the documentation this should work:
function postMerge val = (
print "postMerge"
persistents.show() --new persistent value should be contained here, as well as all others.
if globalVars.isglobal #persistentDataVal do (
print (globalVars.get #persistentDataVal)
)
)
callbacks.addScript #filePostMerge "postMerge" id:#test
I noticed there is also a method for setting a global value, although this method would probably be slower than directly setting the value. But it would be a way of knowing the value definitely is registered as global.
globalVars.set #persistentDataVal "New Value"
--Insead of:
persistentDataVal = "New Value"
Nope, seems the code above doesn’t work. Oh well, at least it works in the second post.