Files
Search for and hide components in drawing views
Code
'Demonstrates how to traverse all drawing views in a drawing and hide components with a _
specified string in the name
'Preconditions: drawing is open
'Results: components with names containing the search string are hidden
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
Const SEARCH_STRING As String = "block"
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim vSheetViews As Variant
Dim vViews As Variant
Dim swDrawComp As SldWorks.DrawingComponent
Dim vDrawComps As Variant
Dim i As Integer
Dim j As Integer
Dim k As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
vSheetViews = swDraw.GetViews
For i = 0 To UBound(vSheetViews)
vViews = vSheetViews(i)
For j = 0 To UBound(vViews)
Set swView = vViews(j)
Set swDrawComp = swView.RootDrawingComponent
If Not swDrawComp Is Nothing Then
vDrawComps = swDrawComp.GetChildren
If IsEmpty(vDrawComps) = False Then
For k = 0 To UBound(vDrawComps)
Set swDrawComp = vDrawComps(k)
If InStr(1, swDrawComp.Name, SEARCH_STRING) <> 0 Then swDrawComp.Visible = False
Next k
End If
End If
Next j
Next i
swModel.EditRebuild3
End Sub