Hi apekas,
Thanks a lot, the link gave me the solution
here is the code with a bonus "change current feature color"
' Create a Block Styler dialog with an RGB Color Picker block.
'
' The update callback demonstrates how to manipulate the returned
' unsigned integer value to get a color from the color table,
' and the name of the color.
'
' The ouput should look something like this:
' Integer Color: 16744576
'Hexadecimal Color: FF8080
' red: 255 red hex: FF
'green: 128 green hex: 80
' blue: 128 blue hex: 80
'Color Number: 148
'Color: Deep Salmon
'============================
' Then the color is affected to the current feature
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.BlockStyler
Public Class RGBColorPicker
'class members
Private Shared theSession As Session
Private Shared theUFSession As UFSession
Private Shared theUI As UI
Private Shared lw As ListingWindow
Public Shared theRGBColorPicker As RGBColorPicker
Private theDialogName As String
Private theDialog As NXOpen.BlockStyler.BlockDialog
Private group0 As NXOpen.BlockStyler.UIBlock ' Block type: Group
Private rGBColorPicker0 As NXOpen.BlockStyler.UIBlock ' Block type: RGB Color Picker
#Region "Block Styler Dialog Designer generator code"
Public Sub New()
Try
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
theUI = UI.GetUI()
lw = theSession.ListingWindow()
theDialogName = "assign_color.dlx"
theDialog = theUI.CreateDialog(theDialogName)
theDialog.AddApplyHandler(AddressOf apply_cb)
theDialog.AddOkHandler(AddressOf ok_cb)
theDialog.AddUpdateHandler(AddressOf update_cb)
theDialog.AddInitializeHandler(AddressOf initialize_cb)
theDialog.AddDialogShownHandler(AddressOf dialogShown_cb)
Catch ex As Exception
'---- Enter your exception handling code here -----
Throw ex
End Try
End Sub
#End Region
'------------------------------------------------------------------------------
Public Shared Sub Main()
Try
theRGBColorPicker = New RGBColorPicker()
' The following method shows the dialog immediately
theRGBColorPicker.Show()
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
Finally
If theRGBColorPicker IsNot Nothing Then
theRGBColorPicker.Dispose()
End If
End Try
End Sub
'------------------------------------------------------------------------------
Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
End Function
Public Shared Function UnloadLibrary(ByVal arg As String) As Integer
Try
Return 0
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Function
Public Sub Show()
Try
theDialog.Show()
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
Public Sub Dispose()
If theDialog IsNot Nothing Then
theDialog.Dispose()
theDialog = Nothing
End If
End Sub
Public Sub initialize_cb()
Try
group0 = CType(theDialog.TopBlock.FindBlock("group0"), NXOpen.BlockStyler.UIBlock)
rGBColorPicker0 = CType(theDialog.TopBlock.FindBlock("rGBColorPicker0"), NXOpen.BlockStyler.UIBlock)
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
Public Sub dialogShown_cb()
Try
'---- Enter your callback code here -----
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub
Public Function apply_cb() As Integer
Dim errorCode As Integer = 0
Try
'---- Enter your callback code here -----
Catch ex As Exception
'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try
If block Is rGBColorPicker0 Then
Dim pl As PropertyList = rGBColorPicker0.GetProperties()
Dim myColor As Integer = pl.GetInteger("Value")
lw.Open()
lw.WriteLine(" Integer Color: " & myColor.ToString())
lw.WriteLine("Hexadecimal Color: " & Hex(myColor.ToString()))
Dim red As Integer = myColor >> 16 And 255
Dim redh As String = Hex(red)
Dim grn As Integer = (myColor >> 8) And 255
Dim grnh As String = Hex(grn)
Dim blue As Integer = (myColor) And 255
Dim blueh As String = Hex(blue)
lw.WriteLine(" red: " & red.ToString() & " red hex: " & redh)
lw.WriteLine("green: " & grn.ToString() & " green hex: " & grnh)
lw.WriteLine(" blue: " & blue.ToString() & " blue hex: " & blueh)
Dim colorValues(2) As Double
Dim outputColorValues(2) As Double
Dim colorName As String = ""
colorValues(0) = CDbl(red) / 255
colorValues(1) = CDbl(grn) / 255
colorValues(2) = CDbl(blue) / 255
Dim colorNumber As Integer = 0
theUFSession.Disp.AskClosestColor(UFConstants.UF_DISP_rgb_model, colorValues, UFConstants.UF_DISP_CCM_EUCLIDEAN_DISTANCE, colorNumber)
lw.WriteLine("Color Number: " & colorNumber.ToString())
theUFSession.Disp.AskColor(colorNumber, UFConstants.UF_DISP_rgb_model, colorName, outputColorValues)
lw.WriteLine("Color: " & colorName)
lw.WriteLine("============================")
Dim wp As Part = theSession.Parts.Work
' les 4 lignes suivantes permettent de changer la couleur du solide de la primitive courante
'Dim featAsExtrude As Features.Extrude = wp.CurrentFeature
' Dim colorArray() As Integer = {featAsExtrude.GetBodies(0).Color}
'featAsExtrude.GetBodies(0).Color = colorNumber
'featAsExtrude.GetBodies(0).RedisplayObject()
' les lignes suivantes permettent de changer la couleur la primitive courante
Dim Color_markId1 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Départ")
Dim colorFeatureBuilder1 As Features.ColorFeatureBuilder = wp.Features.CreateColorFeatureBuilder()
theSession.SetUndoMarkName(Color_markId1, "Boîte de dialogue Affecter une couleur de face de primitive")
Dim last_feature As Features.Extrude = CType(wp.CurrentFeature, Features.Extrude)
Dim Color_added1 As Boolean = colorFeatureBuilder1.SelectFeature.Add(last_feature)
colorFeatureBuilder1.Color = wp.Colors.Find(colorName)
Dim Color_markId3 As Session.UndoMarkId = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Affecter une couleur de face de primitive")
Dim Color_nXObject1 As NXObject = colorFeatureBuilder1.Commit()
theSession.SetUndoMarkName(Color_markId1, "Affecter une couleur de face de primitive")
colorFeatureBuilder1.Destroy()
End If
Catch ex As Exception
'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
update_cb = 0
End Function
Public Function ok_cb() As Integer
Dim errorCode As Integer = 0
Try
'---- Enter your callback code here -----
errorCode = apply_cb()
Catch ex As Exception
'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
ok_cb = errorCode
End Function
End Class
Regards
Didier Psaltopoulos