サンプルコード
from maya import cmds
# buttonに登録するコマンド
def select_joints():
nodes = cmds.ls(selection=True, dag=True)
joints = []
for node in nodes:
if cmds.nodeType(node) == "joint":
joints.append(node)
cmds.select(joints)
return None
# ボタン付きGUIの生成
button_window = cmds.window("hello_button_window")
button_layout = cmds.columnLayout(adjustableColumn=True, parent=button_window)
buttonA = cmds.button(label="Create Poly Sphere", command="cmds.polySphere()", parent=button_layout)
buttonB = cmds.button(label="Create Poly Cylinder", command="cmds.polyCylinder()", parent=button_layout)
buttonC = cmds.button(label="Select Joints", command="select_joints()", parent=button_layout)
cmds.showWindow(button_window)
# もし、ウインドウが生成できない場合調べる方法
cmds.lsUI(windows=True)
cmds.deleteUI("hello_button_window")
Pythonのおすすめ書籍
コメント