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]> 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].
> 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/CAPoKtNea5dEYTdnEWQFJJ5GjeFjaFAOe_oaFDAHYMQSoZqw5NA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.