#Attribute Dictionarizer #Developed by Matthew Oztalay (Rogue00 on Highend3d) #v1.0 # #Allows user to assign the class "objectAttr" to a variable #This class has 3 methods, create, change value, and show value #When you change a value using objectAttr.chVal() you must pass an argument in the form (Attribute Name,New Attribute Value) #imports Maya and MEL modules import maya.cmds as mc import maya.mel as mel #defines the class class objectAttr: #global attributes global attrDict attrDict = {} global attrNames attrNames = [] global attrValues attrValues = [] #establishes the selected command, which is a list, then pulls the first item in the list of selected items into a string global selected selected = mc.ls(sl = 1) global sel sel = selected[0] #populates the dictionary attrDict with attributes def create(self): #defines attrNames as the maya command "listAttr" #passing flags to only list visible, readable, writable, and keyable attributes attrNames = mc.listAttr(v=1,r=1,w=1,k=1) #Uses a temporary string to pass a flag to Maya to query the value of an attribute for x in attrNames: tempString = (sel + "." + x) attrValues.append(mc.getAttr(tempString)) z = 0 #Using a while loop whose duration is equal to the number of attributes, #populates the dictionary with the format attribute name:attribute value while z < (len(attrNames)): attrDict[attrNames[z]] = attrValues[z] z += 1 return attrDict #method for changing the value both in the dictionary and the value in Maya def chVal(self,attrName,attrValue): #creates a temporary string in the form Maya expects for the setAttr arguement tempString = (sel + "." + attrName) #changes the value in Maya mc.setAttr(tempString,attrValue) #recreates the dictionary, and returns the new dictionary to the user self.create() self.shVal() def shVal(self): print attrDict