×
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 VBA Macro to Hide Parts

CATIA VBA Macro to Hide Parts

CATIA VBA Macro to Hide Parts

(OP)
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.

RE: CATIA VBA Macro to Hide Parts

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

The following code do the job


CODE --> CATVBA

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

RE: CATIA VBA Macro to Hide Parts

faster is to make another search in the selection after the first one

CODE --> CATVBA

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

Eric N.
indocti discant et ament meminisse periti

RE: CATIA VBA Macro to Hide Parts

or in 1 shot

CODE --> CATVBA

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

Eric N.
indocti discant et ament meminisse periti

RE: CATIA VBA Macro to Hide Parts

(OP)
Thanks for your input. Works perfectly.

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