Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Background RGB value

Status
Not open for further replies.

LucasC

Automotive
Feb 18, 2019
157
US
The purpose of my code is to switch the screen to a white background then switch back to the users unique background color for multiple users (all with different colors). This is done with a toggle button on a userform.

I'm trying to pass the users current screen RGB through an array, but, I'm getting a type mismatch when using getbackgroundRGB. However, I can get getbackgroundcolor to work but it normalizes the values (sets them to a decimal value between 0 and 1)

What is the type mismatch for getbackgroundRGB? Second, it functions when I use getbackgroundcolor but the value resets to 0 when you un-toggle the userform button. Does this happen because of the toggle? How can I store these values??

Example of the issue; the user starts with a grey background, toggles to white then untoggles to black(instead of grey) since the value is now 0,0,0. It needs to function: users unique color --> white --> users unique color

Thanks in advance


Code:

Private Sub ScreenToggle_Click()

Dim ObjViewer3D
Set ObjViewer3D = CATIA.ActiveWindow.ActiveViewer

Dim BackgroundColorSettingControl
Set BackgroundColorSettingControl = CATIA.SettingControllers

Dim ColorVizSetting
Set ColorVizSetting = BackgroundColorSettingControl.Item("CATVizVisualizationSettingCtrl")

[highlight #8AE234]'I want getbackgroundRGB instead of ...Color...or do it??[/highlight]
Dim BackgroundColor(2)
ObjViewer3D.GetBackgroundColor BackgroundColor

'convert normalized value back to 0-255 scale
Dim UserRed
Dim UserGreen
Dim UserBlue

UserRed = BackgroundColor(0) * 255
UserGreen = BackgroundColor(1) * 255
UserBlue = BackgroundColor(2) * 255


'Test if RGB values are passing through
MsgBox ("Background Color Values are R: ") & BackgroundColor(0) & ", G: " & BackgroundColor(1) & ", B: " & BackgroundColor(2)

'MsgBox ("Background Color Values are R: ") & UserRed & ", G: " & UserGreen & ", B: " & UserBlue

If ScreenToggle.Value = True Then

'set color to white
ColorVizSetting.SetBackgroundRGB 255, 255, 255

ColorVizSetting.SaveRepository

End If

[highlight #8AE234]'Red, Green, Blue values are reset back to 0 here, why??[/highlight]
If ScreenToggle.Value = False Then

Set ObjViewer3D = CATIA.ActiveWindow.ActiveViewer

Set BackgroundColorSettingControl = CATIA.SettingControllers

Set ColorVizSetting = BackgroundColorSettingControl.Item("CATVizVisualizationSettingCtrl")

[highlight #8AE234]'test for values passing[/highlight]
MsgBox ("Background Color Values are R: ") & UserRed & ", G: " & UserGreen & ", B: " & UserBlue

ColorVizSetting.SetBackgroundRGB UserRed, UserGreen, UserBlue

ColorVizSetting.SaveRepository

End If

End Sub
 
Replies continue below

Recommended for you

Sub toggleBGwhite()
Dim ObjViewer3D As INFITF.Viewer3D
Dim dblCurrentArray(2)

ObjViewer3D = MainForm.CATIA.ActiveWindow.ActiveViewer
ObjViewer3D.GetBackgroundColor(dblCurrentArray)

ReDim Preserve MainForm.dblCurrentBGColor(2)
Dim test = MainForm.dblCurrentBGColor(2)

If MainForm.dblCurrentBGColor(0) Is Nothing Then
MainForm.dblCurrentBGColor(0) = 0.2
MainForm.dblCurrentBGColor(1) = 0.2
MainForm.dblCurrentBGColor(2) = 0.4
End If

If Math.Round(dblCurrentArray(0), 2) = 1 And Math.Round(dblCurrentArray(1), 2) = 1 And Math.Round(dblCurrentArray(2), 2) = 1 Then
ObjViewer3D.PutBackgroundColor(MainForm.dblCurrentBGColor)
Else
ReDim MainForm.dblCurrentBGColor(2)
MainForm.dblCurrentBGColor(0) = dblCurrentArray(0)
MainForm.dblCurrentBGColor(1) = dblCurrentArray(1)
MainForm.dblCurrentBGColor(2) = dblCurrentArray(2)

Dim dblWhiteArray(2)
dblWhiteArray(0) = 1
dblWhiteArray(1) = 1
dblWhiteArray(2) = 1

ObjViewer3D.PutBackgroundColor(dblWhiteArray)

End If
End Sub
 
Thanks for the response,

I'm relatively new to VB. what do redim, math.round, and preserve do exactly?
 
So, What I wound up getting to work was getting the users unique CATIA background color RGB(grey, blue, brown, purple, whatever) and changing the toggle button backcolor to that value. This was done in a separate sub when the userform is launched.

The reason for this was, once the toggle button was clicked the first time, it changed the vis setting to white. when the toggle button was clicked a 2nd time to false it ran the code from the beginning. and since the background was now white, it didn't have the original RGB values to switch back to.

Now, when the the toggle was clicked the 2nd time to false, I could retrieve the toggle backcolor value in order to change the CATIA vis setting back to the original color. I had to convert the backcolor value from string of digits, and had to find a bit of code online for that(in red). I think It was hexidecimal

Maybe this is a bit clunky but it works...

Private Sub UserForm_initialize()
[highlight #8AE234]'code runs when userform is launched[/highlight]

Dim ObjViewer3D
Set ObjViewer3D = CATIA.ActiveWindow.ActiveViewer

Dim BackgroundColorSettingControl
Set BackgroundColorSettingControl = CATIA.SettingControllers

Dim ColorVizSetting
Set ColorVizSetting = BackgroundColorSettingControl.Item("CATVizVisualizationSettingCtrl")

Dim BackgroundColor(2)
ObjViewer3D.GetBackgroundColor BackgroundColor

Dim UserRed
Dim UserGreen
Dim UserBlue

UserRed = BackgroundColor(0) * 255
UserGreen = BackgroundColor(1) * 255
UserBlue = BackgroundColor(2) * 255

'Test Color Values
'MsgBox ("Background Color Values are R: ") & UserRedPub & ", G: " & UserGreenPub & ", B: " & UserBluePub

ScreenToggle.BackColor = RGB(UserRed, UserGreen, UserBlue)

End Sub

``````````````````````````````````````````````````````````````````````````````````
```````````````````````````````````````````````````````````````````````````````````
``````````````````````````````````````````````````````````````````````````````````

Private Sub ScreenToggle_Click()

Dim ObjViewer3D
Set ObjViewer3D = CATIA.ActiveWindow.ActiveViewer

Dim BackgroundColorSettingControl
Set BackgroundColorSettingControl = CATIA.SettingControllers

Dim ColorVizSetting
Set ColorVizSetting = BackgroundColorSettingControl.Item("CATVizVisualizationSettingCtrl")

Dim BackgroundColor(2)
ObjViewer3D.GetBackgroundColor BackgroundColor


Dim UserRed
Dim UserGreen
Dim UserBlue

UserRed = BackgroundColor(0) * 255
UserGreen = BackgroundColor(1) * 255
UserBlue = BackgroundColor(2) * 255


[highlight #8AE234]'Test if RGB values are passing through[/highlight]
'MsgBox ("Background Color Values are R: ") & UserRed & ", G: " & UserGreen & ", B: " & UserBlue


If ScreenToggle.Value = True Then

ColorVizSetting.SetBackgroundRGB 255, 255, 255

ColorVizSetting.SaveRepository

End If

If ScreenToggle.Value = False Then

Set ObjViewer3D = CATIA.ActiveWindow.ActiveViewer

Set BackgroundColorSettingControl = CATIA.SettingControllers

Set ColorVizSetting = BackgroundColorSettingControl.Item("CATVizVisualizationSettingCtrl")

[highlight #8AE234]'Test if RGB values are passing through[/highlight]
'MsgBox ("Back Color Values are: ") & ScreenToggle.BackColor

[highlight #EF2929]Dim ConvColor As Long
Dim RGB As String
ConvColor = ScreenToggle.BackColor
R = ConvColor And 255
G = ConvColor \ 256 And 255
B = ConvColor \ 256 ^ 2 And 255[/highlight]

ColorVizSetting.SetBackgroundRGB R, G, B

ColorVizSetting.SaveRepository

End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top