Unity・3DCG技術ブログ

TAもどきによるUnity・3DCGに関する記事をアップします。

【Maya】Pythonスクリプティング基本メモ

概要

MayaでのPythonの基本的なスクリプティングについて覚えたことのメモ

環境

シーン

シーン内のオブジェクトを列挙

オブジェクトにtransformは必ずあるのでtype="transform"で絞るとシーン内のオブジェクトが取れるって感じですね。

import maya.cmds as cmds

objs = cmds.ls(type="transform")
for o in objs:
    print(o)

# 出力例
front
joint1
joint2
joint3
pSphere
pSphere4
pSphere5
pSphere6
persp
side
top

選択中のオブジェクトを列挙

lsでselection=Trueを渡して選択中のオブジェクトが返ってきます。

import maya.cmds as cmds

objs = cmds.ls(selection=True);
for obj in objs:
    print(obj)

シーン名

開いているシーン名=ファイル名なのでfileコマンドで取得します。

import maya.cmds as cmds
import os.path as path

# シーンへのパス
scenePath = cmds.file(query=True,sceneName=True)
print(scenePath)

# ファイル名
sceneName = path.basename(scenePath).replace(".mb","")
print(sceneName)

# 出力例
D:/MayaTraining/Test.mb
Test

コンポーネント

利用可能なコンポーネントタイプ名の取得

import maya.cmds as cmds

avairableTypes = cmds.ls(nt=True)
for tp in avairableTypes:
    print(tp)

# 出力例
AISEnvFacade
AlembicNode
BifMeshImportNode
BossBlender
BossEXRInfluence
BossGeoProperties
BossSpectralWave
BossWaveSolver
ComputeGlobal
ComputeLocal
...長いので略