-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathduplicateAttributes.py
53 lines (45 loc) · 2.45 KB
/
duplicateAttributes.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
from maya import cmds
def dup_attrs():
"""
Duplicate attribute command is buggy in Maya 2017/2018 so i decided to write my own.
Select your transforms that you want to duplicate to first,
lastly select the source transform with attributes you want to duplicate and run the script.
"""
attSel = cmds.ls(sl=True)
destObj = attSel[0:-1]
sourceObj = attSel[-1]
selAttr = cmds.channelBox('mainChannelBox', q=True, sma=True)
for x in selAttr:
attType = cmds.attributeQuery(x, node=sourceObj, attributeType=True)
keyable = cmds.getAttr(sourceObj + '.' + x, k=True)
lock = cmds.getAttr(sourceObj + '.' + x, l=True)
getVal = cmds.getAttr(sourceObj + '.' + x)
if attType == 'bool':
cmds.addAttr(destObj, sn=x, at=attType, keyable=keyable)
elif attType == 'enum':
enumNames = cmds.attributeQuery(x, node=sourceObj, listEnum=True)
cmds.addAttr(destObj, en = enumNames[0], sn=x, at = attType, keyable = keyable)
else:
dv = cmds.attributeQuery(x, node=sourceObj, ld=True)[0]
rangeCheck = cmds.attributeQuery(x, node=sourceObj, re=True)
if rangeCheck:
min = cmds.attributeQuery(x, node=sourceObj, min=True)[0]
max = cmds.attributeQuery(x, node=sourceObj, max=True)[0]
cmds.addAttr(destObj, sn=x, at=attType, keyable=keyable, dv=dv, max=max, min=min)
else:
minCheck = cmds.attributeQuery(x, node = sourceObj, mne = True)
maxCheck = cmds.attributeQuery(x, node = sourceObj, mxe = True)
if minCheck is False and maxCheck is False:
cmds.addAttr(destObj, sn=x, at=attType, keyable=keyable, dv=dv)
if minCheck is True and maxCheck is False:
min = cmds.attributeQuery(x, node=sourceObj, min=True)[0]
cmds.addAttr(destObj, sn=x, at=attType, keyable=keyable, dv = dv, min = min)
if minCheck is False and maxCheck is True:
max = cmds.attributeQuery(x, node=sourceObj, max=True)[0]
cmds.addAttr(destObj, sn=x, at=attType, keyable=keyable, dv = dv, max = max)
for y in destObj:
newAttr = y + '.' + x
cmds.setAttr(newAttr, getVal)
if lock:
cmds.setAttr(newAttr, lock=True)
dup_attrs()