Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the color selected with Block Uistyler

Status
Not open for further replies.

PSI-CAD

Computer
Feb 13, 2009
997
Hi,

I have developped the following Block Styler

Block_UiStyler_2_kvaq6q.jpg


And I try to get the RGB color value to change feature color

Block_UiStyler_j7zjzq.jpg


But I didn't find the syntax at line 15 to put color_value instead of "Red"

Thanks in advance for your help

Regards
Didier Psaltopoulos
 
Replies continue below

Recommended for you

What You receive (values) when You pick a color and click OK? Maybe provide some code, it will be quicker to diagnose problem.

With best regards
Michael
 
Hi,

Thanks in advance for your help: find attached my code and my blockstyler

I have the following error message at line 71

error_message_xui0tb.jpg


Regards
Didier Psaltopoulos
 
The error is "Incorrect property type used for the property name"

the Second line in the error window shows
NXOpen.BlockStyler.PropertyList.GetIntegerVector(String propertyName)

your code at line 71 is
color_value = propList.GetInteger("Value")

at line 18, color_value is defined as Integer

the GetIntegerVector method returns Integer() (array of Integers)

I'm not sure why your code and the error are showing different methods (GetIntegerVector vs GetInteger).
 
DidierPSICAD said:
But I didn't find the syntax at line 15 to put color_value instead of "Red"

Did you try this
Code:
colorFeatureBuilder1.Color = WP.Colors.Find(color_value)

ColorManager.Find_method_Int32_qorfno.png
 
Hi apekas,

Thanks a lot, the link gave me the solution [thumbsup2]

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
 
Thanks for the code, but when I wanna tested it, I receive an error - specified Dlx file not found.

With best regards
Michael
 
Hello,

I have created RGB picker, and I see one huge problem with Your code - last operation in tree must be Extrude, if not, an error occur.

With best regards
Michael
 
OK, Do You use this block styler to color whole body or only single face?

With best regards
Michael
 
Hi,

I don't change the body or face color but the feature color

I apologize: I translate in french the following line in my code

' les lignes suivantes permettent de changer la couleur de la primitive courante

I English we can say:

' the following lines change the color of the current feature





Regards
Didier Psaltopoulos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor