5 Replies Latest reply on Apr 26, 2017 5:34 PM by Raghvendra Bhargava

    Show or hide a feture from a feature tree under a drawing view

    Vincent Li

      HI Master shi fu,

       

      I can use the VBA to get the view object of the drawing.

      But I want to Show or hide a feture from a feature tree under a drawing view, then don't know how to get to that feature.

       

      2017-04-25_0-23-28.jpg

       

      regards

      Vincent

        • Re: Show or hide a feture from a feature tree under a drawing view
          Peter Brinkhuis

          When working with drawings, the sheets are the features that you get. You can then do set swSubFeat = swFeat.GetFirstSubFeature to get the drawing views on that sheet. When you have the drawing view, you can once again get the subfeatures of that.

           

          What are you trying to hide though, the origins? Because that's what the View menu at the top is for usually.

          • Re: Show or hide a feture from a feature tree under a drawing view
            Raghvendra Bhargava

            Try this:

             

            Dim swApp As Object

            Dim Part As ModelDoc2

            Dim boolstatus As Boolean

            Dim featureMgr As FeatureManager

            Dim rootNode As TreeControlItem

            Dim swFirstNode As TreeControlItem

            Dim swNode As TreeControlItem

            Dim swChildNode As TreeControlItem

            Dim swFnlChildNode As TreeControlItem

            Dim longstatus As Long, longwarnings As Long

             

            Sub main()

            Set swApp = Application.SldWorks

            Set Part = swApp.ActiveDoc

            Set featureMgr = Part.FeatureManager

            Set rootNode = featureMgr.GetFeatureTreeRootItem2(swFeatMgrPaneTop)

             

            If Not rootNode Is Nothing Then

            Set swNode = rootNode.GetFirstChild

                While Not swNode Is Nothing

                    Set swFirstNode = swNode.GetFirstChild

                    While Not swFirstNode Is Nothing

                        Set swChildNode = swFirstNode.GetFirstChild

                        Set swFnlChildNode = swChildNode.GetFirstChild

                       

                          While Not swFnlChildNode Is Nothing

                                 Dim Obj As Object

                                 Set Obj = swFnlChildNode.Object

                               

                                 If Not Obj Is Nothing Then

                                     Dim feat As Feature

                                     Set feat = Obj

                                     If feat.GetTypeName2 = "CoordSys" Then 'Getting Coordinate System

                                          boolstatus = feat.Select2(False, -1)

                                          Part.UnBlankRefGeom '>>Use for Show

                                         ' Part.BlankRefGeom '>>Use for Hide          

                                     End If

                                 End If                 

                                 Set swFnlChildNode = swFnlChildNode.GetNext

                          

                            Wend

                        Set swFirstNode = swFirstNode.GetNext

                    Wend

                    Set swNode = swNode.GetNext

                Wend

            End If

             

            Part.ForceRebuild3 True

              • Re: Show or hide a feture from a feature tree under a drawing view
                Vincent Li

                thanks man, using the code, it happen a error.

                 

                2017-04-26_0-23-54.jpg

                  • Re: Show or hide a feture from a feature tree under a drawing view
                    Raghvendra Bhargava

                    Hi Li,

                    try this now:

                    Option Explicit

                     

                     

                    Dim swApp As Object

                    Dim Part As ModelDoc2

                    Dim boolstatus As Boolean

                    Dim featureMgr As FeatureManager

                    Dim rootNode As TreeControlItem

                    Dim swFirstNode As TreeControlItem

                    Dim swNode As TreeControlItem

                    Dim swChildNode As TreeControlItem

                    Dim swFnlChildNode As TreeControlItem

                    Dim longstatus As Long, longwarnings As Long

                     

                    Sub main()

                    Set swApp = Application.SldWorks

                    Set Part = swApp.ActiveDoc

                    Set featureMgr = Part.FeatureManager

                    Set rootNode = featureMgr.GetFeatureTreeRootItem2(swFeatMgrPaneTop)

                     

                    If Not rootNode Is Nothing Then

                    Set swNode = rootNode.GetFirstChild

                        While Not swNode Is Nothing

                            Set swFirstNode = swNode.GetFirstChild

                            While Not swFirstNode Is Nothing

                                Set swChildNode = swFirstNode.GetFirstChild

                               

                                While Not swChildNode Is Nothing

                                    Set swFnlChildNode = swChildNode.GetFirstChild

                                   

                                    While Not swFnlChildNode Is Nothing

                                         Dim Obj As Object

                                         Set Obj = swFnlChildNode.Object

                                       

                                         If Not Obj Is Nothing Then

                                             Dim feat As Feature

                                             Set feat = Obj

                                             If feat.GetTypeName2 = "CoordSys" Then 'Getting Coordinate System

                                                 boolstatus = feat.Select2(False, -1)

                                                 Part.UnBlankRefGeom '>Use for Show

                                                 'Part.BlankRefGeom '>Use for Hide

                                             End If

                                         End If

                                         Set swFnlChildNode = swFnlChildNode.GetNext

                                    Wend

                                Set swChildNode = swChildNode.GetNext

                                Wend

                                 Set swFirstNode = swFirstNode.GetNext

                            Wend

                            Set swNode = swNode.GetNext

                        Wend

                    End If

                     

                    Part.ForceRebuild3 True

                    End Sub

                     

                    Let me know if the macro is getting a stop or any other issue you are facing.