Continue to Site

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!

CATIA V5 - Change Element Properties Programmatically

Status
Not open for further replies.

fatirishman53

Mechanical
Feb 10, 2012
6
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.
 
Replies continue below

Recommended for you

I used this to select the circles with a given radius and change the color of the selection:

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.
 
I think you need to change

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
 
There is no VisProperties class (I think class is what its called), only VisPropertySet and VisualizationSettingAtt.

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.
 
Think the problem is that you use three different selections, if I remember right (been a while since I did some coding) only one is allowed in the code... so you need to clear it after each time you set the visprop
 
The code that I posted directly to the forum works great. It is the code within my original post's link that I'm having problems with. The second post makes a selection based on the circle radii. What I want to do is make color changes to an element directly after or during its creation.
 
Hi,

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
 
@ferdo :
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
 
Of course your code works, what I've done was to edit your second code to work as you said, in a loop (without creating elements, normaly).

For first code, I didn't look, maybe later if I will have time.

Can you upload some example files ?

Regards
Fernando
 
I see. Sorry, I misunderstood what you were trying to convey.

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor