PolyColorPerVertex with Pymel

Good afternoon,

Can anyone tell me how to use the pymel.core.datatypes.PolyColorPerVertex () class ??
I understand that it works with a mesh node, but I don’t understand how it is used.
I know I can use the cmds.PolyVertexPerColor (), but I need to know how it works with Pymel since my code is working object-oriented.

Thank you.

Hey Daniel,

Based on the documentation you have a good example down the bottom of use cases, and also it says that it derives directly from the command, I assume it works by just wrapping the function calls.

PyMel mirrors all of the maya.cmds commands in the pymel.core module.

For example:

import pymel.core as pm

If you want to program in an object-oriented style, pymel’s version of these maya commands will usually return objects rather than strings. That is the primary difference.

As for your question about the PolyColorPerVertex class, first I want to say that I believe PolyColorPerVertex is in pymel.core.nodetypes, not in pymel.core.datatypes, but I digress.

pymel.core.nodetypes.PolyColorPerVertex is the object type that is returned when you retrieve the polyColorPerVertex maya node using pm.ls(). It’s just the pymel representation of the actual maya node created by the polyColorPerVertex command. You most likely don’t need it unless you want to get or set values stored on the node itself.

1 Like

Thanks for your answer, yes, I made the wrong path, it is pymel.core.nodetypes.

JodaRobert, will you have an example to help me?

My goal is to know how to use the methods of the PolyColorPerVertex () class. Again, I know I can do it with cmds.PolyColorPerVertex (), but I want to use class methods. there are some attached.


Thank you very much for your help.

How can I pass that color information to a vertex using pymel?

I apologize, but your pictures aren’t loading for me. I’ll try to answer as best as I can.

pymel.core.nodetypes.PolyColorPerVertex isn’t going to help you here. It’s just not designed to be used in the way I think you’re expecting.

If you want to use a more object-oriented style of scripting, I would instead look at the pymel.core.general.MeshVertex class. You can set and query colors directly on the vertices themselves.

The documentation is here:

For a brief example, you can use MeshVertex like this:

import pymel.core as pm
cube_tfm, cube_shape = pm.polyCube()

# returns pymel.core.general.MeshVertex('pCubeShape1.vtx[0:7]')
vertices = cube_tfm.verts

# color the first vert red
first_vert = vertices[0]

You can also pass a MeshVertex class to the pymel polyColorPerVertex command to easily color a subset of vertices (or only the selected ones, etc.), so mix and match the two methods according to your need.

Keep in mind, this is going to be a lot slower on dense meshes than pm.polyColorPerVertex will be, but is more convenient for some cases.

1 Like

Thank you very much, now I understand how it works. It seems to be accessed directly from the vertices of a geometry.
I was trying to send a vertex and a color as an argument.

I will try, thank you very much for your help.