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
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
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
Regards
Fernando
RE: CATIA Macro Help
[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
:D
Ethan