thanks, that works perfectly. I dont quite understand all aspects of the function but I'm sure I will in a month or two.
Interesting stuff, thanks again. On Wednesday, January 7, 2015 7:05:25 PM UTC-5, Chris Gardner wrote: > > oh, sorry, you might need to replace the "cmds' in my function with "mc" - > i use > import maya.cmds as cmds > > where you obviously import it as "mc" > > cheers, > chrisg > > > On 8 January 2015 at 11:00, Chris Gardner <[email protected] > <javascript:>> wrote: > >> hey will, >> >> here's a function to get the shape of a node (it looks complicated >> because it's been severely battle tested over the years) >> >> def getShape(node): >> """ >> Finds the shape node from a transform >> >> @param node: Object >> @type node: String >> >> @return: Shape node >> """ >> if 'transform' in cmds.nodeType(node, inherited=True): >> if cmds.listRelatives(node, shapes=True): >> shapes = [x for x in cmds.listRelatives(node, shapes=True, >> fullPath=True) >> if cmds.getAttr(x + '.intermediateObject') is False] >> if not shapes: >> return None >> return shapes[0] >> else: >> return None >> elif 'shape' in cmds.nodeType(node, inherited=True): >> return node >> >> >> so then you could >> >> def redWireColour(): >> selection = mc.ls( selection=True ) >> for i in selection: >> selShape = getShape(i) >> mc.setAttr( selShape + '.overrideEnabled', 1 ) >> mc.setAttr( selShape + '.overrideColor', 4 ) >> >> >> btw, in python you don't need to loop over the selection by an index - >> you can just loop directly. saves some legwork. >> >> cheers, >> chrisg >> >> >> On 8 January 2015 at 10:53, Will Sharkey <[email protected] >> <javascript:>> wrote: >> >>> Hi, >>> >>> I've been picking up python recently and while doing a mundane task in >>> Maya, I decided to quickly write a script for practice. Then I got really >>> into it and looked up how to make a basic menu!! >>> >>> I noticed a snag in my script. I'm simply changing the .overrideColor on >>> the shape, but I noticed my script doesnt work it the shapes are not named >>> the same, its not a big deal but I'd love to know the answer.: >>> >>> import maya.cmds as mc >>> >>> def redWireColour(): >>> selection = mc.ls( selection=True ) >>> >>> for i in range (len (selection)): >>> mc.setAttr( selection[i] + '|curveShape.overrideEnabled', 1 ) >>> mc.setAttr( selection[i] + '|curveShape.overrideColor', 4 ) >>> >>> >>> >>> So the name 'curveShape' is hardcoded, which isnt good. How would one >>> look up the shape name of the object and add it to the ' >>> .overrideEnabled'? >>> >>> Thanks in advance >>> >>> -- >>> 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] >>> <javascript:>. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/python_inside_maya/3a701563-f870-40b6-b039-058ce61c6fd2%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/python_inside_maya/3a701563-f870-40b6-b039-058ce61c6fd2%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> > -- 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/3ab287e8-2452-4b79-8140-ccce129cee69%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
