Are you able to call inner functions from a registered command 'Class'?

18 views
Skip to first unread message

I73

unread,
Dec 4, 2016, 4:30:18 PM12/4/16
to Python Programming for Autodesk Maya
I have a registered command that is assigned to a 'Window' class: 

def initializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject)
try:
mplugin.registerCommand('ui', Window)
except:
sys.stderr.write( "Failed to register node: %s\n" % kPluginNodeTypeName )

class Window(OpenMayaMPx.MPxCommand):
    def doIt(self, argList):
        #parsing arglist with MArgParser with -title, -width, etc... 
       
...

   
def CreateWindow(self, title, width, ...):
       
...

   
def AddButton(self, label, width, ...):
       
...

cmds.ui(t='myWindowTitle', w=200)
# Window Created

What I am looking to do is to be able to call something like: 

#anyway to reference AddButton()?
>>>cmds.ui.AddButton(...)
# Error: AttributeError: file <maya console> line 2: 'function' object has no attribute '
AddButton' # 

This whole 'doit' is a pain in the a$$ seeing how it can't return anything (Or I haven't had any luck with returning objects):
    self.window['window'] = cmds.window('myWindow')
    cmds.showWindow(self.window['window'])
    return self.window['window']

<<<myWindow = cmds.ui(t='MyWindow')
<<<print myWindow
>>>None

Has anyone gotten any form of inner method calls of these commands from cmds calls? It would really help to instance this Window and just attach my elements, if not I don't know how I am going to achieve this...

As usual, thank you for any help or time! 

Justin Israel

unread,
Dec 4, 2016, 5:16:12 PM12/4/16
to python_in...@googlegroups.com
You can't do the approach you are suggesting, because the Maya commands API doesn't have a concept of a "Window" instance that it can return to you. When you write a command plugin you are defining a Maya commands-style call, which can take some parameters, do some work, and then return values that are supported through the setResult() methods. Instances of custom python classes are not one of those things you would be returning. What should a MEL user expect to get back in the results? What would a C++ user get back? 

If you look at how the rest of the Maya commands work, you will see they deal in terms of string paths to objects, and accepting those in other functions to perform edit or create operations. 

 

As usual, thank you for any help or time! 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/03f00036-8089-4d38-8bd5-236ece947d30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages