-
Notifications
You must be signed in to change notification settings - Fork 0
/
joint_generator.py
93 lines (75 loc) · 3.13 KB
/
joint_generator.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import maya.cmds as cmds
''' Simple form to create chain of joints.
It allows user to fill prefix of joints names, their amount, spacing
and orientation
'''
window_name = 'joint_generator_win'
if cmds.window(window_name, exists=True):
cmds.deleteUI(window_name, window=True)
win = cmds.window(window_name, t="Joint Window", width=100, s=False) # not resizable
cmds.columnLayout('c_layout', adj=True)
cmds.separator()
cmds.text('Define joint(s)')
cmds.separator()
cmds.textFieldGrp("jntName", l="Prefix:")
cmds.textFieldGrp("jntAmount", l="Amount of joints:")
cmds.textFieldGrp("jntSpacing", l="Spacing of joints:")
cmds.separator()
cmds.text('Choose orientation')
cmds.separator()
cmds.button('b_xyz', l='XYZ', height=30, c='xyz()', p='c_layout')
cmds.button('b_yxz', l='YXZ', height=30, c='yxz()', p='c_layout')
cmds.button('b_zxy', l='ZXY', height=30, c='zxy()', p='c_layout')
cmds.showWindow(win)
def xyz():
''' Create chain of joints with xyz orientation '''
name, amount, spacing = get_values()
cmds.select(cl=True) # clear selection
if amount == '1':
joint = cmds.joint(n='jointSpine_0')
cmds.setAttr(joint + '.jointOrientX', -90)
cmds.setAttr(joint + '.jointOrientY', 0)
cmds.setAttr(joint + '.jointOrientZ', 90)
else:
create_joint_chain(name, int(amount), int(spacing), 'xyz')
def yxz():
''' Create chain of joints with yxz orientation '''
name, amount, spacing = get_values()
cmds.select(cl=True)
if amount == '1':
joint = cmds.joint(n='jointSpine_0')
cmds.setAttr(joint + '.jointOrientX', 0)
cmds.setAttr(joint + '.jointOrientY', 0)
cmds.setAttr(joint + '.jointOrientZ', 0)
else:
create_joint_chain(name, int(amount), int(spacing), 'yxz')
def zxy():
''' Create chain of joints with zxy orientation '''
name, amount, spacing = get_values()
cmds.select(cl=True)
if amount == '1':
joint = cmds.joint(n='jointSpine_0')
cmds.setAttr(joint + '.jointOrientX', 0)
cmds.setAttr(joint + '.jointOrientY', 0)
cmds.setAttr(joint + '.jointOrientZ', 90)
else:
create_joint_chain(name, int(amount), int(spacing), 'zxy')
def get_values():
''' Auxiliary function to get string values from form '''
name = cmds.textFieldGrp("jntName", q=True, tx=True)
amount = cmds.textFieldGrp("jntAmount", q=True, tx=True)
spacing = cmds.textFieldGrp("jntSpacing", q=True, tx=True)
return name, amount, spacing
#NUM_OF_JOINTS = 3
def create_joint_chain(name, amount, spacing, orient):
''' Create chain of 'amount' joints with 'name' prefix, 'spacing' far from each other
with 'orient' orientation
'''
for i in range(amount):
cmds.joint(n='{}_{}'.format(name, i))
cmds.move(0, spacing*i, 0)
cmds.joint('{}_0'.format(name), edit=True, oj=orient, children=True)
selected_joints = cmds.ls(sl=True)
cmds.setAttr(selected_joints[0] + '.jointOrientX', 0)
cmds.setAttr(selected_joints[0] + '.jointOrientY', 0)
cmds.setAttr(selected_joints[0] + '.jointOrientZ', 0)