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

Status
Not open for further replies.

ethan22

Industrial
May 24, 2012
3
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
 
Replies continue below

Recommended for you

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:
' ==============================================================
' 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
 
Sorry for the format, it was shock for me to after I post it [mad]

Code:
' ==============================================================
' 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

Regards
Fernando
 
thanks very much that helped out a lot.

:D

Ethan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top