CATIA V5 - Change Element Properties Programmatically
CATIA V5 - Change Element Properties Programmatically
(OP)
I'm a bit new to programming VBA code for CATIA, so please bear with me. I'm creating some code to make circles along a plane via an Excel spreadsheet. As some background, I recorded some macros as a basis for my code and inserted my own programming. Everything works great EXCEPT for the part where I'm trying to change the color of the circles based on their radius.
Could anyone help me get this code working?
Thanks, in advance.
Could anyone help me get this code working?
Thanks, in advance.





RE: CATIA V5 - Change Element Properties Programmatically
Dim selection1 As selection
Set selection1 = partDocument1.selection
selection1.Search "CATPrtSearch.GSMCircleCtrRad.Radius=0.125in,all"
Dim VisPropSet As VisPropertySet
Set VisPropSet = selection1.VisProperties
RedNum = 0
GreenNum = 255
BlueNum = 255
VisPropSet.SetRealColor RedNum, GreenNum, BlueNum, 1
Dim selection2 As selection
Set selection2 = partDocument1.selection
selection2.Search "CATPrtSearch.GSMCircleCtrRad.Radius=0.15625in,all"
Set VisPropSet = selection2.VisProperties
RedNum = 255
GreenNum = 255
BlueNum = 0
VisPropSet.SetRealColor RedNum, GreenNum, BlueNum, 1
Dim selection3 As selection
Set selection3 = partDocument1.selection
selection3.Search "CATPrtSearch.GSMCircleCtrRad.Radius=0.1875in,all"
Set VisPropSet = selection3.VisProperties
RedNum = 255
GreenNum = 0
BlueNum = 0
VisPropSet.SetRealColor RedNum, GreenNum, BlueNum, 1
selection1.Clear
selection2.Clear
selection3.Clear
However, I would like to know how to change the color of the elements during or directly after each element's creation.
RE: CATIA V5 - Change Element Properties Programmatically
Dim VisPropSet As VisPropertySet
Set VisPropSet = SelectedElements.VisPropertySet
to
Dim VisPropSet As VispProperties
Set VisPropSet = SelectedElements.VispProperties
Win XP64
R20/21, 3DVIA Composer 2012, ST R20
Dell T7400 16GB Ram
Quadro FX 4800 - 1.5GB
RE: CATIA V5 - Change Element Properties Programmatically
The VisPropertySet class only seems to work when something is "selected". If I can find a way to "select" the element that was just created, I think I can make it work. I'm just not sure how to reference it.
RE: CATIA V5 - Change Element Properties Programmatically
RE: CATIA V5 - Change Element Properties Programmatically
RE: CATIA V5 - Change Element Properties Programmatically
Something like this (CATScript) ?
Sub CATMain()
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim VisPropSet As VisPropertySet
Dim selection1 As selection
Set selection1 = partDocument1.selection
selection1.Search "CATPrtSearch.GSMCircleCtrRad.Radius=0.125in,all"
If (CATIA.ActiveDocument.Selection.Count) > 0 Then
For i = 1 To CATIA.ActiveDocument.Selection.Count ' For each element...
Set VisPropSet = selection1.VisProperties
RedNum = 0
GreenNum = 255
BlueNum = 255
VisPropSet.SetRealColor RedNum, GreenNum, BlueNum, 1
Next
End If
selection1.Clear
Dim selection2 As selection
Set selection2 = partDocument1.selection
selection2.Search "CATPrtSearch.GSMCircleCtrRad.Radius=0.15625in,all"
If (CATIA.ActiveDocument.Selection.Count) > 0 Then
For i = 1 To CATIA.ActiveDocument.Selection.Count ' For each element...
Set VisPropSet = selection2.VisProperties
RedNum = 255
GreenNum = 255
BlueNum = 0
VisPropSet.SetRealColor RedNum, GreenNum, BlueNum, 1
Next
End If
selection2.Clear
Dim selection3 As selection
Set selection3 = partDocument1.selection
selection3.Search "CATPrtSearch.GSMCircleCtrRad.Radius=0.1875in,all"
If (CATIA.ActiveDocument.Selection.Count) > 0 Then
For i = 1 To CATIA.ActiveDocument.Selection.Count ' For each element...
Set VisPropSet = selection3.VisProperties
RedNum = 255
GreenNum = 0
BlueNum = 0
VisPropSet.SetRealColor RedNum, GreenNum, BlueNum, 1
Next
End If
selection3.Clear
End Sub
Regards
Fernando
RE: CATIA V5 - Change Element Properties Programmatically
The code in my second post works (which is what you have edited)... I'm looking for a fix to the original post code which attempts to change the color of an element during/directly after it is being created.
Example:
- Loop start
- Create element
- Change VisProperty
- Loop
RE: CATIA V5 - Change Element Properties Programmatically
For first code, I didn't look, maybe later if I will have time.
Can you upload some example files ?
Regards
Fernando
RE: CATIA V5 - Change Element Properties Programmatically
My problem wasn't putting something in a loop. What I am trying to figure out is how to change an element's visual properties during/directly after creation rather than by a selection method.
The link in the OP has my code framework with inserted notes. The excel spreadsheet is just a spreadsheet with 4 columns. The first column is for reference numbers. The second contains X coordinates. The third column contains Y coordinates and the fourth contains the diameters.