Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA VBA Macro to Hide Parts

Status
Not open for further replies.

JV03

Aerospace
Feb 5, 2015
8
0
0
US
In need of some programming help.

I'm trying to create a macro to hide all hardware from an assembly. (i.e. NAS*, SL*, etc.) The problem I am having is that if a sketch within a sub-assy has the hole feature name SLXXX the macro recognizes that as an instance and hides the sketch, therefore hiding the entire sub-assy. Is there any way around this?

Below is the code I have so far.

Sub HideHardware()
'Finding and hiding all hardware
MsgBox ("This Macro will hide all common hardware: SL*, NAS*, MS*, TYE*, AN*, CCR*"), vbOKOnly
Set productDocument1 = CATIA.ActiveDocument
Set Selection1 = productDocument1.Selection
Selection1.Search "Name = NAS*+AN*+MS*+TYE*+SL*+CCR*, sel"

Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
visProperties1.SetShow catVisPropertyNoShowAttr

End Sub

Any help would be much appreciated.
 
Replies continue below

Recommended for you

You can loop the selection and remove the item if it's not a Part.

The following code do the job


Code:
Sub HideHardware()
 'Finding and hiding all hardware
 MsgBox ("This Macro will hide all common hardware: SL*, NAS*, MS*, TYE*, AN*, CCR*"), vbOKOnly
 Set productDocument1 = CATIA.ActiveDocument
 Set Selection1 = productDocument1.Selection
 
 Selection1.Search "Name = NAS*+AN*+MS*+TYE*+SL*+CCR*, sel"
 
 Dim itemInSelection As Integer
 
 itemInSelection = Selection1.Count
 
 U = 1
 
 While U <= itemInSelection

    Set checkItem = Selection1.Item(U).Value
    If TypeName(checkItem) <> "Part" Then
        Selection1.Remove (U)
        itemInSelection = itemInSelection - 1
        U = U - 1
    End If
    U = U + 1

 Wend
 

 Set visProperties1 = CATIA.ActiveDocument.Selection.VisProperties
 visProperties1.SetShow catVisPropertyNoShowAttr

 End Sub

Eric N.
indocti discant et ament meminisse periti
 
faster is to make another search in the selection after the first one

Code:
  Selection1.Search "Name = NAS*+AN*+MS*+TYE*+SL*+CCR*, sel"
Selection1.Search "Type = Part, sel"

Eric N.
indocti discant et ament meminisse periti
 
or in 1 shot

Code:
Selection1.Search "(( Name = NAS*+AN*+MS*+TYE*+SL*+CCR*)&Type = Part), sel"

Eric N.
indocti discant et ament meminisse periti
 
Status
Not open for further replies.
Back
Top