def copyAttrState(srcNode, destNode , *sAttrList): logMsg(log='all') sSrcNode = argToStr(srcNode) sDestNode = argToStr(destNode) for sAttr in sAttrList: sDestNodeAttr = getObject(sDestNode + "." + sAttr) if sDestNodeAttr: sSrcNodeAttr = sSrcNode + "." + sAttr mc.setAttr(sDestNodeAttr, k=mc.getAttr(sSrcNodeAttr, k=True), l=mc.getAttr(sSrcNodeAttr, l=True), cb=mc.getAttr(sSrcNodeAttr, cb=True))
def copyAttrs(srcNode, destNode, *sAttrList, **kwargs): logMsg(log='all') if "values" not in kwargs: kwargs["values"] = True bDelete = kwargs.pop("delete", False) bCreate = kwargs.pop("create", False) sSrcNode = argToStr(srcNode) sDestNode = argToStr(destNode) mObj = api.getNode(sSrcNode) fnNode = om.MFnDependencyNode(mObj) sCopyAttrList = [] for sAttr in sAttrList: if not getObject(sDestNode + "." + sAttr): if bCreate: mAttr = om.MFnAttribute(fnNode.attribute(sAttr)) sAddAttrCmd = mAttr.getAddAttrCmd(False).replace(";", " {};".format(sDestNode)) logMsg("Copy attr. '{}' from '{}' to '{}'." .format(sAttr, sSrcNode, sDestNode), log="info") pm.mel.eval(sAddAttrCmd) else: sAttr = "" else: if bCreate: logMsg("Attr. '{}' already exists on '{}'.".format(sAttr, sDestNode), log="info") if sAttr: sCopyAttrList.append(sAttr) mc.copyAttr(sSrcNode, sDestNode, attribute=sCopyAttrList, **kwargs) #copyAttrState(sSrcNode, sDestNode , *sCopyAttrList) if bDelete: for sAttr in sCopyAttrList: mc.deleteAttr(sSrcNode + "." + sAttr) return sCopyAttrList