×
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 Macro Help

CATIA Macro Help

CATIA Macro Help

(OP)
Hello Everyone,

Ok so im trying to wright a Macro for Catia that reads in user in put from a multi-selection, the problem is how do you wright a comand prompt for multi selection for vba code in catia.

This is what i have so far.

Private Sub Black_Click()

Dim productDocument1 As Document
Set productDocument1 = CATIA.ActiveDocument

Dim selection1 As Selection
Set selection1 = productDocument1.Selection

selection1.Search "CATPrtSearch.MechanicalFeature,all"
Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 51, 51, 51, 1
Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255, 1
selection1.Clear
selection1.Search "CATAsmSearch.Part,all"
Set visPropertySet1 = selection1.VisProperties
visPropertySet1.SetRealColor 51, 51, 51, 1
Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetRealOpacity 255, 1
selection1.Clear
Dim specsAndGeomWindow1 As Window
Set specsAndGeomWindow1 = CATIA.ActiveWindow
Dim viewer3D1 As Viewer
Set viewer3D1 = specsAndGeomWindow1.ActiveViewer
viewer3D1.Reframe
Dim viewpoint3D1 As Viewpoint3D
Set viewpoint3D1 = viewer3D1.Viewpoint3D
End Sub

This coad is linked to GUI interface for each color there is a buton this one happens to be black.

What i want to do, is before the program runs have the user select the part bodie's that they want the color to be changed and then for the program to read that input and only change thoes bodies, right now this program changes every body in the part. I also want the user to beable to slect more than just one body hence Multi-Select.

Thanks
Ethan

RE: CATIA Macro Help

Hi,

You need first to tell the user to create the selection (put a message box with option to continue or not for example) then code will be something like bellow

CODE --> CATScript

' ============================================================== ' 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" & chr(13) , "RED number from RGB code", r) g = InputBox ("Write green code color here"& chr(13) , "GREEN number from RGB code", g) b= InputBox ("Write blue code color here" & chr(13) , "BLUE number from RGB code", 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

Regards
Fernando

RE: CATIA Macro Help

Sorry for the format, it was shock for me to after I post it [mad]

[code CATscript]
' ==============================================================
' 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" & chr(13) , "RED", r)
g = InputBox ("Write green color here"& chr(13) , "GREEN", g)
b= InputBox ("Write blue color here" & 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
[/code]

Regards
Fernando

RE: CATIA Macro Help

(OP)
thanks very much that helped out a lot.

:D

Ethan

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