On Mon, Dec 5, 2016 at 10:30 AM I73 <[email protected]> wrote:
> 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...
>
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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/03f00036-8089-4d38-8bd5-236ece947d30%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/03f00036-8089-4d38-8bd5-236ece947d30%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1%3D%3Dtq9Y6q%3D8U_%3DPBgACjccHnZqD0XYiGiqf1pwvNp4zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.