Last active
December 5, 2021 23:20
-
-
Save leixingyu/358f5a9c86278a43852148c87253e3d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Maya Python API 1.0 | |
""" | |
import sys | |
import maya.OpenMayaMPx as mpx | |
import maya.OpenMaya as om | |
pluginName = 'pyTemplate' | |
sampleShortFlagName = '-s' | |
sampleLongFlagName = '-sample' | |
class PyTemplate(mpx.MPxCommand): | |
def __init__(self): | |
mpx.MPxCommand.__init__(self) | |
def doIt(self, args): | |
print 'doIt' | |
self.parseArgument(args) | |
self.redoIt() | |
def redoIt(self): | |
# this is optional | |
print 'redoIt' | |
def undoIt(self): | |
# this is also optional | |
print 'undoIt' | |
def parseArgument(self, args): | |
argData = om.MArgParser(self.syntax(), args) | |
if argData.isFlagSet(sampleShortFlag): | |
self.sample = argData.flagArgumentDouble(sampleShortFlag, 0) | |
print self.sample | |
def isUndoable(self): | |
# this is required when undo and redo is available | |
return True | |
def cmdCreator(): | |
return mpx.asMPxPtr(PyParticle()) | |
def syntaxCreator(): | |
# use this only when custom argument is defined | |
syntax = om.MSyntax() | |
syntax.addFlag(sampleShortName, sampleLongName, om.MSyntax.kDouble) | |
return syntax | |
def initializePlugin(mobject): | |
mplugin = mpx.MFnPlugin(mobject) | |
try: | |
mplugin.registerCommand(pluginName, cmdCreator, syntaxCreator) | |
except: | |
sys.stderr.write('fail to register: ' + pluginName) | |
raise | |
def uninitializePlugin(mobject): | |
mplugin = mpx.MFnPlugin(mobject) | |
try: | |
mplugin.deregisterCommand(pluginName) | |
except: | |
sys.stderr.write('fail to de-register: ' + pluginName) | |
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Maya Python API 2.0 | |
""" | |
import sys | |
import maya.OpenMaya as om | |
pluginName = 'pyTemplate' | |
sampleShortFlagName = '-s' | |
sampleLongFlagName = '-sample' | |
def maya_useNewAPI(): | |
pass | |
class PyTemplate(mpx.MPxCommand): | |
def __init__(self): | |
mpx.MPxCommand.__init__(self) | |
def doIt(self, args): | |
print 'doIt' | |
self.parseArgument(args) | |
def parseArgument(self, args): | |
argData = om.MArgParser(self.syntax(), args) | |
if argData.isFlagSet(sampleShortFlag): | |
self.sample = argData.flagArgumentDouble(sampleShortFlag, 0) | |
print self.sample | |
def cmdCreator(): | |
return PyTemplate() | |
def syntaxCreator(): | |
syntax = om.MSyntax() | |
syntax.addFlag(sampleShortName, sampleLongName, om.MSyntax.kDouble) | |
return syntax | |
def initializePlugin(mobject): | |
mplugin = mpx.MFnPlugin(mobject) | |
try: | |
mplugin.registerCommand(pluginName, cmdCreator, syntaxCreator) | |
except: | |
sys.stderr.write('fail to register: ' + pluginName) | |
raise | |
def uninitializePlugin(mobject): | |
mplugin = mpx.MFnPlugin(mobject) | |
try: | |
mplugin.deregisterCommand(pluginName) | |
except: | |
sys.stderr.write('fail to de-register: ' + pluginName) | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment