So I am trying to make some stuff work from a python script, and I'd like to use callbacks, which as we know need a global function to work. So far I have this (with "mxs" being the maxscript commands imported to my python script):
mxs.callbacks.addScript(mxs.pyhelper.namify("selectionSetChanged"), "addChangeHandlersToSelected()", id = mxs.pyhelper.namify("objectWatcher"))
and it works in adding the callback, but it does NOT find the function "addChangeHandlersToSelected" because that is a python function of my class. How do I declare this as a global function that is found in 3ds Max by the callback?
I could probably write all of it as a big string and just execute that, but I want to be a bit more professional...
Cheers
By
Comments (2)
Comment policy
did you try fileIn() ?
I'm not use Python but am pretty sure it execute in global scope, and using
function looks quite enough anyway as it also executed in global scope context.
I did not use fileIn, but your idea was correct! I now used a static python class, which method is accessed by the callback. The problem was, that the classname (ViewWatcher) is meaningless to the MAXScript callback if I only execute my script file. I had to use "python.run( myPythonModuleFile.py )" prior to anything else so the classes are accessible through MAXScript.
This is still quite a hack, but working so far, thanks for the suggestion Anubis.