Hi everyone!
I have imported a vrml file from maya into rhino 5 (I had to pass through rhino 4 to keep the vertexes color, don't know why btw..)
I would like to read the value of the color for each face of the mesh, but apparentely rhinoscriptsyntax.MeshVertexColors doesn't give me an output I can read and use , and same goes when I try to use rhinoscriptsyntax.ColorHLSToRGB command
look:
import rhinoscriptsyntax as rs
rs.Command("_selmesh")
rs.Command("unweld 0")
rs.UnselectAllObjects
rs.AddLayer("MainMesh")
#'pick Mesh which is unwelded at 0
strObject = rs.GetObject("Select mesh", 32)
#'store mesh in base layer
rs.ObjectLayer(strObject,"MainMesh")
#' get the face vertices of the mesh
arrFaces = rs.MeshFaces(strObject, True)
#'get the vertex colors of the mesh
color = rs.MeshVertexColors(strObject)
i = 0
arrFace = []
arrHLS = []
arrFaceVertices2 = []
while i <= len(arrFaces)-1:
''''''arrFace.append(arrFaces[i])
''''''arrFace.append(arrFaces[i+1])
''''''arrFace.append(arrFaces[i+2])
''''''arrFace.append(arrFaces[i+3])
''''''arrHLS.append(rs.ColorRGBToHLS(color[i]))
''''''print(color[i])
''''''print arrHLS
'''''' i = i + 4
''''''arrFace = []
''''''arrHLS = []
''''''arrFaceVertices2 = []
############
The result I get is :
Color [A=255, R=55, G=55, B=55]
[<Rhino.Display.ColorHSL object at 0x00000000000001F7 [Rhino.Display.ColorHSL]>]
Color [A=255, R=55, G=55, B=55]
[<Rhino.Display.ColorHSL object at 0x00000000000001F8 [Rhino.Display.ColorHSL]>]
Color [A=255, R=55, G=55, B=55]
[<Rhino.Display.ColorHSL object at 0x00000000000001F9 [Rhino.Display.ColorHSL]>]
Color [A=255, R=59, G=59, B=59]
[<Rhino.Display.ColorHSL object at 0x00000000000001FA [Rhino.Display.ColorHSL]>]
Color [A=255, R=55, G=55, B=55]
[<Rhino.Display.ColorHSL object at 0x00000000000001FB [Rhino.Display.ColorHSL]>]
But if I try to get color[i][0] I get an error, how can I access to the numbers RGB or the HLS one as numbers?
Thanks a lot!
V.
Alessio Erioli
Hi Vince!!!
Color variable type is an hexadecimal number wich represents all 3 RGB components. If you use rhinoscriptsynthax you should extract them separately with rs.ColorRedValue(color), rs.ColorBlueValue(color), rs.ColorGreenValue(color). For example, here's a script that writes the Red component value on each of the mesh's points:
import rhinoscriptsyntax as rs
myMesh = rs.GetObject("select a mesh", rs.filter.mesh)
vCol = rs.MeshVertexColors(myMesh)
vPt = rs.MeshVertices(myMesh)
count = 0
for pt in vPt:
co = vCol[count]
rs.AddText(str(rs.ColorRedValue(co)),pt)
count+= 1
try it out and let me know if this works. Oh, and... are you still in London?
Apr 15, 2012