用maya API获取DAG节点的path和matrix信息

公司来了位在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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值