×
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

line width and body color; vb script

line width and body color; vb script

line width and body color; vb script

(OP)
Hello. I guess I will basically asking this to Ferdo, because I'm sure he'll be the first to reply.

I have been to many resources about VBA scripting. Everywhere I go I learn the same thing; about data types and loops. I totally understand this kind of stuff in VBA, but I have no idea where to START with CATIA. I have yet to find a resource that describes what the wording looks like to select say, a body's color property, and how to change it. Or how to open the properties dialog while a part is selected and change a property.

Without the record macro option, there is no way to learn this stuff.

I will ask for a specific example of what I expect to be a dead simple script.

With a CATPart file open with a single body. I wish to select the body with the mouse. Then I wish to hit a button that will run a script (I know how to assign a macro to a button). I want that script to change the color of the body to a light grey, and then change the line width to the thinnest available line width.

I feel like if I SEE this script, I will be able to start figuring out how to make my own. My scripts will likely all be extremely simple like this one, just changing properties in bulk.

That's it.

I would be unendingly greatful for help with this one. Again, I'm asking someone to write this for me, so I can see it and learn some basic CATIA language.

Nick

Light structural commercial aircraft parts
PCDMIS 4.3 CAD++, CATIA V5 R20, NX6
APM Consortium Inc.
Cambridge Ontario, Canada

RE: line width and body color; vb script

Hi,

Bellow CATScript will give you some ideas.

' ==============================================================
' Purpose: 'The goal of this macro is to demonstrate the change of visualization (properties of objects)
' Usage: 1 - A CATProduct must be active, few components in spec tree selected by user
' 2 - Run macro
' Author: ferdo (Disclaimer: You use this code at your own risk)
' ===============================================================

Language="VBSCRIPT"
Sub CATMain()
Dim Selection0 As Selection
Set Selection0 = CATIA.ActiveDocument.Selection

Dim Obj2 As VisProperties
Set Obj2 = Selection0.VisProperties

'''''''''''''''''''''''''''''''''''''''''
sLF = Chr(10)

'input data for RGB code (try for example RGB code=0,0,255 ; r=0 , g=0 , b=255 , objects will be colored in blue )
r = InputBox ("Write red code color here, for example 0 from RGB code 0,0,255" & chr(13) , "RED", r)
g = InputBox ("Write green color here, for example 0 from RGB code 0,0,255"& chr(13) , "GREEN", g)
b= InputBox ("Write blue color here, for example 255 from RGB code 0,0,255" & chr(13) , "BLUE", b)

'''''''''''''''''''''''''''''''''''''''''

Dim visProperties1 As VisProperty
Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties

Dim r, g, b

'Changes the color of all selected
'imposing inheritance

Obj2.SetRealColor r,g,b,1

'Changes the transparency of all the objects to mid-transparency
' (for opacity=128/255) and imposing inheritance

Obj2.SetRealOpacity 255,1

End Sub

Next CATScript is shorter, without inputs, you have to change the RGB code and adapt to CATPart

Language="VBSCRIPT"

Sub CATMain()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 210,210,255,1

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255,1

selection1.Clear

End Sub

If you want you can also do (but changing RGB code to what you want)

Sub CATMain ()

Dim sel1 As Selection
Set sel1= CATIA.ActiveDocument.Selection
sel1.Clear
sel1.Add CATIA.ActiveDocument.Part.MainBody
sel1.VisProperties.SetRealColor 0, 255, 0, 1

End Sub

And there are few other ways to solve what you want smile.

For resources to see how you can programm in CATIA, check this forum for CATIA_Portable_Script_Center. The best resource is anyway v5Automation.chm file in your CATIA installation folder, there you will find all kind of explanations and examples.

Regards
Fernando

https://picasaweb.google.com/102257836106335725208

RE: line width and body color; vb script

(OP)
"v5Automation.chm" huh. Never knew that was there. Looks like it's what I need. Thank you Ferdo, for putting that all together.

Nick

Light structural commercial aircraft parts
PCDMIS 4.3 CAD++, CATIA V5 R20, NX6
APM Consortium Inc.
Cambridge Ontario, Canada

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