Created
December 17, 2015 07:30
-
-
Save nrtkbb/d27150dd701e454e2900 to your computer and use it in GitHub Desktop.
シーングラフを照会する http://help.autodesk.com/view/MAYAUL/2016/JPN//?guid=__files_GUID_0B85C721_C3C6_47D7_9D85_4F27B787ABB6_htm
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import sys | |
import maya.OpenMayaMPx as omMPx | |
import maya.OpenMaya as om | |
kPluginCmdName = 'printPaths' | |
class printPathsCmd(omMPx.MPxCommand): | |
def __init__(self): | |
omMPx.MPxCommand.__init__(self) | |
def doIt(self, *args, **kwargs): | |
selections = om.MSelectionList() | |
om.MGlobal.getActiveSelectionList(selections) | |
iterator = om.MItSelectionList(selections, om.MFn.kDagNode) | |
if iterator.isDone(): | |
self.printScene() | |
else: | |
self.printSelectedDAGPaths(iterator) | |
def printSelectedDAGPaths(self, pSelectionListIterator): | |
dagPath = om.MDagPath() | |
dagFn = om.MFnDagNode() | |
print '=======================\n SELECTED DAG OBJECTS: \n=======================' | |
while not pSelectionListIterator.isDone(): | |
pSelectionListIterator.getDagPath(dagPath) | |
try: | |
dagPath.extendToShape() | |
except Exception as e: | |
pass | |
dagObject = dagPath.node() | |
dagFn.setObject(dagObject) | |
name = dagFn.name() | |
apiTypeName = dagObject.apiTypeStr() | |
fntypes = [] | |
om.MGlobal.getFunctionSetList(dagObject, fntypes) | |
print '%s (%s)' % (name, apiTypeName) | |
print '\tDAG path: [%s]' % (dagPath.fullPathName()) | |
print '\tCompatible function sets: %s' % fntypes | |
pSelectionListIterator.next() | |
print '=======================' | |
def printScene(self): | |
dagNodeFn = om.MFnDagNode() | |
dagIterator = om.MItDag( om.MItDag.kDepthFirst, | |
om.MFn.kInvalid) | |
print '=======================\n SCENE GRAPH (DAG): \n=======================' | |
while not dagIterator.isDone(): | |
dagObject = dagIterator.currentItem() | |
depth = dagIterator.depth() | |
dagNodeFn.setObject(dagObject) | |
name = dagNodeFn.name() | |
apiTypeName = dagObject.apiTypeStr() | |
output = ['\t' for i in range(0, depth)] | |
output.append('%s (%s)' % (name, apiTypeName)) | |
print ''.join(output) | |
dagIterator.next() | |
print '=======================' | |
def cmdCreator(): | |
return omMPx.asMPxPtr(printPathsCmd()) | |
def initializePlugin(mobject): | |
mplugin = omMPx.MFnPlugin(mobject) | |
try: | |
mplugin.registerCommand(kPluginCmdName, cmdCreator) | |
except: | |
sys.stderr.write(u'Failed to register command: %s\n' % kPluginCmdName) | |
def uninitializePlugin(mobject): | |
mplugin = omMPx.MFnPlugin(mobject) | |
try: | |
mplugin.deregisterCommand(kPluginCmdName) | |
except: | |
sys.stderr.write(u'Failed to unregister command: %s\n' % kPluginCmdName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment