OpenMaya 選択中のオブジェクトのComponent IDsやPoly Countを取得する

OpenMaya,Plug-in,Tutorial,C++,Maya

この記事はMaya Advent Calendar 2021の10日目の記事です

OpenMayaで選択中のオブジェクトのComponent IDsやPoly Countを取得する逆引きのようなものです

import maya.OpenMaya as OpenMaya

#get mSelection List
SelectionList = OpenMaya.MSelectionList()
OpenMaya.MGlobal.getActiveSelectionList(SelectionList)

#MItSelectionList iteritor for meshes
#filter with mfn class
iterMesh = OpenMaya.MItSelectionList(SelectionList, OpenMaya.MFn.kGeometric)

# selection iterator
while not iterMesh.isDone():
    polyList = []
    dagPath = OpenMaya.MDagPath()
    iterMesh.getDagPath(dagPath)
    fnMesh = OpenMaya.MFnMesh(dagPath)

    # print num information about polycount, vertecescount and etc....
    meshNumPolygons = fnMesh.numPolygons()
    print fnMesh.numPolygons: %s % meshNumPolygons
    meshNumVertices = fnMesh.numVertices()
    print fnMesh.numVertices: %s % meshNumVertices
    meshNumEdges = fnMesh.numEdges()
    print fnMesh.numEdges: %s % meshNumEdges
    meshNumUVs = fnMesh.numUVs()
    print fnMesh.numUVs: %s % meshNumUVs
    meshNumFaceVertices = fnMesh.numFaceVertices()
    print fnMesh.numFaceVertices: %s % meshNumFaceVertices
    meshNumUVSets = fnMesh.numUVSets()
    print fnMesh.meshNumUVSets: %s % meshNumUVSets
    numColors = fnMesh.numColors()
    print fnMesh.numColors: %s % numColors
    meshNumColorSets = fnMesh.numColorSets()
    print fnMesh.meshNumColorSets: %s % meshNumColorSets
    numNormals = fnMesh.numNormals()
    print fnMesh.numNormals: %s % numNormals

    iterMesh.next()