Py3dsMax: global functions

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

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

did you try fileIn() ?

I'm not use Python but am pretty sure it execute in global scope, and using FileIn() function looks quite enough anyway as it also executed in global scope context.

my recent MAXScripts RSS (archive here)

br0t's picture

I did not use fileIn, but

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.

mxs.callbacks.addScript(mxs.pyhelper.namify("viewportChange"), "python.exec(\"ViewWatcher.syncView()\")", id = mxs.pyhelper.namify("viewWatcher"))

This is still quite a hack, but working so far, thanks for the suggestion Anubis.

Never get low & slow & out of ideas

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.