Functionality to toggle visibility of colors on meshes

227 views
Skip to first unread message

Nirmal Kumar

unread,
Nov 17, 2021, 12:25:37 PM11/17/21
to Python Programming for Autodesk Maya
Hello everyone,

I’m trying to develop a hide/show functionality using python in Maya.

I was able to develop a functionality that assigns colors to selected meshes using the polyColorPerVertex command.

```
cmds.polyColorPerVertex(self.select, rgb=(1,0.5,0), cdo=1)
#I fetch self.select using the cmds.ls (sl-True) command, which I have declared previously
```

coming to the problem now , I need to develop a Hide/Show functionality , so far , I’ve tried to turn off the visibility mode , using cdo=0 and it did not work

```
cmds.polyColorPerVertex(self.select, cdo = 0)
```

I have also tried to set it as a attribute using

```
for obj in self.select:
      cmds.setAttr('obj.displayColors',False)
```

and I’m gettng the following error

RuntimeError: setAttr: No object matches name: obj.displayColors

Can someone help me on where I could be going wrong or help me with any python command which could enable me to design the Hide/Show functionality.

Thank you! Good day.



Driftwood

unread,
Nov 29, 2021, 10:34:55 PM11/29/21
to Python Programming for Autodesk Maya
I think you should use Color Set to manage the vertex color.

import maya.cmds as cmds
# create a color set
cmds.polyColorSet(colorSet="my_colorSet", create=True, currentColorSet=True)
# assgin color
cmds.polyColorPerVertex(rgb=(1,0.4,0.2),alpha=1,cdo=True)
# hide color (switch to the original color set)
cmds.polyColorSet(colorSet="colorSet1", currentColorSet=True)

Reply all
Reply to author
Forward
0 new messages