<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: change colour of curve objects in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9767760#M5356</link>
    <description>&lt;LI-CODE lang="python"&gt;import maya.cmds as cmds
from functools import partial

def changeColor(omenu, cDict, *ignore):
    crvSel = cmds.ls(sl=True)
    crv_shape = cmds.listRelatives(crvSel, s = True)
    if crv_shape is None:
        print("Nothing selected")
    else:
        cmds.setAttr(crv_shape[0] + ".overrideEnabled", 1)
        cmds.setAttr(crv_shape[0] + ".overrideRGBColors", 0)
        key = cmds.optionMenu(omenu, q=True, v=True)
        val = cDict.get(key, 0)
        cmds.setAttr(crv_shape[0] + ".overrideColor", val)

def buildMenu():
    if cmds.window("change_colors", exists = True):
        cmds.deleteUI("change_colors")
    cmds.window("change_colors")

    cmds.columnLayout()
    omenu = cmds.optionMenu( label="Colors")
    colorDict = {"Red" : 13, "Blue": 6, "Yellow": 17, "Green": 14, "Pink" : 9, "Light Blue" : 18}
    for k in sorted(colorDict.keys()):
        cmds.menuItem( label=k )
    cmds.optionMenu(omenu, e = True, cc=partial(changeColor, omenu, colorDict))
    cmds.showWindow()

buildMenu()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this on for size&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Sep 2020 07:52:09 GMT</pubDate>
    <dc:creator>forrest.brent</dc:creator>
    <dc:date>2020-09-25T07:52:09Z</dc:date>
    <item>
      <title>change colour of curve objects</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9766686#M5355</link>
      <description>&lt;P&gt;So I have an option Menu with a list of colours. When I select the curve, and the colour from the options and I run the code nothing happens. Can someone help please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CODE:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import maya.cmds as cmds&lt;/P&gt;&lt;P&gt;if cmds.window('change_colors', exists = True):&lt;BR /&gt;cmds.deleteUI('change_colors')&lt;/P&gt;&lt;P&gt;cmds.window('change_colors')&lt;/P&gt;&lt;P&gt;cmds.columnLayout()&lt;BR /&gt;cmds.optionMenu( label='Colors')&lt;/P&gt;&lt;P&gt;red = cmds.menuItem( label='Red' )&lt;BR /&gt;blue = cmds.menuItem( label='Blue' )&lt;BR /&gt;yellow = cmds.menuItem( label='Yellow' )&lt;BR /&gt;green = cmds.menuItem( label='Green' )&lt;BR /&gt;pink = cmds.menuItem( label='Pink' )&lt;BR /&gt;lightBlue = cmds.menuItem( label='Light Blue' )&lt;/P&gt;&lt;P&gt;cmds.showWindow()&lt;/P&gt;&lt;P&gt;crvSel = cmds.ls(sl=True)&lt;/P&gt;&lt;P&gt;crv_shape = cmds.listRelatives(crvSel, s = True)&lt;/P&gt;&lt;P&gt;cmds.setAttr(crv_shape[0] + '.overrideEnabled', 1)&lt;/P&gt;&lt;P&gt;if red == True:&lt;BR /&gt;cmds.setAttr(crv_shape[0] + '.overrideColor', 13)&lt;BR /&gt;if blue == True:&lt;BR /&gt;cmds.setAttr(crv_shape[0] + '.overrideColor', 6)&lt;BR /&gt;if yellow == True:&lt;BR /&gt;cmds.setAttr(crv_shape[0] + '.overrideColor', 17)&lt;BR /&gt;if green == True:&lt;BR /&gt;cmds.setAttr(crv_shape[0] + '.overrideColor', 14)&lt;BR /&gt;if pink == True:&lt;BR /&gt;cmds.setAttr(crv_shape[0] + '.overrideColor', 9)&lt;BR /&gt;if lightBlue == True:&lt;BR /&gt;cmds.setAttr(crv_shape[0] + '.overrideColor', 18)&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2020 18:56:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9766686#M5355</guid>
      <dc:creator>danispag</dc:creator>
      <dc:date>2020-09-24T18:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: change colour of curve objects</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9767760#M5356</link>
      <description>&lt;LI-CODE lang="python"&gt;import maya.cmds as cmds
from functools import partial

def changeColor(omenu, cDict, *ignore):
    crvSel = cmds.ls(sl=True)
    crv_shape = cmds.listRelatives(crvSel, s = True)
    if crv_shape is None:
        print("Nothing selected")
    else:
        cmds.setAttr(crv_shape[0] + ".overrideEnabled", 1)
        cmds.setAttr(crv_shape[0] + ".overrideRGBColors", 0)
        key = cmds.optionMenu(omenu, q=True, v=True)
        val = cDict.get(key, 0)
        cmds.setAttr(crv_shape[0] + ".overrideColor", val)

def buildMenu():
    if cmds.window("change_colors", exists = True):
        cmds.deleteUI("change_colors")
    cmds.window("change_colors")

    cmds.columnLayout()
    omenu = cmds.optionMenu( label="Colors")
    colorDict = {"Red" : 13, "Blue": 6, "Yellow": 17, "Green": 14, "Pink" : 9, "Light Blue" : 18}
    for k in sorted(colorDict.keys()):
        cmds.menuItem( label=k )
    cmds.optionMenu(omenu, e = True, cc=partial(changeColor, omenu, colorDict))
    cmds.showWindow()

buildMenu()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this on for size&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 07:52:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9767760#M5356</guid>
      <dc:creator>forrest.brent</dc:creator>
      <dc:date>2020-09-25T07:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: change colour of curve objects</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9767767#M5357</link>
      <description>&lt;P&gt;The key thing to remember when you're expecting a menu item to issue a command based in it's own value - you need to pass &lt;EM&gt;itself&lt;/EM&gt; to the function its calling.&amp;nbsp; so in this case, omenu refers to "change_colors|columnLayout71|optionMenu37" Which has a weird long name because we didnt name any of our UI elements.&amp;nbsp; Maya needs this to query what the value is.&amp;nbsp; Red == True has no menaing because Red is not a variable that exists anywhere within the scope of your code.&lt;/P&gt;&lt;P&gt;You need a separate function to look at the ui widget, query what it says, and then do something based on what it says.&amp;nbsp; So basically, look at optionmenu called "change_colors|columnLayout71|optionMenu37" - get me the value in plain english (optionmenu query, value=True) that will give you "Red".&amp;nbsp; OK.&amp;nbsp; What to do with "Red"?&amp;nbsp; If red then assign 13.&amp;nbsp; I've put all the names and corresponding index numbers into key value pairs in a dictionary - so if you want to add more you just update the dictionary, instead of making an endless list of if statements.&amp;nbsp; The ui passes the name of the widget, and the dictionary to the changecolor function, and presto - best christmas ever.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 07:58:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9767767#M5357</guid>
      <dc:creator>forrest.brent</dc:creator>
      <dc:date>2020-09-25T07:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: change colour of curve objects</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9768720#M5358</link>
      <description>&lt;P&gt;Thank you so much, and really appreciated your explanation. It worked :). Just one small thing. At the moment you can only change colour of 1 curve instead of multiple. I tried to add a for loop which is marked in red and still its not changing the colour on multiple curves. Am I missing something?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;def changeColor(omenu, cDict, *ignore):&lt;BR /&gt;crvSel = cmds.ls(sl=True)&lt;BR /&gt;crv_shape = cmds.listRelatives(crvSel, s = True)&lt;BR /&gt;if crv_shape is None:&lt;BR /&gt;print("Nothing selected")&lt;BR /&gt;else:&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;for i in crv_shape:&lt;/FONT&gt;&lt;BR /&gt;cmds.setAttr(crv_shape[0] + ".overrideEnabled", 1)&lt;BR /&gt;cmds.setAttr(crv_shape[0] + ".overrideRGBColors", 0)&lt;BR /&gt;key = cmds.optionMenu(omenu, q=True, v=True)&lt;BR /&gt;val = cDict.get(key, 0)&lt;BR /&gt;cmds.setAttr(crv_shape[0] + ".overrideColor", val)&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2020 16:04:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9768720#M5358</guid>
      <dc:creator>danispag</dc:creator>
      <dc:date>2020-09-25T16:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: change colour of curve objects</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9769390#M5359</link>
      <description>You want curveshape[i] not [0]&lt;BR /&gt;</description>
      <pubDate>Fri, 25 Sep 2020 22:25:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/change-colour-of-curve-objects/m-p/9769390#M5359</guid>
      <dc:creator>forrest.brent</dc:creator>
      <dc:date>2020-09-25T22:25:15Z</dc:date>
    </item>
  </channel>
</rss>

