NXOpen Component get color in rgb

Hi everyone,
Can you help me?

How can I get the color of a NXOpen.Component in RGB mode by coding?

Thank you very much.

http://www.nxjournaling.com/comment/3098#comment-3098

The code in the link above will allow you to select an object, then it will report the object color (NX color name, NX color number, and RGB values).

Thank you for helping me. Sorry, but I but I didn't explain myself well.
I process all components in assembly. For each component (NXOpen.Component), I should get the color in RGB mode.

CODE:
Session theSession = Session.GetSession();
Part workPart = theSession.Parts.Work;
ComponentAssembly comp = workPart.ComponentAssembly;
foreach (Component _child in comp.RootComponent.GetChildren())
{
/// GET RGB COLOR FOR _CHILD
}

The code above casts the selected object to a "DisplayableObject" type then reports the color. A component is a type of DisplayableObject, so no conversion is necessary in your case; but the rest of the code applies to your situation as I understand it.

If "myDispObj" holds a reference to your component, the code below will report the NX color name and the RGB values.

lw.WriteLine("color number: " & myDispObj.Color)
Dim myColor As NXColor
myColor = theSession.Parts.Work.Colors.Find(myDispObj.Color)
lw.WriteLine("color label: " & myColor.Label)
lw.WriteLine("color rgb: " & myColor.GetRgb.ToString)
Dim red As Integer = myColor.GetRgb.R * 255
Dim green As Integer = myColor.GetRgb.G * 255
Dim blue As Integer = myColor.GetRgb.B * 255

lw.WriteLine("red: " & red.ToString)
lw.WriteLine("green: " & green.ToString)
lw.WriteLine("blue: " & blue.ToString)
lw.WriteLine("")

NX reports the RGB values on a scale from 0 to 1, so some math is required to get it in the more standard scale of 0 - 255. If you want the color as a hexadecimal number (or string), you will need to convert it. A quick search turned up this thread that may be helpful:
http://www.vbforums.com/showthread.php?642704-RESOLVED-RGB-to-Hex-conver...

I should also mention that component colors can be a bit tricky. A component can have a specific color assigned or it can inherit the color from the component part file; also, a user can change the color of individual faces or use the "random color" option, in which case what you see on screen may not match the color reported for the component itself.

Thank you for all! It works perfectly!!

Hi everyone,
at the end, I got the color of the component following your advice. At the same time, I tried to get the material of the component. Here the code:

Part dispPart = theSession.Parts.Display;
if(myComponent.HasUserAttribute("Material",
NXObject.AttributeType.String, -1))
{
Guide.InfoWriteLine("material");
}
else
{
Guide.InfoWriteLine("No material");

}
I don't know if this is correct. Thank you in advance.

If .HasUserAttribute returns True, you could use .GetUserAttributeAsString to get the value of the attribute.