×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA V5 - Change Element Properties Programmatically

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.

RE: CATIA V5 - Change Element Properties Programmatically

(OP)
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.

RE: CATIA V5 - Change Element Properties Programmatically

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

RE: CATIA V5 - Change Element Properties Programmatically

(OP)
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.

RE: CATIA V5 - Change Element Properties Programmatically

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

RE: CATIA V5 - Change Element Properties Programmatically

(OP)
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.

RE: CATIA V5 - Change Element Properties Programmatically

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
 

RE: CATIA V5 - Change Element Properties Programmatically

(OP)
@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

RE: CATIA V5 - Change Element Properties Programmatically

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
 

RE: CATIA V5 - Change Element Properties Programmatically

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources