To do matching like this at a more basic level usually people do some sort of token within the name of each object that represents the object type. For example:
target_locator target_shader target2_locator target2_shader something like that. This way you can do really quick string replacements to try to query the relationship of the names of two objects. Otherwise you'd probably need to query some sort of relationship between the two, use sets or a myriad of ways of defining relationships between objects in Maya. You're also running into the issue of matching the shape node because you can't actually name two nodes the exact same string. So for example (if you now name your nodes in some way like above) you could refactor your code to something like this: https://gist.github.com/AndresMWeber/788e203f4500039a12bf38dfc086b904 On Monday, October 9, 2017 at 1:43:35 PM UTC-4, Jeremy Beauchamp wrote: > > I'm still fairly new to Maya and python, so i have a few questions. > > I have two lists: > 1. Materials > 2. Locators > I want to compare each list and if the locator has the same name as the > material then: > getAttr transforms from the locator and setAttr color to the material. > > > If I define the name of the material and locator as 'someMaterial', it > works. > How do I make it so I don't have to define the names of the material or > locator as that can be completely random? > Also, the locators will always have the same name as the material by > default, unless there is a better way to compare? > > ------------------------------------------- > > locator = cmds.ls(type='locator') > someMaterialLoc=[] > for x in locator: > if x == 'someMaterialShape1': > someMaterialLoc.append(x) > print someMaterialLoc > > allShaders = cmds.ls(type='VRayMtl') > someMaterial =[] > for x in allShaders: > if x =='someMaterial': > someMaterial.append(x) > print someMaterial > > if str(someMaterial[0]) == someMaterialLoc[0][0:12]: > red = cmds.getAttr(someMaterialLoc[0], '.translateX') > green = cmds.getAttr(someMaterialLoc[0], '.translateY') > blue = cmds.getAttr(someMaterialLoc[0], '.translateZ') > cmds.setAttr ((someMaterial[0] + '.color'), red, green, blue, type = > 'double3' ) > > ------------------------------------------- > > Any recommendations would be greatly appreciated. > Thanks, > Jeremy > > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/78fc598d-638c-4bea-a8f2-21b250a96e57%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
