AnsweredAssumed Answered

Macro Issue to make a selected Drawing View hidden component Show Hidden Edges

Question asked by Pavlo Palagut on Oct 13, 2018
Latest reply on Oct 13, 2018 by Pavlo Palagut

I am trying to make a macro which will be able to make a selected Drawing View hidden component to show hidden edges (Solidworks Snip below).

I have managed to select the required component "FL-ANSI-10-P-CS-1" with the macro shown below, but my problem is that the line:     "swDrawComp.View.SetDisplayMode3 False, swDisplayMode_e.swHIDDEN_GREYED, True, False"

is equivalent to the click of the "Hidden Lines Visible" in a Solidworks drawing for the whole selected view and not only for one required component "FL-ANSI-10-P-CS-1", which I select with the line:

     "swDrawComp.Select True, Nothing"


Thank you in advance,

I will appreciate any ideas or thoughts...




Option Explicit

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swDraw                      As SldWorks.DrawingDoc

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swSelData                   As SldWorks.SelectData

    Dim swModelDocExt               As SldWorks.ModelDocExtension

    Dim swView                      As SldWorks.View

    Dim swRootDrawComp              As SldWorks.DrawingComponent

    Dim vDrawChildCompArr           As Variant

    Dim vDrawChildComp              As Variant

    Dim swDrawComp                  As SldWorks.DrawingComponent

    Dim swComp                      As SldWorks.Component2

    Dim swCompModel                 As SldWorks.ModelDoc2

    Dim status                      As Boolean

    Dim strCompToShowName           As String


    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

    Set swModelDocExt = swModel.Extension

    Set swSelMgr = swModel.SelectionManager

    Set swSelData = swSelMgr.CreateSelectData


    swDraw.ActivateView ("DrawingTopView")

    status = swModelDocExt.SelectByID2("DrawingTopView", "DRAWINGVIEW", 0.104008832128, 0.1163870710783, 0, False, 0, Nothing, 0)

    Set swView = swSelMgr.GetSelectedObject6(1, -1)

    Set swRootDrawComp = swView.RootDrawingComponent

    vDrawChildCompArr = swRootDrawComp.GetChildren


    For Each vDrawChildComp In vDrawChildCompArr

        Set swDrawComp = vDrawChildComp

        Set swComp = swDrawComp.Component

        strCompToShowName = swComp.Name2


        If strCompToShowName = "FL-ANSI-10-P-CS-1" Then

            swDrawComp.Select True, Nothing

           swDrawComp.View.SetDisplayMode3 False, swDisplayMode_e.swHIDDEN_GREYED, True, False


        End If


End Sub