PedroReg
Mechanical
- Oct 1, 2021
- 5
Hi Guys
I have recently understood the power of macros and have been trying to learn a few things.
I work a lot on the GSD, so I tried to create a macro to randomize the surface colors (only the default) that are displayed on my screen.
Unfortunately, I couldn't do that.
Here is the code that I tried:
-----------------------------
Sub CATMain()
Dim vis As Variant
Set objSel = CATIA.ActiveDocument.Selection
objSel.Search "CATGmoSearch.Surface.Color='(243,254,177)',scr"
Dim I As Integer
Dim r As Integer
Dim g As Integer
Dim b As Integer
For I = 1 To objSel.Count
r = I * 5
g = I * 10
b = I * 15
If r > 255 Then
r = r - 255
End If
If g > 255 Then
r = r - 255
End If
If b > 255 Then
r = r - 255
End If
vis = objSel.Item(I).VisProperties
vis.SetRealColor r, g, b, 0
Next I
End Sub
-----------------------------
Here's the following questions that I have:
1. Can I separate the selections I get from my search?
2. Why is " vis = objSel.Item(I).VisProperties " getting an error?
Thanks in advance
I have recently understood the power of macros and have been trying to learn a few things.
I work a lot on the GSD, so I tried to create a macro to randomize the surface colors (only the default) that are displayed on my screen.
Unfortunately, I couldn't do that.
Here is the code that I tried:
-----------------------------
Sub CATMain()
Dim vis As Variant
Set objSel = CATIA.ActiveDocument.Selection
objSel.Search "CATGmoSearch.Surface.Color='(243,254,177)',scr"
Dim I As Integer
Dim r As Integer
Dim g As Integer
Dim b As Integer
For I = 1 To objSel.Count
r = I * 5
g = I * 10
b = I * 15
If r > 255 Then
r = r - 255
End If
If g > 255 Then
r = r - 255
End If
If b > 255 Then
r = r - 255
End If
vis = objSel.Item(I).VisProperties
vis.SetRealColor r, g, b, 0
Next I
End Sub
-----------------------------
Here's the following questions that I have:
1. Can I separate the selections I get from my search?
2. Why is " vis = objSel.Item(I).VisProperties " getting an error?
Thanks in advance