Describes the contents of the Maya command plug-in for beginners.
--What is a command plugin? ――How can you use the command plug-in? ――What kind of reference article do you have?
You don't see much information about command plugins. By the way, I didn't use it at all ... So my aim is to write an introductory article for myself. Anyway, the content is light because I think I will increase the number of articles about Maya Python.
Official Help says:
Define a new custom MEL command and respond accordingly add functions to the maya.cmds Python module so they can be used in scripts.
In short, you can call your own Python module directly from cmds.
Anyway, it's quick to write and use it. So, let's write the function of cmds.ls (sl = True) with a command plugin. The following code is based on (or copied) from Maya Help.
command_select.py
# -*- coding: utf-8 -*-
import maya.api.OpenMaya as OpenMaya
def maya_useNewAPI():
pass
class CommandSelection(OpenMaya.MPxCommand):
kPluginCmdName = "selection"
def __init__(self):
OpenMaya.MPxCommand.__init__(self)
@staticmethod
def cmdCreator():
return CommandSelection()
def doIt(self, args):
self.setResult(list(OpenMaya.MGlobal.getActiveSelectionList().getSelectionStrings()))
def initializePlugin(mobject):
plugin = OpenMaya.MFnPlugin(mobject)
plugin.registerCommand(CommandSelection.kPluginCmdName, CommandSelection.cmdCreator)
def uninitializePlugin(mobject):
pluginFn = OpenMaya.MFnPlugin(mobject)
pluginFn.deregisterCommand(CommandSelection.kPluginCmdName)
command_select_doit.py
cmds.selection()
>>> # Result: [u'pPlane2', u'pPlane1'] #
The return value of the command is not a return statement! (Prejudice) When I check Help, it says setResult (), so I call it with doIt ().
When I tried to setResult () my own class to improve it a little,
An error occurs with # Command results must be string or numeric.
.
I haven't investigated the case of other parent classes, but I wonder if the command plugin can only return strings or numbers.
Classes prefixed with> ** MPx ** are called proxy classes and are called proxy classes.
Used to create various plugin types.
So I looked at the Reference to see what other classes are available. Which parent should be inherited according to the plugin you want to make? I need more study.
Class | Description |
---|---|
MPxAttributePatternFactory | Base class for custom attribute pattern factories. |
MPxCommand | Base class for custom commands. |
MPxData | Base Class for User-defined Dependency Graph Data Types. |
MPxGeometryData | Base Class for User-defined Dependency Graph Geometry Data Types. |
MPxGeometryIterator | Base class for user defined geometry iterators. |
MPxNode | Base class for user defined dependency nodes. |
MPxSurfaceShape | Parent class of all user defined shapes. |
If you use a command plug-in for processing that seems to be used very often, the amount of code will be reduced and it may be easier. It can also be used as a MEL command, so it may be useful for MELer artists. I would like to continue studying while waiting for advice and advice from various fields.
-Digital Matrix Simple Plugin -Digital Matrix Command to check selected node -[Autodesk Knowledge Network: Command Plugin](https://knowledge.autodesk.com/en/support/maya/learn-explore/caas/documentation/MAYAUL/2014/JPN/Maya-API-Documentation/files/Command -plugins-htm.html)
Recommended Posts