Build tree (xform+Maya Event)

前言

透過監聽click事件,在被選取的點上建立object。

法一:
http://discourse.techart.online/t/execute-python-script-in-maya-on-double-click/2171
http://download.autodesk.com/us/maya/2010help/CommandsPython/draggerContext.html
draggerContext

法二:
https://stackoverflow.com/questions/32090392/how-to-get-from-maya-event-of-a-change-highlight-objects-in-the-scene
https://www.mail-archive.com/[email protected]/msg06838.html
http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__py_ref_class_open_maya_1_1_m_event_message_html
http://discourse.techart.online/t/how-to-properly-define-callbacks-and-delete-them-later-in-maya/6041

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import maya.cmds as cmd
import maya.OpenMaya as OpenMaya
def create_Obj():
cube_height = 6
cube = cmd.polyCube(sx=1, sy=1, sz=1, w=0.5, d=0.5, h=cube_height)
cmd.move(0, cube_height / 2, 0, cube)
cone_height = 2
cone = cmd.polyCone(r=1, h=cone_height)
cmd.move(0, cone_height / 2 + cube_height, 0, cone)
cmd.select(cube,cone)
cmd.group(n='TreeGrp#')
def clicked(self):
mySelection = cmd.ls(selection=True)
print mySelection
mySelPosition = cmd.xform(mySelection, q=True, ws=True, t=True)
print mySelPosition
Obj = create_Obj()
cmd.move(mySelPosition[0], mySelPosition[1], mySelPosition[2], Obj)
return
idx = OpenMaya.MEventMessage.addEventCallback("SelectionChanged", clicked)
#when ever you finish doing your stuff
OpenMaya.MMessage.removeCallback(idx)

凸型平面作法

  1. 建立平面
  2. select by component type
  3. press B
  4. use move tool

Demo

凸型平面作法

  1. 建立平面
  2. select by component type
  3. press B

Troubleshooting

Python compiler error, x takes no arguments (1 given)
https://stackoverflow.com/questions/4445405/python-compiler-error-x-takes-no-arguments-1-given

def function(self):

參考

https://www.youtube.com/watch?v=hDDgs3hrSsU&list=PLdQnt7xu73OXBjKNlsA-lX9tWATVUjtA9&index=6