def transfer_attrs(*args):
"""
transfers attrs and connections from second obj to first object selected
"""
tgt, src = get_source_and_targets()
if not tgt or len(src) > 1:
cmds.warning("Select only one target then one source obj to transfer the attributes and connections!")
return ()
attrs = cmds.channelBox('mainChannelBox', q=True, selectedMainAttributes=True)
if not attrs:
cmds.warning("You have to select at least one attr on last object selected to transfer!")
return ()
for attr in attrs:
attrType, hasMin, attrMin, hasMax, attrMax, value, inConnection, outConnection, locked = get_channel_attributes(
src[0], attr)
if not attrType == "enum":
# create attribute
if not cmds.attributeQuery(attr, node=tgt, exists=True):
if hasMin and not hasMax:
cmds.addAttr(tgt, ln=attr, at=attrType, min=attrMin[0], dv=value, k=True)
elif hasMax and not hasMin:
cmds.addAttr(tgt, ln=attr, at=attrType, max=attrMax[0], dv=value, k=True)
elif hasMin and hasMax:
cmds.addAttr(tgt, ln=attr, at=attrType, min=attrMin[0], max=attrMax[0], dv=value, k=True)
else:
cmds.addAttr(tgt, ln=attr, at=attrType, dv=value, k=True)
else:
cmds.warning("The attribute: {0} already exists. Skipping creation!".format(attr))
# lock
if locked:
cmds.setAttr("{0}.{1}".format(tgt, attr), l=True)
else:
cmds.warning("I don't do enums at the moment!")
# connect tgt attr to connection, forced
if inConnection:
cmds.connectAttr(inConnection[0], "{0}.{1}".format(tgt, attr))
if outConnection:
for conn in outConnection:
cmds.connectAttr("{0}.{1}".format(tgt, attr), conn, force=True)
评论列表
文章目录