公司来了位在autodesk工作十年的大神,最近给我们培训maya API这块儿的东西,感觉学到不少东西,这是第二节课,她给我们布置的作业是写个带flag的command,具体说就是用api获取选择物体的dagpath,并且添加个flag——verbos,如果有这个flag的话,那么就打出这个物体的inclusiveMatrix和exclusiveMatrix,自己用python API写了一下,又用C++写了下,最后C++在打印矩阵的格式时不是很理想,等以后有时间再完善之,下面分别是二者的代码。
Python
import sys
import maya.api.OpenMaya as om
def maya_useNewAPI(): pass
class DagInfoCommand(om.MPxCommand):
commandName = 'dagInfo'
verbosFlag = '-v'
verbosFlagLong = '-verbos'
helpFlag = '-h'
helpFlagLong = '-help'
helpText = '\nThe dagInfo command is used to get dag node path and matrix\n'
def __init__(self):
om.MPxCommand.__init__(self)
@staticmethod
def creator():
return DagInfoCommand()
def doIt(self, args):
try:
argDatabase = om.MArgDatabase(self.syntax(), args)
except RuntimeError:
om.MGlobal.displayError('Error while parsing arguments:\n#\t# If passing in list of nodes, also check that node names exist in scene.')
raise
help = argDatabase.isFlagSet(DagInfoCommand.helpFlag)
if help:
self.setResult(DagInfoCommand.helpText)
return
activeObjects = om.MGlobal.getActiveSelectionList()
iterObjects = om.MItSelectionList(activeObjects)
verbos = argDatabase.isFlagSet(DagInfoCommand.verbosFlag)
while not iterObjects.isDone():
path = iterObjects.getDagPath()
fullPath = path.fullPathName()
p