window4.py を作り、下図のようにボタンを 3 つ並べて、それぞれのボタンで違う NURBS プリミティブを作るスクリプトを
PyMELを利用しオブジェクト指向で作ってください。
上から順番に NURBS の球、コーン、キューブを作るボタンを配置してください。
(実行方法 1)
import pymel.core as pm
win = Window(title='window4')
win.addButton(label='sphere', command=pm.sphere)
win.addButton(label='cone', command=pm.cone)
win.addButton(label='nurbsCube', command=pm.nurbsCube)
win.show()
(実行方法 2)
import pymel.core as pm
win = Window(title='window4')
win.show()
win.addButton(label='sphere', command=pm.sphere)
win.addButton(label='cone', command=pm.cone)
win.addButton(label='nurbsCube', command=pm.nurbsCube)
(解答例)
import pymel.core as pm
class Window(object):
def __init__(self, title='window', layout=pm.columnLayout):
pm.window(title=title)
self.topLayout = layout()
def _doNothing(self):
pass
def addButton(self, label='button', command=None):
if not command:
command = self._doNothing
pm.setParent(self.topLayout)
pm.button(label=label, command=pm.Callback(command))
pm.setParent('..')
def show(self):
pm.showWindow()
win = Window(title='window4')
win.show()
win.addButton(label='sphere', command=pm.sphere)
win.addButton(label='cone', command=pm.cone)
win.addButton(label='nurbsCube', command=pm.nurbsCube)