AnsweredAssumed Answered

hide multiple component in drawing view

Question asked by Abdul Rauf Aman on Sep 16, 2015


I would like to hide multiple component in selected drawing view. where the hidden components need to be taken from custom property list. For example, I have few part from the same component type need to be hidden from an assembly in the drawing view. Currently I can only find below sample macro. Sample below can only hide 1 component from all drawing view in active sheet.



Const SEARCH_STRING As String = "R-EC96V"

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


End Sub


Could anyone help me out? I'm not good in programming.


Thank you.