def resetAttributes(node, N_name=False): attrs = getAttributes(node) for attr in attrs: if N_name: name = cmds.attributeName(node + '.' + attr) attribute_names.append(name) if not N_name: name = cmds.attributeName(node + '.' + attr, long=True) attribute_names.append(name)
def attrsAtDefault(obj, attrList=None, tol=0.000001): """ Check object attributes are at default values. @param tol: @param obj: Object to check default attribute values on. @type obj: str @param attrList: List of attributes to check. @type attrList: list or None """ # Check Object if not cmds.objExists(obj): print('Object "' + obj + '" does not exist! Returning False...') return False # Check Attribute List if not attrList: attrList = [] attrList += cmds.listAttr(obj, k=True) or [] attrList += cmds.listAttr(obj, cb=True) or [] # Get List of User Defined Attributes udAttrList = [ cmds.attributeName(obj + '.' + at, s=True) for at in cmds.listAttr(obj, ud=True) or [] ] # Check Attribute Values for at in attrList: # Check Attribute Exists if not cmds.attributeQuery(at, n=obj, ex=True): print('Object attribute "' + obj + '.' + at + '" not found!') continue # Check Value attr = cmds.attributeName(obj + '.' + at, s=True) if attr in ['tx', 'ty', 'tz', 'rx', 'ry', 'rz']: # Translate / Rotate if abs(cmds.getAttr(obj + '.' + attr)) > tol: return False elif attr in ['sx', 'sy', 'sz']: # Scale if abs(1.0 - cmds.getAttr(obj + '.' + attr)) > tol: return False else: # User Defined if attr in udAttrList: defVal = cmds.addAttr(obj + '.' + attr, q=True, dv=True) if abs(defVal - cmds.getAttr(obj + '.' + attr)) > tol: return False # ================= # - Return Result - # ================= return True
def sortCB(): sel = cmds.ls(sl=1) for geo in sel: attrs1 = cmds.listAttr(geo, k=1) p2ps1 = [] p2ps = [] envs = [] scus = [] for a in attrs1: if a.endswith('_scu'): scus.append(a) if a.endswith('_p2p'): p2ps1.append(a) if a.endswith('Envelope'): envs.append(a) scus.sort(key=sortKey) if p2ps1: p2ps1.sort(key=sortKey) envs.sort(key=sortKey) lv = 1 if envs: p2ps = [envs[0]] for i in p2ps1: if 'lv{}_'.format(lv) not in i: lv += 1 p2ps.append(envs[lv - 1]) p2ps.append(i) if scus: #for a in scus: # cmds.setAttr ('{}.{}'.format (geo,a), l = 0) for a in scus: cmds.deleteAttr(geo, at=a) mel.eval('Undo;') nn = cmds.attributeName('{}.{}'.format(geo, a), nice=1) #if '(EDIT^)' in nn: # cmds.setAttr ('{}.{}'.format (geo,a), l = 1) if p2ps1: #for a in p2ps: # cmds.setAttr ('{}.{}'.format (geo,a), l = 0) for a in p2ps: cmds.deleteAttr(geo, at=a) mel.eval('Undo;') nn = cmds.attributeName('{}.{}'.format(geo, a), nice=1) #if '(EDIT^)' in nn: # cmds.setAttr ('{}.{}'.format (geo,a), l = 1) sys.stdout.write('Sorted channel box using the deleteAttr/undo trick.')
def attrsAtDefault(obj, attrList=None, tol=0.000001): """ Check object attributes are at default values. @param tol: @param obj: Object to check default attribute values on. @type obj: str @param attrList: List of attributes to check. @type attrList: list or None """ # Check Object if not cmds.objExists(obj): print('Object "' + obj + '" does not exist! Returning False...') return False # Check Attribute List if not attrList: attrList = [] attrList += cmds.listAttr(obj, k=True) or [] attrList += cmds.listAttr(obj, cb=True) or [] # Get List of User Defined Attributes udAttrList = [cmds.attributeName(obj + '.' + at, s=True) for at in cmds.listAttr(obj, ud=True) or []] # Check Attribute Values for at in attrList: # Check Attribute Exists if not cmds.attributeQuery(at, n=obj, ex=True): print('Object attribute "' + obj + '.' + at + '" not found!') continue # Check Value attr = cmds.attributeName(obj + '.' + at, s=True) if attr in ['tx', 'ty', 'tz', 'rx', 'ry', 'rz']: # Translate / Rotate if abs(cmds.getAttr(obj + '.' + attr)) > tol: return False elif attr in ['sx', 'sy', 'sz']: # Scale if abs(1.0 - cmds.getAttr(obj + '.' + attr)) > tol: return False else: # User Defined if attr in udAttrList: defVal = cmds.addAttr(obj + '.' + attr, q=True, dv=True) if abs(defVal - cmds.getAttr(obj + '.' + attr)) > tol: return False # ================= # - Return Result - # ================= return True
def rsAttributeData(s_oAttribute): l_attributeData = [] l_attributes = [] try: s_atName = cmds.attributeName(s_oAttribute, l=True) except: raise RuntimeError("It is not an attribute") s_parent = s_oAttribute.split(".")[0] l_Siblings = "" l_SiblingsPa = cmds.attributeQuery(s_atName, node=s_parent, listParent=True) if l_SiblingsPa != None: s_oAttribute = "%s.%s" % (s_parent, l_SiblingsPa[0]) s_atName = cmds.attributeName(s_oAttribute, l=True) l_attributes.append(s_atName) s_atType = cmds.getAttr(s_oAttribute, type=True) if s_atType == "double3": l_Siblings = cmds.attributeQuery(s_atName, node=s_parent, listChildren=True) for o_sib in l_Siblings: l_attributes.append(o_sib) for s_atName in l_attributes: s_oAttribute = "%s.%s" % (s_parent, s_atName) s_atType = cmds.getAttr(s_oAttribute, type=True) s_atNiceName = cmds.attributeQuery(s_atName, node=s_parent, niceName=True) i_atLock = cmds.getAttr(s_oAttribute, lock=True) l_attributeDataTemp = [s_atType, s_parent, s_atName, s_oAttribute, s_atNiceName, i_atLock] if s_atType == "string": s_stringValue = cmds.getAttr(s_oAttribute) l_attributeDataTemp.append(s_stringValue) return (l_attributeDataTemp, None) i_atKey = cmds.getAttr(s_oAttribute, keyable=True) i_atHidden = cmds.getAttr(s_oAttribute, channelBox=True) l_attributeDataTemp.append(i_atKey) l_attributeDataTemp.append(i_atHidden) if s_atType == "enum": s_enum = (cmds.attributeQuery(s_atName, node=s_parent, listEnum=True))[0] l_enum = s_enum.split(':') l_attributeDataTemp.append(l_enum) return (l_attributeDataTemp, None) if s_atType != "double3": s_hasMin = cmds.addAttr(s_oAttribute, query=True, hasMinValue=True) f_atMinValue = 0 if s_hasMin: f_atMinValue = (cmds.attributeQuery(s_atName, node=s_parent, minimum=True))[0] s_hasMax = cmds.addAttr(s_oAttribute, query=True, hasMaxValue=True) f_atMaxValue = 0 if s_hasMax: f_atMaxValue = (cmds.attributeQuery(s_atName, node=s_parent, maximum=True))[0] f_atDefValue = (cmds.attributeQuery(s_atName, node=s_parent, listDefault=True))[0] l_rest = [s_hasMin, f_atMinValue, s_hasMax, f_atMaxValue, f_atDefValue] l_attributeDataTemp.extend(l_rest) l_attributeData.append(l_attributeDataTemp) return (l_attributeData)
def rsSubsParam(s_source, s_target, b_delSrcAttr=0): s_parent = s_source.split(".") s_parentTarget = s_target.split(".") try: cmds.attributeName(s_source, l=True) except: raise RuntimeError("%s - It is not an attribute" % (s_source)) b_att = True try: cmds.attributeName(s_target, l=True) except: b_att = False if b_att: l_attributeData = rsAttributeData(s_source) if l_attributeData[0][0] == "double3": l_attributeDataTarget = rsAttributeData(s_target) if l_attributeDataTarget[0][0] == "double3": s_sourceVec = "%s.%s" % (s_parent[0], l_attributeData[0][2]) i_sourceLock = cmds.getAttr(s_sourceVec, lock=True) for i in range(len(l_attributeData)): s_sourceObj = "%s.%s" % (s_parent[0], l_attributeData[i][2]) s_targetObj = "%s.%s" % (s_parentTarget[0], l_attributeDataTarget[i][2]) rsSubsParamExecute(s_sourceObj, s_targetObj, 0) if b_delSrcAttr == True: if i_sourceLock: cmds.setAttr(s_sourceVec, lock=0) cmds.deleteAttr(s_sourceVec) else: cmds.warning("Source and Target types are not similar") else: rsSubsParamExecute(s_source, s_target, b_delSrcAttr) else: if cmds.objExists(s_target): l_attributeData = rsAttributeData(s_source) rsCloneAttribute(l_attributeData, s_target) if l_attributeData[0][0] == "double3": s_sourceVec = "%s.%s" % (s_parent[0], l_attributeData[0][2]) i_sourceLock = cmds.getAttr(s_sourceVec, lock=True) for i in range(len(l_attributeData)): s_sourceObj = "%s.%s" % (s_parent[0], l_attributeData[i][2]) s_targetObj = "%s.%s" % (s_target, l_attributeData[i][2]) rsSubsParamExecute(s_sourceObj, s_targetObj, 0) if b_delSrcAttr == True: if i_sourceLock: cmds.setAttr(s_sourceVec, lock=0) cmds.deleteAttr(s_sourceVec) else: s_target = "%s.%s" % (s_target, l_attributeData[0][2]) rsSubsParamExecute(s_source, s_target, b_delSrcAttr) else: raise RuntimeError("%s - Object do not exists" % (s_target)) return True
def get_attribute(): """ Get selected attribute from channelbox """ return set( "{}.{}".format(o, cmds.attributeName("{}.{}".format(o, at), l=True)) for o in cmds.ls(sl=True) for at in cmds.channelBox("mainChannelBox", sma=True, q=True) or [] if cmds.attributeQuery(at, n=o, ex=True))
def __init__( self, channel, objects): self.channel = mc.listAttr( objects[0] + '.' + channel)[0] self.niceName = mc.attributeName( objects[0] + '.' + self.channel, nice=1) self.objects = [] for obj in objects: # IF the channel is settable for this object add the object to the list if mc.getAttr( obj + '.' + self.channel, se=1) : self.objects.append( SelChnlObj( self.channel, obj))
def ATT_INCREMENT(iAmount): # Attribute Increment v3.0.0 oChannel = [ str(c + '.' + cmds.attributeName(c + '.' + b, l=True)) for a in 'msho' for b in cmds.channelBox('mainChannelBox', **{ 'q': True, 's%sa' % a: True }) or [] for c in cmds.channelBox( 'mainChannelBox', q=True, **{'%sol' % a: True}) ] if oChannel: for c in oChannel: iVal = cmds.getAttr(c) cmds.setAttr(c, iVal + iAmount) if iAmount >= 0.01: aPrint = ['a7a8af', '+' + str(iAmount), 0x6b6c75, 'botCenter'] else: aPrint = ['d8766c', '+' + str(iAmount), 0x756b6b, 'botCenter'] else: aPrint = ['d8766c', 'No Attr Selected', 0x756b6b, 'topCenter'] cmds.inViewMessage(amg='<text style="color:#%s";>%s</text>' % (aPrint[0], aPrint[1]), pos=aPrint[3], fade=True, fts=10, ft='arial', bkc=aPrint[2])
def connectShape(self, shape, mesh=None, live=False, delete=False): """ Force a shape to match a mesh The "connect shape" button is: mesh=None, delete=True The "match shape" button is: mesh=someMesh, delete=False There is a possibility of a "make live" button: live=True, delete=False """ if mesh is None: attrName = cmds.attributeName(shape.thing, long=True) mesh = "{0}_Extract".format(attrName) if not cmds.objExists(mesh): return index = self._getShapeIndex(shape) tgn = "{0}.inputTarget[0].inputTargetGroup[{1}]".format( self.shapeNode, index) cnx = mesh + 'Shape' if cmds.nodeType(mesh) == 'transform' else mesh outAttr = "{0}.worldMesh[0]".format( cnx) # Make sure to check the right shape object inAttr = "{0}.inputTargetItem[6000].inputGeomTarget".format(tgn) if not cmds.isConnected(outAttr, inAttr): cmds.connectAttr(outAttr, inAttr, force=True) if not live: cmds.disconnectAttr(outAttr, inAttr) if delete: cmds.delete(mesh)
def applyEdit(geo, scu, drv, lv=1, ihi=1): if cmds.objExists('{}.{}'.format(geo, drv)): drvn = apply(scu, 'standard', lv=lv, ihi=ihi) if 'p2p' not in drv: cmds.connectAttr('{}.{}'.format(geo, drv), '{}.{}'.format(geo, drvn)) else: level = drv.split('lv')[1] level = level.split('_')[0] env = 'p2pLv{}Envelope'.format(level) cons = cmds.listConnections('{}.{}'.format(geo, env)) for c in cons: if c.endswith('mult'): mult = c break cmds.connectAttr('{}.outputX'.format(mult), '{}.{}'.format(geo, drvn)) nn = cmds.attributeName('{}.{}'.format(geo, drvn), nice=1) cmds.addAttr('{}.{}'.format(geo, drvn), e=1, nn='(EDIT^) {}'.format(nn)) #cmds.setAttr ('{}.{}'.format (geo,drvn), k = 0) else: cmds.warning("You can only apply edit sculpts!")
def HotKey_BreakConnections(): # Break Connection of Selected Attributes v3.0.0 oChannel = [str(c+'.'+cmds.attributeName(c+'.'+b, l=True)) for a in 'msho' for b in cmds.channelBox('mainChannelBox', **{'q':True, 's%sa'%a:True}) or [] for c in cmds.channelBox('mainChannelBox', q = True, **{'%sol'%a:True})] for c in oChannel: aObj = c.split('.') cmds.delete(aObj[0], at = aObj[1], c = True)
def ATT_INCREMENT(iAmount): # Attribute Increment v4.0.0 oChannel = [str(c+'.'+cmds.attributeName(c+'.'+b, l=True)) for a in 'msho' for b in cmds.channelBox('mainChannelBox', **{'q':True, 's%sa'%a:True}) or [] for c in cmds.channelBox('mainChannelBox', q = True, **{'%sol'%a:True})] iNewValue = None if oChannel: for c in oChannel: iVal = cmds.getAttr(c) + iAmount if cmds.attributeQuery(c.split('.')[-1], node = c.split('.')[0], minExists = True): if cmds.attributeQuery(c.split('.')[-1], node = c.split('.')[0], min = True)[0] >= iVal : iNewValue = cmds.attributeQuery(c.split('.')[-1], node = c.split('.')[0], min = True)[0] if cmds.attributeQuery(c.split('.')[-1], node = c.split('.')[0], maxExists = True): if cmds.attributeQuery(c.split('.')[-1], node = c.split('.')[0], max = True)[0] <= iVal: iNewValue = cmds.attributeQuery(c.split('.')[-1], node = c.split('.')[0], max = True)[0] if not iNewValue == None: cmds.setAttr(c, iNewValue) else: cmds.setAttr(c, iVal) else: aPrint = ['d8766c', 'No Attr Selected', 0x756b6b, 'midCenterBot'] cmds.inViewMessage(amg = '<text style="color:#%s";>%s</text>'%(aPrint[0], aPrint[1]), pos = aPrint[3], fade = True, fts = 10, ft = 'arial',bkc = aPrint[2] ) DisplayFaceValues()
def _getShapeIndex(self, shape): aName = cmds.attributeName(shape.thing) aliases = cmds.aliasAttr(self.shapeNode, query=True) idx = aliases.index(aName) raw = aliases[idx + 1] matches = re.findall(r'\[\d+\]', raw) if not matches: raise IndexError("No index found for the current shape") return int(matches[-1].strip('[]'))
def refresh(s): """ Set gui to capture frame """ attr = s.state[s.state_pos]["attr"] time = s.state[s.state_pos]["time"] cmds.text(s.text, e=True, l="<h1>{} : {}</h1>".format( attr.split(".")[0], cmds.attributeName(attr, n=True))) cmds.currentTime(time)
def connectComboShape(self, combo, shape, mesh=None, live=True, delete=False): """ Connect a shape into a combo progression""" if mesh is None: attrName = cmds.attributeName(shape.thing, long=True) mesh = "{0}_Extract".format(attrName) shapeIdx = combo.prog.getShapeIndex(shape) tVal = combo.prog.pairs[shapeIdx].value delta = self._createDelta(combo, mesh, tVal) self.connectShape(shape, delta, live, delete) if delete: cmds.delete(mesh)
def bakeCharacterChannels(charSet, start=None, end=None, attrList=[]): ''' Bake character set channels. Used to bake trax animation directly to channels @param charSet: Character set to bake channels for. @type charSet: str @param start: Start frame of bake results range. If empty, use timeline start frame. @type start: int or None @param end: End frame of bake results range. If empty, use timeline end frame. @type end: int or None @param attrList: Override the list of character character set attributes to bake. If empty, use attribute list from character set. @type attrList: str ''' # ========== # - Checks - # ========== if not isCharSet(charSet): raise Exception('Object "' + charSet + '" is not a valid character set!') # Start/End if start == None: start = mc.playbackOptions(min=True) if end == None: end = mc.playbackOptions(max=True) # ========================= # - Character Set Details - # ========================= # Get Character Set Channels charChannels = mc.sets(charSet, q=True) # Get Character Set Objects charObjList = mc.ls(charChannels, o=True) # Get Character Set Channel Names if not attrList: attrList = [] for ch in charChannels: attr = mc.attributeName(ch, s=True) if not attrList.count(attr): attrList.append(attr) # ================ # - Bake Results - # ================ mc.bakeResults(charObjList, t=(1, 600), at=attrList, simulation=True) # ================= # - Return Result - # ================= return charObjList
def get_attr_data(node, attr): '''Gets data for attribute''' path = node + '.' + attr if cmds.objExists(path): children = get_child_attrs(node, attr) value = cmds.getAttr(path) if isinstance(value, list): value = value[0] return dict( name=attr, value=value, type=cmds.getAttr(path, type=True), short=cmds.attributeName(path, short=True), nice=cmds.attributeName(path, nice=True), compound=bool(children), children=children, options=get_enum_options(node, attr), keyable=cmds.attributeQuery(attr, node=node, keyable=True) )
def bakeCharacterChannels(charSet, start=None, end=None, attrList=[]): """ Bake character set channels. Used to bake trax animation directly to channels @param charSet: Character set to bake channels for. @type charSet: str @param start: Start frame of bake results range. If empty, use timeline start frame. @type start: int or None @param end: End frame of bake results range. If empty, use timeline end frame. @type end: int or None @param attrList: Override the list of character character set attributes to bake. If empty, use attribute list from character set. @type attrList: str """ # ========== # - Checks - # ========== if not isCharSet(charSet): raise Exception('Object "' + charSet + '" is not a valid character set!') # Start/End if start == None: start = cmds.playbackOptions(min=True) if end == None: end = cmds.playbackOptions(max=True) # ========================= # - Character Set Details - # ========================= # Get Character Set Channels charChannels = cmds.sets(charSet, q=True) # Get Character Set Objects charObjList = cmds.ls(charChannels, o=True) # Get Character Set Channel Names if not attrList: attrList = [] for ch in charChannels: attr = cmds.attributeName(ch, s=True) if not attrList.count(attr): attrList.append(attr) # ================ # - Bake Results - # ================ cmds.bakeResults(charObjList, t=(1, 600), at=attrList, simulation=True) # ================= # - Return Result - # ================= return charObjList
def showAttributes(self, node): """ showAttributes(str node) Set the ChannelBox to view the given node. If node is empty or None, the ChannelBox will simply be cleared. """ with noSignals(self.table): while self.table.rowCount() > 1: self.table.removeRow(1) if not node or not cmds.objExists(node): self._setTableVisible(False) return self._setTableVisible(True) # update the node name self._currentNode = node name = node.split('|')[-1] self.table.item(0, 0).setText(name) # update the attributes attrs = cmds.listAttr(node, r=True, w=True, v=True, k=True) self.table.setRowCount(len(attrs) + 1) for row, name in enumerate(attrs): row += 1 self.table.setRowHeight(row, 20) attr = '%s.%s' % (node, name) niceName = cmds.attributeName(attr) item = QtGui.QTableWidgetItem(niceName) item.attrName = attr item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable) item.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.table.setItem(row, 0, item) val = cmds.getAttr(attr) item = AttrItem() item.setTextAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) item.setBackgroundColor(QtGui.QColor(40, 40, 40)) item.attrName = attr item.attrVal = val item.setAttrValue(val) self.table.setItem(row, 1, item)
def showAttributes(self, node): """ showAttributes(str node) Set the ChannelBox to view the given node. If node is empty or None, the ChannelBox will simply be cleared. """ with noSignals(self.table): while self.table.rowCount() > 1: self.table.removeRow(1) if not node or not cmds.objExists(node): self._setTableVisible(False) return self._setTableVisible(True) # update the node name self._currentNode = node name = node.split("|")[-1] self.table.item(0, 0).setText(name) # update the attributes attrs = cmds.listAttr(node, r=True, w=True, v=True, k=True) self.table.setRowCount(len(attrs) + 1) for row, name in enumerate(attrs): row += 1 self.table.setRowHeight(row, 20) attr = "%s.%s" % (node, name) niceName = cmds.attributeName(attr) item = QtGui.QTableWidgetItem(niceName) item.attrName = attr item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable) item.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.table.setItem(row, 0, item) val = cmds.getAttr(attr) item = AttrItem() item.setTextAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) item.setBackgroundColor(QtGui.QColor(40, 40, 40)) item.attrName = attr item.attrVal = val item.setAttrValue(val) self.table.setItem(row, 1, item)
def gatherInfo(self): if (self.attr in self._standardAttrs ): # Attribute is apart of the main translates. # if there is a attrTemp = cmds.attributeName(self.fullObj, short=True) if (attrTemp == 'v'): self.defValue = cmds.attributeQuery('v', node=self.obj, ld=True)[0] self.min = cmds.attributeQuery('v', node=self.obj, min=True)[0] self.max = cmds.attributeQuery('v', node=self.obj, max=True)[0] self.dataType = "long" else: enabledLimits = eval( "cmds.transformLimits( self.obj, q=True, e%s=True)" % attrTemp) if (enabledLimits[0]): self.min = eval( "cmds.transformLimits( self.obj, q=True, %s=True)" % attrTemp)[0] if (enabledLimits[1]): self.max = eval( "cmds.transformLimits( self.obj, q=True, %s=True)" % attrTemp)[1] if ("s" in self.attr): # Then we are at scale self.defValue = 1 else: self.defValue = 0 self.dataType = "double" # current value will be the offset # What about a enum values? else: # Custom attributes if (cmds.attributeQuery(self.attr, node=self.obj, minExists=True)): self.min = cmds.attributeQuery(self.attr, node=self.obj, min=True)[0] if (cmds.attributeQuery(self.attr, node=self.obj, maxExists=True)): self.max = cmds.attributeQuery(self.attr, node=self.obj, max=True)[0] self.defValue = cmds.attributeQuery(self.attr, node=self.obj, listDefault=True)[0] self.dataType = cmds.addAttr(self.fullObj, q=True, at=True) self.offset = cmds.getAttr(self.fullObj)
def appendItem(self, nodename, attrname, value): nodeItem = QtGui.QStandardItem(nodename) nodeItem.setEditable(False) try: attrname = cmds.attributeName('%s.%s' % (nodename, attrname), l=True) except: pass attrItem = QtGui.QStandardItem(attrname) attrItem.setEditable(False) valueItem = QtGui.QStandardItem(str(value)) valueItem.setEditable(False) valueItem.setData(value) self.appendRow([nodeItem, attrItem, valueItem])
def attributeMenuItem(node, attr): plug = node+'.'+attr niceName = mc.attributeName(plug, nice=True) #get attribute type attrType = mc.getAttr(plug, type=True) if attrType == 'enum': listEnum = mc.attributeQuery(attr, node=node, listEnum=True)[0] if not ':' in listEnum: return listEnum = listEnum.split(':') mc.menuItem(label=niceName, subMenu=True) for value, label in enumerate(listEnum): mc.menuItem(label=label, command=partial(mc.setAttr, plug, value)) mc.setParent('..', menu=True) elif attrType == 'bool': value = mc.getAttr(plug) label = 'Toggle '+ niceName mc.menuItem(label=label, command=partial(mc.setAttr, plug, not value))
def format_and_set(self, plug): value = cmds.getAttr(plug) niceName = cmds.attributeName(plug) if isinstance(value, list): channels = ['X', 'Y', 'Z'] tup = value[0] for idx, val in enumerate(tup): checkingAtt = "%s %s" % (niceName, channels[idx]) try: _, val_ch = self.matchItems(checkingAtt) except: return try: if val_ch is not None: with noSignals(self.CB_table): val_ch.setAttrValue(val) except: return elif isinstance(value, float): toMatch = niceName try: _, val_ch = self.matchItems(toMatch) except: return try: if val_ch is None: return else: with noSignals(self.CB_table): val_ch.setAttrValue(value) except: return
def populateChannels(self, node): # will populate the channel box with the channels # but first will remove any callback previous .... self.removeCallback(self._node_callbackID) with noSignals(self.CB_table): self.callbackNodeWrapper(self.checkShapes(node)) for itm in range(self.CB_table.rowCount()): self.CB_table.removeRow(itm) if not node or not cmds.objExists(node): return attr = self.getAllattributesData(node, niceName=False) self.CB_table.setRowCount(len(attr)) for row, name in enumerate(attr): self.CB_table.setRowHeight(row, 20) attr = "{}.{}".format(node, name) niceName = cmds.attributeName(attr) item = qg.QTableWidgetItem(niceName) item.setFont(self.QFont) item.setFlags(item.flags() ^ qc.Qt.ItemIsEditable) item.setTextAlignment(qc.Qt.AlignRight | qc.Qt.AlignVCenter) self.CB_table.setItem(row, 0, item) val = cmds.getAttr(attr) item = CustomTableItem() item.setTextAlignment(qc.Qt.AlignLeft | qc.Qt.AlignVCenter) if self.lookforKeys(attr): item.setBackground(qg.QColor(220, 1, 1, 100)) else: item.setBackground(qg.QColor(1, 1, 1, 100)) item.attrName = attr item.attrVal = val item.setAttrValue(val) self.CB_table.setItem(row, 1, item)
def eval(self, expression_string, container=None, **kwargs): long_kwargs = {} for var, value in kwargs.items(): if isinstance(value, string_types): tokens = value.split(".") if len(tokens) == 1: # Assume a single node name is the world matrix value = "{}.worldMatrix[0]".format(tokens[0]) else: # Turn all attribute names into long names for consistency with # results in listConnections value = tokens[0] for t in tokens[1:]: attr = "{}.{}".format(value, t) value += ".{}".format( cmds.attributeName(attr, long=True)) long_kwargs[var] = value self.kwargs = long_kwargs # Reverse variable look up to write cleaner notes self._reverse_kwargs = {} for k, v in self.kwargs.items(): self._reverse_kwargs[v] = k self.expression_string = expression_string self.expr_stack = [] self.assignment_stack = [] self.results = self.bnf.parseString(expression_string, True) self.container = (cmds.container(name=container, current=True) if container else None) self.created_nodes = {} stack = self.expr_stack[:] + self.assignment_stack[:] result = self.evaluate_stack(stack) if self.container: self.publish_container_attributes() return result
def gatherInfo(self): if( self.attr in self._standardAttrs ): # Attribute is apart of the main translates. # if there is a attrTemp = cmds.attributeName( self.fullObj, short=True) if( attrTemp == 'v'): self.defValue = cmds.attributeQuery( 'v', node=self.obj, ld=True)[0] self.min = cmds.attributeQuery( 'v', node=self.obj, min=True)[0] self.max = cmds.attributeQuery( 'v', node=self.obj, max=True)[0] self.dataType = "long" else: enabledLimits = eval( "cmds.transformLimits( self.obj, q=True, e%s=True)" %attrTemp) if( enabledLimits[0] ): self.min = eval( "cmds.transformLimits( self.obj, q=True, %s=True)" %attrTemp)[0] if( enabledLimits[1] ): self.max = eval( "cmds.transformLimits( self.obj, q=True, %s=True)" %attrTemp)[1] if( "s" in self.attr ): # Then we are at scale self.defValue = 1 else: self.defValue = 0 self.dataType = "double" # current value will be the offset # What about a enum values? else: # Custom attributes if( cmds.attributeQuery( self.attr, node=self.obj, minExists=True) ): self.min = cmds.attributeQuery( self.attr, node=self.obj, min=True)[0] if( cmds.attributeQuery( self.attr, node=self.obj, maxExists=True) ): self.max = cmds.attributeQuery( self.attr, node=self.obj, max=True)[0] self.defValue = cmds.attributeQuery( self.attr, node=self.obj, listDefault=True)[0] self.dataType = cmds.addAttr( self.fullObj, q=True, at=True) self.offset = cmds.getAttr( self.fullObj )
def homogonizeName(fullPath): '''Takes in any full attribute path and returns the relative object path with full attribute names''' # Split attributes attrs = fullPath.split('.') # Get relative path to object while removing obj from attrs obj = cmd.ls(attrs.pop(0), o=1)[0] # Get full name of each attribute and add it back to obj. for attr in attrs: fullAttr = '%s.%s' % (obj, attr) longName = cmd.attributeName(fullAttr, l=1) if ' ' in longName: # Maya has seen fit to sometimes give nice names instead of # long names. Here, we'll hope to god that the nice name # correlates exactly with the long name. and camel case it. # Yaaaay Autodesk. longName = [name.capitalize() for name in longName.split()] longName[0] = longName[0].lower() longName = ''.join(longName) obj = '%s.%s' % (obj, longName) return obj
def get_nice_name(self): return cmds.attributeName(self.get_name())
def get_long_name(self): return cmds.attributeName(self.get_name(), long=True)
def DisplayFaceValues(): iStop = 0 iNegative = False oChannel = [str(c+'.'+cmds.attributeName(c+'.'+b, l=True)) for a in 'msho' for b in cmds.channelBox('mainChannelBox', **{'q':True, 's%sa'%a:True}) or [] for c in cmds.channelBox('mainChannelBox', q = True, **{'%sol'%a:True})] oSel = [str(o) for o in cmds.ls(sl = True, o = True)] if len(oSel) == 1: if 0 < len(oChannel) <= 2: for c in oChannel: if cmds.attributeQuery(c.split('.')[-1], node = oSel[0], minExists = True): if cmds.attributeQuery(c.split('.')[-1], node = oSel[0], min = True)[0] == -1.0: iNegative = True else: iStop = 2 if cmds.attributeQuery(c.split('.')[-1], node = oSel[0], maxExists = True): if not cmds.attributeQuery(c.split('.')[-1], node = oSel[0], max = True)[0] == 1.0: iStop = 3 else: iStop = 5 if len(oChannel) == 2: if not oChannel[1].split('.')[-1] == oChannel[0].split('.')[-1][:-1]+'R': iStop = 6 else: iStop = 7 else: iStop = 8 if iStop: #print iStop pass else: # Initial Bar Colours aBar = [] aColour = [] for i in range(201): aBar.append('-') aColour.append('#85929E') for i in range(0, 201, 10): aBar[i] = ':' aColour[i] = '#AEB6BF' for i in range(0, 201, 50): aBar[i] = '|' aColour[i] = '#D6DBDF' for i in range(0, 100): aColour[i] = '#808B96' # Logic to split markings for i, c in enumerate(oChannel): iVal = int(cmds.getAttr(c)*100.0)+100 aColour[iVal] = '#D4AC0D' if len(oChannel) == 1: if c[-1] == 'L': aBar[iVal] = ')' elif c[-1] == 'R': aBar[iVal] = '(' else: aBar[iVal] = '|' #aColour[iVal] = '#FEF9E7' else: if i == 0: aBar[iVal] = ')' else: if aBar[iVal] == ')': aBar[iVal] = 'O' else: aBar[iVal] = '(' aText = [] for i, v in enumerate(aBar[:]): aText.append('<text style="color:%s";>%s</text>'%(aColour[i], v ) ) if not iNegative: aText = aText[100:] sText = ''.join(aText) cmds.inViewMessage(amg = sText, pos = 'botCenter', fade = False, fts = 7, ft = 'arial',bkc = 0x5D6D7E, dragKill = 1)
def print_attrs_for_single_node(node, **kwargs): '''Print name, type, and value of attributes of Maya node. Args: node (str): Node. attr_filter (str): Attribute filter. Only shows attributes that contain this filter. val_filter (str, int, float, etc): Value filter. Only shows values equal to this filter. Raises: ValueError: No object matches name. ''' if cmds.objExists(node): print '{}:'.format(node) else: print '{}: Does not exist'.format(node) return attrs = list_attrs(node) # Get filters. attr_filter = kwargs.get('attr_filter', None) has_val_filter = 'val_filter' in kwargs val_filter = kwargs.get('val_filter', None) # Loop attributes. count = 0 for attr in attrs: # Skip attributes with period. (ie. type TdataCompound) if '.' in attr: continue # Filter by attr. if attr_filter and attr_filter.lower() not in attr.lower(): continue plug = '{}.{}'.format(node, attr) # Get type. try: typ = cmds.getAttr(plug, type=True) except Exception, err: typ = str(err), # Get and print value. try: val = cmds.getAttr(plug) except Exception: # Error getting attribute. Probably a connection attribute. # Skip if filter speciifed. if attr_filter or has_val_filter: continue connections = cmds.listConnections(plug, plugs=True) if connections: print '{} connected to ({}): {}'.format( attr, len(connections), ', '.join(connections)) else: print '{} not connected to anything'.format(attr) else: # If enum, get it as string too. if typ == 'enum': val = '{} [{}]'.format(cmds.getAttr(plug, asString=True), val) # Filter by value, if specified. if has_val_filter: # Skip if not same type. if type(val_filter) != type(val): continue # If string, match with "in" operator. if isinstance(val_filter, str): if val_filter.lower() not in val.lower(): continue elif val_filter != val: # Match by same type and value. continue # Add single quote around string. if typ == 'string': if val is not None: val = "'{}'".format(val) locked = cmds.getAttr(plug, lock=True) # Print value. full_name = cmds.attributeName(plug) print '{} ({}) "{}" {}: {}'.format(attr, typ, full_name, ' [locked]' if locked else '', val) count += 1
## if usage. x = 1 if z else 2 ## enumerate for iIndex, x in enumerate(oSel[:]): # [:] makes it run a copy of oSel so you can modify oSel in the loop. print iIndex print x oSel.remove(x) # Print all attributes selected. (Regardless of shape, transform node..) print [str(c+'.'+cmds.attributeName(c+'.'+b, l=True)) for a in 'msho' for b in cmds.channelBox('mainChannelBox', **{'q':True, 's%sa'%a:True}) or [] for c in cmds.channelBox('mainChannelBox', q = True, **{'%sol'%a:True}) or [] if cmds.attributeQuery(b, n=c, ex=True)] # runs until reaches "" iter(f.readline, ""): # For loop variations. for true { true = False "or" break }
def getAttributeName(self, sNodeWithAttribute): return mc.attributeName(sNodeWithAttribute)
def getCurves( self, maya_nodes_curves=[], maya_attribute_curves=[], silent=False, start_frame=None, end_frame=None, left_eye_curves=[], right_eye_curves=[], ): """ This function will get animation curve from maya nodes and all anim curve data will be processed and it will generate a curve class.In silent mode, unsupported curve types will be replaced with a default curve type of user. :param maya_nodes: list of maya objects :type maya_nodes: list :param silent: If this option is true then we will ignore all tangent errors. :type silent: bool :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param left_eye_curves: Left eye objects :type left_eye_curves: list :param right_eye_curves: Right eye objects :type right_eye_curves: list :return: Curve class object :rtype: curve Example >>> curve_obj = getCurves(maya_nodes = ["pSphere1","pSphere2"],start_frame = 10,end_frame = 100,silent = False,left_eye_curves=["pSphere1"],right_eye_curves=["pSphere2"]) """ temp_maya_nodes_curves = maya_nodes_curves curves_from_maya_node = [] if not temp_maya_nodes_curves: raise KipBaseError("Exporter need object list to export data !" " Nothing found to Export!") build_node_list = [] build_node_attr_list = [] build_dest_node_list = [] build_accepted_attributes = [] if type(temp_maya_nodes_curves) == dict: for each_nd in temp_maya_nodes_curves.keys(): node_name_tr, node_attr_tr = temp_maya_nodes_curves[each_nd].split(".") build_accepted_attributes.append(temp_maya_nodes_curves[each_nd].split(".")[1]) dest_node_name_tr = each_nd.split(".")[0] build_node_list.append(node_name_tr) build_node_attr_list.append(node_attr_tr) build_dest_node_list.append({node_name_tr: dest_node_name_tr}) elif type(temp_maya_nodes_curves) == list: build_node_list = temp_maya_nodes_curves else: raise KipBaseError("Unknown mapping structure found ! list and dict only supported!") # current_prser_index = 0 for each_node in build_node_list: kipCurveClassObject = ClassObject() kipCurveObject = CurveClass() current_prser_index = build_node_list.index(each_node) attribute_val = build_node_attr_list[current_prser_index] a_curves = cmds.keyframe(each_node, name=True, query=True) if start_frame and end_frame: if isinstance(start_frame, int) and isinstance(end_frame, int): a_curves = cmds.keyframe(each_node, name=True, time=(int(start_frame), int(end_frame)), query=True) else: message = ( "%s or %s is not a int value , non int values are not support" " for exporting time frame" % (start_frame, end_frame) ) raise KipBaseError(message) try: if not a_curves: continue for each_curve in a_curves: count_split = "%s.%s" % (each_node, attribute_val) current_node_prs_name = each_node try: node_attr_type = cmds.attributeName(count_split, n=True).split(" ")[0] current_attr_name = cmds.attributeName(count_split, l=True) except: continue if maya_attribute_curves: for each_pass_attr in maya_attribute_curves: if current_attr_name.find(each_pass_attr) == -1: continue if not current_attr_name in build_accepted_attributes: continue value = cmds.keyframe(each_curve, absolute=True, query=True, valueChange=True) time = cmds.keyframe(each_curve, absolute=True, query=True, timeChange=True) in_angle = cmds.keyTangent(each_curve, query=True, ia=True) out_angle = cmds.keyTangent(each_curve, query=True, oa=True) in_weight = cmds.keyTangent(each_curve, query=True, iw=True) out_weight = cmds.keyTangent(each_curve, query=True, ow=True) in_tan_type = cmds.keyTangent(each_curve, query=True, itt=True) out_tan_type = cmds.keyTangent(each_curve, query=True, ott=True) i = 0 key = CurveKeyClass() for t in time: key.time.append(time[i]) key.value.append(value[i]) key.in_angle.append(in_angle[i]) key.out_angle.append(out_angle[i]) key.in_weight.append(in_weight[i]) key.out_weight.append(out_weight[i]) in_tan_type_prs = str(in_tan_type[i]) if not in_tan_type_prs in self.supported_tan_types: if silent: in_tan_type_prs = "user" else: raise KipTangentError( "%s not supported tangent to nuke, Please " "update anim curve with any one of this %s" % (in_tan_type_prs, self.supported_tan_types) ) key.in_tan_type.append(in_tan_type_prs) out_tan_type_prs = str(out_tan_type[i]) if not out_tan_type_prs in self.supported_tan_types: if silent: out_tan_type_prs = "user" else: raise KipTangentError( "%s not supported tangent to nuke, Please " "update anim curve with any one of this %s" % (out_tan_type_prs, self.supported_tan_types) ) key.out_tan_type.append(out_tan_type_prs) rad_in_angle = math.radians(in_angle[i]) rad_out_angle = math.radians(out_angle[i]) key.in_slope.append(math.tan(rad_in_angle)) key.out_slope.append(math.tan(rad_out_angle)) i += 1 maya_prs_original_attr = None if type(temp_maya_nodes_curves) == dict: current_node_from_attr = cmds.connectionInfo( "%s.output" % each_curve, destinationFromSource=True ) source_node_attr = current_node_from_attr[0] attribute_value_here = source_node_attr.split(".")[-1] if source_node_attr in temp_maya_nodes_curves.values(): for current_key, current_value in temp_maya_nodes_curves.items(): if current_value == source_node_attr: splitter_attribute = current_value.split(".")[1] if attribute_value_here.find(splitter_attribute) != -1: split_current_key = current_key.split(".") maya_prs_node = split_current_key[0] maya_prs_original_attr = split_current_key[1] maya_prs_strip_attr = maya_prs_original_attr[0:-1] del (temp_maya_nodes_curves[current_key]) break else: continue else: maya_prs_node = current_node_prs_name maya_prs_strip_attr = node_attr_type.lower() maya_prs_original_attr = current_attr_name if not maya_prs_original_attr: continue kipCurveObject.keys.append(key) kipCurveObject.name.append(maya_prs_node) kipCurveObject.parm.append(maya_prs_strip_attr) kipCurveObject.parm_attr.append(maya_prs_original_attr) each_curve_it = None if curves_from_maya_node: for each_curve_it in curves_from_maya_node: if maya_prs_node in each_curve_it: break else: each_curve_it = None if each_curve_it: get_append_curve_v = kipCurveObject.output() for each_append_cruve in get_append_curve_v: each_curve_it[2].append(each_append_cruve) else: kipCurveClassObject.name = maya_prs_node eye_type = "default" if each_node in left_eye_curves: eye_type = "left" elif each_node in right_eye_curves: eye_type = "right" kipCurveClassObject.type = eye_type kipCurveClassObject.animation.append(kipCurveObject) curves_from_maya_node.append(kipCurveClassObject.output()) current_prser_index += 1 except Exception: current_prser_index += 1 continue rodin_logger.info("Finished maya exporting data") return curves_from_maya_node
def channelbox_command_isolateAttr(box, menuItem, key, *args): with sysCmd.Undo(0): state = cmds.menuItem(menuItem, q=1, isOptionBox=1) if state: # clicked menuItem rather than option box if cmds.window("selectAttrWin", exists=1): cmds.deleteUI("selectAttrWin") window = cmds.window("selectAttrWin", title="Select Attributes", mxb=1, mnb=1, s=1) layout = cmds.formLayout(p=window) def state(_key): # restore checkbox values if _key in box.filter_attrs and box.filter_attrs[_key] == 1: return 1 else: return 0 def cb_cmd(_key, cb, *args): # checkbox command, sets value for each _key, calls resetfilters to clear previous, then updates box.filter_attrs[_key] = cmds.checkBox(cb, q=1, v=1) channelbox_command_resetFilters(box) channelBox_filterAttrs(box) # primary interface clayout = cmds.columnLayout(p=layout) r1 = cmds.rowLayout(nc=4, cw4=(70, 30, 30, 30), p=clayout) cmds.text(l="", p=r1) cmds.text(l="X", p=r1) cmds.text(l="Y", p=r1) cmds.text(l="Z", p=r1) r2 = cmds.rowLayout(nc=4, cw4=(70, 30, 30, 30), p=clayout) cmds.text(l="Translate", p=r2) _tx = cmds.checkBox(l="", v=state("translateX"), p=r2) _ty = cmds.checkBox(l="", v=state("translateY"), p=r2) _tz = cmds.checkBox(l="", v=state("translateZ"), p=r2) cmds.checkBox(_tx, e=1, cc=partial(cb_cmd, "translateX", _tx)) cmds.checkBox(_ty, e=1, cc=partial(cb_cmd, "translateY", _ty)) cmds.checkBox(_tz, e=1, cc=partial(cb_cmd, "translateZ", _tz)) r3 = cmds.rowLayout(nc=4, cw4=(70, 30, 30, 30), p=clayout) cmds.text(l="Rotate", p=r3) _rx = cmds.checkBox(l="", v=state("rotateX"), p=r3) _ry = cmds.checkBox(l="", v=state("rotateY"), p=r3) _rz = cmds.checkBox(l="", v=state("rotateZ"), p=r3) cmds.checkBox(_rx, e=1, cc=partial(cb_cmd, "rotateX", _rx)) cmds.checkBox(_ry, e=1, cc=partial(cb_cmd, "rotateY", _ry)) cmds.checkBox(_rz, e=1, cc=partial(cb_cmd, "rotateZ", _rz)) r4 = cmds.rowLayout(nc=4, cw4=(70, 30, 30, 30), p=clayout) cmds.text(l="Scale", p=r4) _sx = cmds.checkBox(l="", v=state("scaleX"), p=r4) _sy = cmds.checkBox(l="", v=state("scaleY"), p=r4) _sz = cmds.checkBox(l="", v=state("scaleZ"), p=r4) cmds.checkBox(_sx, e=1, cc=partial(cb_cmd, "scaleX", _sx)) cmds.checkBox(_sy, e=1, cc=partial(cb_cmd, "scaleY", _sy)) cmds.checkBox(_sz, e=1, cc=partial(cb_cmd, "scaleZ", _sz)) # other attributes slayout = cmds.scrollLayout(childResizable=1, p=clayout) # extra attribs placed in scroll layout skip = ["translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ", "scaleX", "scaleY", "scaleZ"] objects = cmds.channelBox(box.channelbox, q=1, mainObjectList=1) if objects: for obj in objects: attrs = [] attrs_cb = cmds.listAttr(obj, cb=1) attrs_k = cmds.listAttr(obj, k=1, v=1) # list all obj attribs to loop over if attrs_cb and len(attrs_cb) >= 1: attrs += attrs_cb if attrs_k and len(attrs_k) >= 1: attrs += attrs_k for attr in attrs: if attr not in skip: name = obj + "." + attr leafs = cmds.listAttr(name, leaf=1) attr = leafs[0] nice_name = cmds.attributeQuery(attr, niceName=1, node=obj) if nice_name: _cb = cmds.checkBox(l=nice_name, v=state(attr), p=slayout) cmds.checkBox(_cb, e=1, cc=partial(cb_cmd, attr, _cb)) cmds.showWindow() else: # option box box.filter_attrs = {} plugs = channelBox_SelectedPlugs(box) # which attributes are selected in channel box if not plugs: cmds.warning("No attributes selected") return for plug in plugs: name = cmds.attributeName(plug, long=1) # we are given shortened attributes, this grabs the long name box.filter_attrs[name] = 1 channelbox_command_resetFilters(box) channelBox_filterAttrs(box)
def getCurves(self, maya_nodes_curves = [], maya_attribute_curves = [], silent = False, start_frame = None, end_frame = None, left_eye_curves = [], right_eye_curves = []): """ This function will get animation curve from maya nodes and all anim curve data will be processed and it will generate a curve class.In silent mode, unsupported curve types will be replaced with a default curve type of user. :param maya_nodes: list of maya objects :type maya_nodes: list :param silent: If this option is true then we will ignore all tangent errors. :type silent: bool :param start_frame: start frame to capture :type start_frame: int :param end_frame: end frame to capture :type end_frame: int :param left_eye_curves: Left eye objects :type left_eye_curves: list :param right_eye_curves: Right eye objects :type right_eye_curves: list :return: Curve class object :rtype: curve Example >>> curve_obj = getCurves(maya_nodes = ["pSphere1","pSphere2"],start_frame = 10,end_frame = 100,silent = False,left_eye_curves=["pSphere1"],right_eye_curves=["pSphere2"]) """ temp_maya_nodes_curves = maya_nodes_curves curves_from_maya_node = [] if not temp_maya_nodes_curves: raise KipBaseError("Exporter need object list to export data !"\ " Nothing found to Export!") build_node_list = [] build_node_attr_list = [] build_dest_node_list = [] build_accepted_attributes = [] if type(temp_maya_nodes_curves) == dict: for each_nd in temp_maya_nodes_curves.keys(): node_name_tr, node_attr_tr = temp_maya_nodes_curves[each_nd].split(".") build_accepted_attributes.append(temp_maya_nodes_curves[each_nd].split(".")[1]) dest_node_name_tr = each_nd.split(".")[0] build_node_list.append(node_name_tr) build_node_attr_list.append(node_attr_tr) build_dest_node_list.append({node_name_tr:dest_node_name_tr}) elif type(temp_maya_nodes_curves) == list: build_node_list = temp_maya_nodes_curves else: raise KipBaseError("Unknown mapping structure found ! list and dict only supported!") # current_prser_index = 0 for each_node in build_node_list: kipCurveClassObject = ClassObject() kipCurveObject = CurveClass() current_prser_index = build_node_list.index(each_node) attribute_val = build_node_attr_list[current_prser_index] a_curves = cmds.keyframe(each_node, name = True, query = True) if start_frame and end_frame: if isinstance(start_frame, int ) and isinstance(end_frame, int ): a_curves = cmds.keyframe(each_node, name = True, \ time = (int(start_frame), int(end_frame)), query= True) else: message = ("%s or %s is not a int value , non int values are not support"\ " for exporting time frame"%(start_frame,end_frame)) raise KipBaseError(message) try: if not a_curves: continue for each_curve in a_curves: count_split = "%s.%s" % (each_node, attribute_val) current_node_prs_name = each_node try: node_attr_type = cmds.attributeName(count_split, n=True).split(" ")[0] current_attr_name = cmds.attributeName(count_split, l=True) except: continue if maya_attribute_curves: for each_pass_attr in maya_attribute_curves: if current_attr_name.find(each_pass_attr) == -1: continue if not current_attr_name in build_accepted_attributes: continue value = cmds.keyframe(each_curve, absolute = True, query = True, \ valueChange = True) time = cmds.keyframe(each_curve, absolute=True, query=True, timeChange=True) in_angle = cmds.keyTangent(each_curve, query=True, ia=True) out_angle = cmds.keyTangent(each_curve, query=True, oa=True) in_weight = cmds.keyTangent(each_curve, query=True, iw=True) out_weight = cmds.keyTangent(each_curve, query=True, ow=True) in_tan_type = cmds.keyTangent(each_curve, query=True, itt=True) out_tan_type = cmds.keyTangent(each_curve, query=True, ott=True) i = 0 key = CurveKeyClass() for t in time: key.time.append(time[i]) key.value.append(value[i]) key.in_angle.append(in_angle[i]) key.out_angle.append(out_angle[i]) key.in_weight.append(in_weight[i]) key.out_weight.append(out_weight[i]) in_tan_type_prs = str(in_tan_type[i]) if not in_tan_type_prs in self.supported_tan_types: if silent: in_tan_type_prs = "user" else: raise KipTangentError("%s not supported tangent to nuke, Please "\ "update anim curve with any one of this %s" % \ (in_tan_type_prs, self.supported_tan_types)) key.in_tan_type.append(in_tan_type_prs) out_tan_type_prs = str(out_tan_type[i]) if not out_tan_type_prs in self.supported_tan_types: if silent: out_tan_type_prs = "user" else: raise KipTangentError("%s not supported tangent to nuke, Please "\ "update anim curve with any one of this %s"%(out_tan_type_prs, \ self.supported_tan_types)) key.out_tan_type.append(out_tan_type_prs) rad_in_angle = math.radians(in_angle[i]) rad_out_angle = math.radians(out_angle[i]) key.in_slope.append(math.tan(rad_in_angle)) key.out_slope.append(math.tan(rad_out_angle)) i += 1 maya_prs_original_attr = None if type(temp_maya_nodes_curves) == dict: current_node_from_attr = cmds.connectionInfo("%s.output" % each_curve, \ destinationFromSource=True) source_node_attr = current_node_from_attr[0] attribute_value_here = source_node_attr.split(".")[-1] if source_node_attr in temp_maya_nodes_curves.values(): for current_key, current_value in temp_maya_nodes_curves.items(): if current_value == source_node_attr: splitter_attribute = current_value.split(".")[1] if attribute_value_here.find(splitter_attribute) !=-1: split_current_key = current_key.split(".") maya_prs_node = split_current_key[0] maya_prs_original_attr = split_current_key[1] maya_prs_strip_attr = maya_prs_original_attr[0:-1] del (temp_maya_nodes_curves[current_key]) break else: continue else: maya_prs_node = current_node_prs_name maya_prs_strip_attr = node_attr_type.lower() maya_prs_original_attr = current_attr_name if not maya_prs_original_attr: continue kipCurveObject.keys.append(key) kipCurveObject.name.append(maya_prs_node) kipCurveObject.parm.append(maya_prs_strip_attr) kipCurveObject.parm_attr.append(maya_prs_original_attr) each_curve_it = None if curves_from_maya_node: for each_curve_it in curves_from_maya_node: if maya_prs_node in each_curve_it: break else: each_curve_it = None if each_curve_it: get_append_curve_v = kipCurveObject.output() for each_append_cruve in get_append_curve_v: each_curve_it[2].append(each_append_cruve) else: kipCurveClassObject.name = maya_prs_node eye_type = "default" if each_node in left_eye_curves: eye_type = "left" elif each_node in right_eye_curves: eye_type = "right" kipCurveClassObject.type = eye_type kipCurveClassObject.animation.append(kipCurveObject) curves_from_maya_node.append(kipCurveClassObject.output()) current_prser_index += 1 except Exception: current_prser_index += 1 continue rodin_logger.info("Finished maya exporting data") return (curves_from_maya_node)