How do I get the current ColorDefinition?

How do I get the current ColorDefinition?

There is a function given a CDF. NXOpen > CDF > GetColorDefinitions()

But How do I get the current CDF ?

I've not yet had a need to get at the current CDF, but I did find a code example on GTAC that may be of interest.

Search on GTAC solutions for
nx_api4119
or the phrase:
"nxopen sample load specified color definition file"

May I ask why you need the CDF?
You don't need the CDF in order to get color definitions -- there are other ways.

' FIND CURRENT COLOR DEFINITION OF 1 TO 216 FROM COLOR PALETTE
' Carlo Tony Daristotile on 2014-01-06
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

Sub Main()
lw.Open
dim colormanager1 as colormanager = workPart.colors
for i as integer = 0 to 216
dim nxcolor1 as nxcolor = colormanager1.find(i)
dim rgb1 as NXColor.Rgb = nxcolor1.getrgb
dim clr_num as integer
dim rgb1s(2) as double
rgb1s(0) = rgb1.r
rgb1s(1) = rgb1.g
rgb1s(2) = rgb1.b
ufs.Disp.AskClosestColor(UFConstants.UF_DISP_rgb_model, _
rgb1s, _
UFConstants.UF_DISP_CCM_EUCLIDEAN_DISTANCE, _
clr_num )
if i = 0 then
lw.Writeline("{ {""" & nxcolor1.label & """,""" & i & """,""" & Format(rgb1.r , "0.0000000") & """,""" & Format(rgb1.g , "0.0000000") & """,""" & Format(rgb1.b , "0.0000000") & """} , _ ")
else if i = 216
lw.Writeline("{""" & nxcolor1.label & """,""" & i & """,""" & Format(rgb1.r , "0.0000000") & """,""" & Format(rgb1.g , "0.0000000") & """,""" & Format(rgb1.b , "0.0000000") & """} }")
else
lw.Writeline("{""" & nxcolor1.label & """,""" & i & """,""" & Format(rgb1.r , "0.0000000") & """,""" & Format(rgb1.g , "0.0000000") & """,""" & Format(rgb1.b , "0.0000000") & """} , _ ")
end if
next
lw.close
End Sub
End Module

Carlo Tony Daristotile

' SET COLOR DEFINITION PALETTE OF 0 TO 216
' Carlo Tony Daristotile on 2014-01-06
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
Sub Main()
lw.Open
for i as integer = 0 to color_palette.GetUpperBound(0)
dim clr_name as string
clr_name = color_palette(i,0)
dim clr_num as integer
clr_num = cint(color_palette(i,1))
dim rgb1s(2) as double
rgb1s(0) = cdbl(color_palette(i,2))
rgb1s(1) = cdbl(color_palette(i,3))
rgb1s(2) = cdbl(color_palette(i,4))
ufs.Disp.SetColor(clr_num, _
UFConstants.UF_DISP_rgb_model, _
clr_name, _
rgb1s )
next
'Downloads the color table to the graphics display
'int UF_DISP_load_color_table(void)
ufs.Disp.LoadColorTable()
lw.close
End Sub

dim color_palette as string(,) = _
{ {"Background","0","0.8235294","0.8313725","0.8392157"} , _
{"White","1","1.0000000","1.0000000","1.0000000"} , _
{"Pale Lemon","2","1.0000000","0.9803922","0.7490196"} , _
{"Medium Lemon","3","1.0000000","0.9607843","0.6549020"} , _
{"Strong Lemon","4","1.0000000","0.9490196","0.5137255"} , _
{"Medium Yellow","5","1.0000000","0.9411765","0.4941176"} , _
{"Yellow","6","1.0000000","1.0000000","0.0000000"} , _
{"Pale Sky","7","0.8823529","0.9607843","1.0000000"} , _
{"Pale Green","8","0.8431373","1.0000000","0.7803922"} , _
{"Pale Lime","9","0.8000000","1.0000000","0.6000000"} , _
{"Medium Lime","10","0.8000000","1.0000000","0.4000000"} , _
{"Lime","11","0.8000000","1.0000000","0.2000000"} , _
{"Deep Lemon","12","1.0000000","0.9098039","0.3843137"} , _
{"Pale Cyan","13","0.7411765","1.0000000","1.0000000"} , _
{"Pale Emerald","14","0.6000000","1.0000000","0.7921569"} , _
{"Powder Gray","15","0.9490196","0.9490196","0.9490196"} , _
{"Pale Spring","16","0.8666667","0.9215686","0.8392157"} , _
{"Pale Yellow","17","1.0000000","0.9411765","0.6627451"} , _
{"Strong Pistachio","18","0.8627451","0.8901961","0.6039216"} , _
{"Medium Cyan","19","0.6000000","1.0000000","1.0000000"} , _
{"Medium Emerald","20","0.4470588","1.0000000","0.8039216"} , _
{"Pale Aqua","21","0.8627451","0.9372549","0.9294118"} , _
{"Pale Mint","22","0.8156863","0.9098039","0.8352941"} , _
{"Pale Khaki","23","0.7568627","0.7568627","0.5647059"} , _
{"Deep Pistachio","24","0.8117647","0.8705882","0.4196078"} , _
{"Strong Cyan","25","0.3058824","1.0000000","1.0000000"} , _
{"Medium Aqua","26","0.7529412","0.8901961","0.8745098"} , _
{"Pale Turquoise","27","0.6862745","0.8588235","0.8588235"} , _
{"Medium Spring","28","0.7960784","0.9019608","0.7843137"} , _
{"Strong Green","29","0.2000000","1.0000000","0.2000000"} , _
{"Strong Lime","30","0.7372549","0.9294118","0.2039216"} , _
{"Cyan","31","0.0000000","1.0000000","1.0000000"} , _
{"Medium Sky","32","0.7647059","0.8784314","0.9450980"} , _
{"Strong Aqua","33","0.6235294","0.8352941","0.8235294"} , _
{"Medium Mint","34","0.7058824","0.8588235","0.7450980"} , _
{"Medium Green","35","0.6000000","1.0000000","0.4000000"} , _
{"Green","36","0.0000000","1.0000000","0.0000000"} , _
{"Pale Pink","37","0.9764706","0.8431373","0.9058824"} , _
{"Pale Salmon","38","1.0000000","0.8431373","0.8235294"} , _
{"Pale Orange","39","1.0000000","0.8000000","0.6000000"} , _
{"Medium Peach","40","0.9843137","0.7803922","0.6274510"} , _
{"Medium Orange","41","1.0000000","0.7529412","0.2980392"} , _
{"Deep Yellow","42","1.0000000","0.7921569","0.0000000"} , _
{"Pale Lavender","43","0.7921569","0.7803922","0.8941176"} , _
{"Light Gray","44","0.8000000","0.8000000","0.8000000"} , _
{"Pale Brown","45","0.9411765","0.8000000","0.5254902"} , _
{"Strong Yellow","46","1.0000000","0.8627451","0.2274510"} , _
{"Medium Olive","47","0.8000000","0.8000000","0.2000000"} , _
{"Pale Olive","48","0.9019608","0.8588235","0.2862745"} , _
{"Pale Ice","49","0.8117647","0.8431373","0.9098039"} , _
{"Ash Gray","50","0.8745098","0.8745098","0.8745098"} , _
{"Pale Pistachio","51","0.9098039","0.9254902","0.8470588"} , _
{"Pale Gold","52","0.8901961","0.8274510","0.6156863"} , _
{"Medium Gold","53","0.8823529","0.7607843","0.2823529"} , _
{"Pale Leaf","54","0.6196078","0.7921569","0.2392157"} , _
{"Medium Cornflower","55","0.4000000","0.8000000","1.0000000"} , _
{"Deep Aqua","56","0.3764706","0.8039216","0.8235294"} , _
{"Pale Pine","57","0.7647059","0.8823529","0.7450980"} , _
{"Medium Pistachio","58","0.8901961","0.9098039","0.5254902"} , _
{"Deep Lime","59","0.6627451","0.8901961","0.0000000"} , _
{"Deep Green","60","0.4000000","0.8000000","0.0000000"} , _
{"Pale Cornflower","61","0.6000000","0.8000000","1.0000000"} , _
{"Deep Cyan","62","0.0000000","0.8117647","0.8117647"} , _
{"Strong Spring","63","0.6705882","0.8392157","0.6274510"} , _
{"Deep Spring","64","0.6117647","0.8156863","0.4941176"} , _
{"Medium Pine","65","0.6274510","0.8313725","0.6588235"} , _
{"Strong Pine","66","0.5333333","0.7333333","0.4392157"} , _
{"Strong Sky","67","0.5960784","0.7882353","0.9215686"} , _
{"Strong Mint","68","0.6039216","0.8117647","0.6588235"} , _
{"Strong Emerald","69","0.0000000","0.8039216","0.5254902"} , _
{"Pale Sea","70","0.7176471","0.8117647","0.7647059"} , _
{"Pale Forest","71","0.4313725","0.7019608","0.3803922"} , _
{"Deep Mint","72","0.4705882","0.7529412","0.5490196"} , _
{"Pale Magenta","73","1.0000000","0.6627451","1.0000000"} , _
{"Pale Peach","74","0.9607843","0.8313725","0.7254902"} , _
{"Strong Salmon","75","1.0000000","0.6000000","0.6000000"} , _
{"Pale Carrot","76","0.9647059","0.6274510","0.2862745"} , _
{"Strong Orange","77","1.0000000","0.6000000","0.2000000"} , _
{"Orange","78","1.0000000","0.6000000","0.0000000"} , _
{"Medium Ice","79","0.7019608","0.7647059","0.8784314"} , _
{"Pale Stone","80","0.8666667","0.8549020","0.7882353"} , _
{"Pale Maroon","81","0.8117647","0.6039216","0.6117647"} , _
{"Medium Coral","82","0.7882353","0.5921569","0.3960784"} , _
{"Medium Brown","83","0.8000000","0.6000000","0.2000000"} , _
{"Strong Gold","84","0.6705882","0.5960784","0.3215686"} , _
{"Pale Midnight","85","0.6039216","0.7294118","0.8392157"} , _
{"Strong Lavender","86","0.5921569","0.5843137","0.7725490"} , _
{"Silver Gray","87","0.6000000","0.6000000","0.6000000"} , _
{"Medium Stone","88","0.7686275","0.7490196","0.6470588"} , _
{"Strong Olive","89","0.6078431","0.5647059","0.0000000"} , _
{"Medium Khaki","90","0.6980392","0.6941176","0.4039216"} , _
{"Pale Blue","91","0.5372549","0.7137255","1.0000000"} , _
{"Deep Ice","92","0.4000000","0.6000000","0.8000000"} , _
{"Medium Sea","93","0.5176471","0.6784314","0.6078431"} , _
{"Pale Moss","94","0.2156863","0.6666667","0.5333333"} , _
{"Strong Khaki","95","0.5529412","0.5803922","0.2039216"} , _
{"Medium Leaf","96","0.4627451","0.6235294","0.1647059"} , _
{"Strong Cornflower","97","0.2000000","0.6000000","1.0000000"} , _
{"Medium Azure","98","0.0000000","0.6156863","0.8509804"} , _
{"Pale Teal","99","0.1450980","0.6235294","0.6470588"} , _
{"Medium Moss","100","0.0000000","0.5882353","0.4352941"} , _
{"Medium Forest","101","0.2000000","0.6000000","0.2000000"} , _
{"Strong Sea","102","0.2823529","0.5647059","0.4156863"} , _
{"Cornflower","103","0.0000000","0.6000000","1.0000000"} , _
{"Pale Azure","104","0.0000000","0.6901961","0.9411765"} , _
{"Medium Teal","105","0.0000000","0.6000000","0.6000000"} , _
{"Deep Emerald","106","0.0000000","0.6745098","0.3960784"} , _
{"Deep Pine","107","0.3686275","0.5215686","0.2470588"} , _
{"Emerald","108","0.0000000","0.6000000","0.0000000"} , _
{"Medium Pink","109","0.9607843","0.7490196","0.8470588"} , _
{"Medium Salmon","110","1.0000000","0.7019608","0.7058824"} , _
{"Pale Red","111","1.0000000","0.5647059","0.5647059"} , _
{"Medium Red","112","1.0000000","0.4000000","0.4000000"} , _
{"Deep Peach","113","0.9647059","0.6274510","0.4078431"} , _
{"Deep Orange","114","1.0000000","0.4000000","0.0000000"} , _
{"Pale Purple","115","0.7098039","0.7098039","1.0000000"} , _
{"Pale Fuchsia","116","0.8274510","0.6235294","0.7843137"} , _
{"Pale Plum","117","0.8000000","0.4000000","0.6000000"} , _
{"Strong Peach","118","0.9686275","0.6862745","0.5176471"} , _
{"Medium Carrot","119","0.9019608","0.4823529","0.0705882"} , _
{"Strong Coral","120","0.8235294","0.4196078","0.2156863"} , _
{"Pale Steel","121","0.7529412","0.8235294","0.8823529"} , _
{"Medium Lavender","122","0.6784314","0.6588235","0.8313725"} , _
{"Smoke Gray","123","0.6941176","0.6941176","0.6941176"} , _
{"Medium Maroon","124","0.6000000","0.4000000","0.4000000"} , _
{"Brown","125","0.6000000","0.4000000","0.2000000"} , _
{"Deep Olive","126","0.4352941","0.4078431","0.0000000"} , _
{"Medium Purple","127","0.4470588","0.4156863","1.0000000"} , _
{"Pale Violet","128","0.4000000","0.4000000","0.8000000"} , _
{"Medium Steel","129","0.5960784","0.6666667","0.6862745"} , _
{"Granite Gray","130","0.4000000","0.4000000","0.4000000"} , _
{"Deep Khaki","131","0.4000000","0.4000000","0.2000000"} , _
{"Deep Leaf","132","0.3058824","0.3803922","0.0000000"} , _
{"Medium Turquoise","133","0.5098039","0.7137255","0.7686275"} , _
{"Medium Royal","134","0.2000000","0.4000000","0.8000000"} , _
{"Strong Steel","135","0.2117647","0.3764706","0.5725490"} , _
{"Strong Moss","136","0.0000000","0.3450980","0.1568627"} , _
{"Deep Sea","137","0.2000000","0.4000000","0.2000000"} , _
{"Strong Leaf","138","0.2901961","0.4509804","0.1058824"} , _
{"Medium Blue","139","0.2549020","0.3764706","1.0000000"} , _
{"Strong Turquoise","140","0.1921569","0.5215686","0.6078431"} , _
{"Strong Azure","141","0.0000000","0.4000000","0.6000000"} , _
{"Strong Teal","142","0.0000000","0.4000000","0.4000000"} , _
{"Deep Forest","143","0.1098039","0.2862745","0.0117647"} , _
{"Strong Forest","144","0.0000000","0.4000000","0.0000000"} , _
{"Medium Magenta","145","1.0000000","0.4274510","1.0000000"} , _
{"Strong Magenta","146","1.0000000","0.2274510","0.8823529"} , _
{"Deep Red","147","1.0000000","0.1882353","0.1882353"} , _
{"Deep Salmon","148","1.0000000","0.5450980","0.5450980"} , _
{"Pale Crimson","149","0.8509804","0.3372549","0.2980392"} , _
{"Deep Pink","150","0.9176471","0.4313725","0.6470588"} , _
{"Pale Tan","151","0.8274510","0.7411765","0.6705882"} , _
{"Deep Magenta","152","0.8000000","0.2000000","0.8000000"} , _
{"Strong Tan","153","0.7137255","0.5725490","0.4313725"} , _
{"Deep Tan","154","0.7019608","0.5058824","0.3647059"} , _
{"Medium Crimson","155","0.8000000","0.2000000","0.2000000"} , _
{"Deep Gold","156","0.6117647","0.4549020","0.1607843"} , _
{"Pale Coral","157","0.8196078","0.7019608","0.6196078"} , _
{"Pale Indigo","158","0.6509804","0.6392157","0.7686275"} , _
{"Medium Gray","159","0.4901961","0.4901961","0.4901961"} , _
{"Strong Plum","160","0.6000000","0.2000000","0.4000000"} , _
{"Strong Maroon","161","0.6000000","0.2000000","0.2000000"} , _
{"Deep Brown","162","0.4000000","0.2000000","0.0000000"} , _
{"Medium Tan","163","0.7764706","0.6588235","0.5529412"} , _
{"Purple","164","0.4000000","0.2000000","0.8000000"} , _
{"Medium Indigo","165","0.4627451","0.4156863","0.5882353"} , _
{"Medium Violet","166","0.3176471","0.1215686","0.4980392"} , _
{"Deep Carrot","167","0.4274510","0.1764706","0.0392157"} , _
{"Deep Stone","168","0.2862745","0.2705882","0.1803922"} , _
{"Strong Blue","169","0.2000000","0.2000000","1.0000000"} , _
{"Strong Ice","170","0.5960784","0.6901961","0.8470588"} , _
{"Medium Midnight","171","0.5019608","0.6352941","0.7058824"} , _
{"Deep Indigo","172","0.2431373","0.2000000","0.3294118"} , _
{"Dark Gray","173","0.2000000","0.2000000","0.2000000"} , _
{"Deep Umber","174","0.1607843","0.1411765","0.1333333"} , _
{"Deep Cornflower","175","0.0000000","0.2666667","1.0000000"} , _
{"Pale Royal","176","0.2196078","0.4705882","0.7529412"} , _
{"Deep Turquoise","177","0.1254902","0.3450980","0.4039216"} , _
{"Deep Azure","178","0.0000000","0.2470588","0.3686275"} , _
{"Deep Teal","179","0.0000000","0.2784314","0.2509804"} , _
{"Deep Moss","180","0.0000000","0.2274510","0.0000000"} , _
{"Magenta","181","1.0000000","0.0000000","1.0000000"} , _
{"Strong Red","182","1.0000000","0.3176471","0.3176471"} , _
{"Medium Fuchsia","183","0.6941176","0.4588235","0.5764706"} , _
{"Strong Fuchsia","184","0.5647059","0.1960784","0.4156863"} , _
{"Strong Pink","185","0.9333333","0.5843137","0.7411765"} , _
{"Red","186","1.0000000","0.0000000","0.0000000"} , _
{"Pale Umber","187","0.5254902","0.4509804","0.3803922"} , _
{"Medium Plum","188","0.7529412","0.1882353","0.6431373"} , _
{"Strong Brown","189","0.6431373","0.4000000","0.0000000"} , _
{"Strong Carrot","190","0.5647059","0.3137255","0.0274510"} , _
{"Strong Stone","191","0.5764706","0.5450980","0.3921569"} , _
{"Deep Coral","192","0.6745098","0.2156863","0.0745098"} , _
{"Deep Lavender","193","0.4784314","0.4509804","0.7098039"} , _
{"Strong Indigo","194","0.3607843","0.2862745","0.5019608"} , _
{"Medium Umber","195","0.3725490","0.3137255","0.2705882"} , _
{"Strong Umber","196","0.2549020","0.2156863","0.1960784"} , _
{"Deep Crimson","197","0.4941176","0.0000000","0.0000000"} , _
{"Strong Crimson","198","0.6000000","0.0000000","0.0000000"} , _
{"Strong Purple","199","0.4000000","0.0000000","1.0000000"} , _
{"Deep Purple","200","0.4000000","0.0000000","0.8000000"} , _
{"Iron Gray","201","0.2980392","0.2980392","0.2980392"} , _
{"Deep Fuchsia","202","0.2588235","0.0980392","0.2588235"} , _
{"Deep Plum","203","0.3960784","0.0000000","0.2666667"} , _
{"Deep Maroon","204","0.4000000","0.0000000","0.0000000"} , _
{"Deep Sky","205","0.3372549","0.6941176","1.0000000"} , _
{"Strong Royal","206","0.0000000","0.2235294","0.6039216"} , _
{"Strong Midnight","207","0.1647059","0.2862745","0.4470588"} , _
{"Strong Violet","208","0.2235294","0.0666667","0.3333333"} , _
{"Deep Violet","209","0.1411765","0.0000000","0.1411765"} , _
{"Charcoal Gray","210","0.0470588","0.0470588","0.0470588"} , _
{"Blue","211","0.0000000","0.0000000","1.0000000"} , _
{"Deep Blue","212","0.0000000","0.0000000","0.7529412"} , _
{"Deep Steel","213","0.1411765","0.2509804","0.3803922"} , _
{"Deep Royal","214","0.0705882","0.1568627","0.4274510"} , _
{"Deep Midnight","215","0.0588235","0.1411765","0.2431373"} , _
{"Black","216","0.0000000","0.0000000","0.0000000"} }

End Module

Carlo Tony Daristotile

Is it possible to redefine what a color is made of so that you can use the id to color your objects?

As an example black is id 216 which is set to rgb of 0.0, 0.0, 0.0 but I would like to use gunmetal black which for this example is 0.44, 0.53, 0.57. Is there a way to redefine what the id is so that I can color something gunmetal?

just a noob trying to learn how to program in vb and python for NX

The NX colors are stored in a "Color Definition File" (*.cdf), which is a plain text file that you can edit. To create a copy of the current cdf, go to menu -> preferences -> color palette... Expand the "options" section of the dialog if necessary and pick the "save cdf as" icon. Save the new file in a convenient location and open it in your favorite text editor. In the NX cdf, the color values are scaled from zero to 1; to convert RGB values, divide each by 255. Save your edits to the cdf, then in the options section of the NX color palette dialog, choose the "open" icon to apply your new color settings.

Normalizing values from 0-255 to 0-1 would not be an issue.

Is there anyway to set colors of objects without having to create a custom cdf file? In OpenGL you could just set the rgb of a color and send it to the draw buffer. Is there a similar option?

just a noob trying to learn how to program in vb and python for NX

There is a SetColor function that looks like it will immediately alter the color table definition. However, I've not found the right "update" function that will repaint the display; any objects using the color before the color definition changes display as the old color on the screen until you close and reopen the part or until the display part changes.

For what it's worth, here's my code so far:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim workPart As Part = theSession.Parts.Work

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Set color")

Dim RGBvalues(2) As Double
RGBvalues(0) = 0.44
RGBvalues(1) = 0.53
RGBvalues(2) = 0.57

theUfSession.Disp.SetColor(216, UFConstants.UF_DISP_rgb_model, "Gunmetal", RGBvalues)

'For Each tempBody As Body In workPart.Bodies
' tempBody.RedisplayObject()
'Next

'theUfSession.Disp.Refresh()

'theUfSession.Disp.MakeDisplayUpToDate()

theUfSession.Disp.RegenerateDisplay()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module