ScriptSpot

Forum topic · General Scripting

Py3dsMax: global functions

By br0t · 2013-02-25

Description

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 (2)

did you try fileIn() ?

Anubis · 2013-02-25

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.

br0t · 2013-03-10

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.