Submitted by Snied on Mon, 11/27/2023 - 02:52
Forums:
Hello,
we need to harmonize the color palette for our NX parts. For this I have a journal that automatically creates the needed colors when a part is checked out. Now I am looking for a way to modify also the favourites in the color palette in this journal to make it easier for the user to apply the needed colors. Did anyone met this problem before and found a solution for that?
Thanks and best regards.
Snied
re: favorite colors
Does your code read/write the CDF file directly?
If you open the CDF in a plain text editor, you will see the color name followed by the RGB values. The favorite colors will have a number (0-59) after the RGB value.
We have a lot of parts that
We have a lot of parts that are already colored. These parts have different color palettes. When I exchange the complete color palette for this parts, the parts may get unwanted colors. For this reason I only want to change/add 5 colors and these new colors should be placed at the beginning of the favorites in the color palette. New parts already have a common color palette, the problem are the older once.
This is the code I'm using now to add the new colors, but I didn't find a way to modify the favorites inside the journal.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
If IsNothing(theSession.Parts.BaseWork) Then
'no active part
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim rgb1(2) As Double
Dim colorname1 As String = "Company_Red"
Dim colorhandle1 As Integer = 110
rgb1(0) = Math.Round(155.0/255.0, 7)
rgb1(1) = Math.Round(21.0/255.0, 7)
rgb1(2) = Math.Round(63.0/255.0, 7)
ufs.Disp.SetColor(colorhandle1, UFConstants.UF_DISP_rgb_model, colorname1, rgb1)
Dim myColor As NXColor
myColor = theSession.Parts.Work.Colors.Find(colorhandle1)
lw.WriteLine("color name: " & myColor.label)
lw.WriteLine("color handle: " & myColor.handle)
lw.WriteLine("color rgb: " & myColor.GetRgb.ToString)
ufs.Disp.LoadColorTable()
Dim ColorDefinition1 As ColorDefinition
'?????????
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
Maybe the ColorDefinition Class - FavoriteIndex can do this, but I am not able to handle this correctly.
Thanks!