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
import maya.api.OpenMaya as om2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
print(selList) | |
mDagPath1 = selList.getDagPath(0) | |
print("mDagPath1 = %s" %mDagPath1.fullPathName()) | |
mDagPath2, mObject = selList.getComponent(0) | |
print("mDagPath2 = %s - mObject = %s\n" %(mDagPath2.fullPathName(), mObject)) |
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
import maya.api.OpenMaya as om2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
selListIter = om2.MItSelectionList(selList, om2.MFn.kTransform) | |
print("selListIter type = %s" %type(selListIter)) | |
# 注意点 この MItSelectionList のように MIt~ で始まっているクラスはイテレータなので | |
# 戻り値を普通のリストのように for でまわしても中身を取得できません。 | |
# while not iter.isDone() でまわして、且つ next() を書かないと | |
# 次のアイテムにいけず無限ループに陥るのでのでご注意を… |
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
import maya.api.OpenMaya as om2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
mObject = selList.getDependNode(0) # .getComponent()で取得できる MObject を使ってもよい | |
print("mObject apiTypeStr = %s" %mObject.apiTypeStr) | |
# 上記の apiTypeStr は文字列で kTransform だとか kMesh という風に返ってくるが、 | |
# dagPath が持つ apiType() メソッドは MFn クラスに定義してあるタイプのIDがintで返ってくる | |
print("mDagPath2 apiType = %s" %mDagPath2.apiType()) |
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
import maya.api.OpenMaya as om2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
mDagPath = selList.getDagPath(0) | |
if mDagPath.hasFn(om2.MFn.kMesh): | |
transform = om2.MFnTransform(mDagPath) | |
print("transform = %s" %transform.fullPathName()) | |
mesh = om2.MFnMesh(mDagPath) | |
mesh2 = mDagPath.extendToShape() # こんな方法もあります |
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
import maya.api.OpenMaya as om2 | |
dgModifier = om2.MDGModifier() | |
dgModifier.renameNode(mObject, "hogehoge") # 第1引数は MObject で、第2引数に 変更したい名前 です | |
dgModifier.doIt() # この doIt() を書き忘れると実行されないのでご注意を |
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
import maya.api.OpenMaya as om2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
mDagPath = selList.getDagPath(0) | |
transform = om2.MFnTransform(mDagPath) | |
trs = transform.translation(om2.MSpace.kTransform) | |
print("translation = %s" %trs) | |
trsW = transform.translation(om2.MSpace.kWorld) |
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
import maya.api.OpenMaya as om2 | |
import maya.api.OpenMayaAnim as oma2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
mObject = selList.getDependNode(0) | |
# findPlug を使って取得する場合 | |
dependencyNode = om2.MFnDependencyNode(mObject) | |
transXplug = dependencyNode.findPlug('tx', 0) |
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
import maya.api.OpenMaya as om2 | |
import maya.OpenMaya as om | |
selList = om2.MGlobal.getActiveSelectionList() | |
mDagPath = selList.getDagPath(0) | |
objectName = om.MFnDependencyNode(mDagPath.transform()).name() | |
# 残念ならがまだ Python API 2.0 の方に MFnExpression クラスが移植されていないようなので1.0の方を使います | |
exp = om.MFnExpression() | |
exp.create("%s.rotateY = time * 10;" % objectName) # 中身はいつものExpressionを書く |
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
import maya.api.OpenMaya as om2 | |
selList = om2.MGlobal.getActiveSelectionList() | |
mDagPath = selList.getDagPath(0) | |
mesh = om2.MFnMesh(mDagPath) | |
# ColorSetの名前一覧を取得 | |
colorSetNames = mesh.getColorSetNames() | |
print(colorSetNames) # stringのTupleで返ってきます |
OlderNewer