3 Replies Latest reply on Jan 21, 2015 5:25 PM by Yong Ning

    How to hide dimension?

    Yong Ning

      ***********************

      Follow Code key Point0.jpg

      Set SwDim = .Parameter(Ss)

      My question

        How to Hide dimension → SwDim → Hide Dimension

       

      Thanks.

       

      ************************

      Sub ll1()

        Dim Arr(7)

          Arr(0) = "PipeTHK@FlangeSketch@ee.Part"

          'Arr(1) = "D@FlangeSketch@ee.Part"

          Arr(2) = "Fd@FlangeSketch@ee.Part"

          Arr(3) = "A1AB@FlangeSketch@ee.Part"

          Arr(4) = "NAB@FlangeSketch@ee.Part"

          Arr(5) = "L@CutHoleSketch@ee.Part"

          'Arr(6) = "K@CutHoleSketch@ee.Part"

          Arr(7) = "D1@Alfa基准面@ee.Part"

          ''

        Dim ii, jj

        Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc, SwModel As ModelDoc2

       

        Set SwApp = Application.SldWorks

        Set SwDraw = SwApp.ActiveDoc

        Dim vSheets, SwSheet As Sheet, SwView As View, SwDim As Dimension

        Dim Ss

       

        With SwDraw

          vSheets = .GetSheetNames

          For ii = 0 To 0 'UBound(vSheets)

            .ActivateSheet vSheets(ii)

            Set SwSheet = .GetCurrentSheet

            For jj = 0 To UBound(Arr)

              If Not IsEmpty(Arr(jj)) Then

                Set SwDim = .Parameter(Arr(jj))

                Debug.Print jj, "Need Hide → ", SwDim.FullName

              End If

            Next jj

          Next ii

        End With

       

      End Sub

       

      ***********************

      Result is

      0            Need Hide →  PipeTHK@FlangeSketch@ee.Part

      2            Need Hide →  Fd@FlangeSketch@ee.Part

      3            Need Hide →  A1AB@FlangeSketch@ee.Part

      4            Need Hide →  NAB@FlangeSketch@ee.Part

      5            Need Hide →  L@CutHoleSketch@ee.Part

      7            Need Hide →  D1@Alfa基准面@ee.Part

        • Re: How to hide dimension?
          Simon Turner

          You actually need to access the DisplayDimension object rather than Dimension.

          Something like this:

           

          boolstatus = swModel.Extension.SelectByID2("PipeTHK@FlangeSketch@ee-1@Drawing View1", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

          swModel.HideDimension

          swModel.ClearSelection2 True

            • Re: How to hide dimension?
              Yong Ning

              Thanks your tips

              *************************

              SwDraw.Extension.SelectByID2→Select Dimension to  Highlight → Hide dimension → don't show dimension.

               

              Hope Set Swdim function → hide dimension → return Show dimension.

               

              *************************

              Sub ll1()

                Dim Arr(7)

                  Arr(0) = "PipeTHK@FlangeSketch"

                  'Arr(1) = "D@FlangeSketch"

                  Arr(2) = "Fd@FlangeSketch"

                  Arr(3) = "A1AB@FlangeSketch"

                  Arr(4) = "NAB@FlangeSketch"

                  Arr(5) = "L@CutHoleSketch"

                  'Arr(6) = "K@CutHoleSketch"

                  Arr(7) = "D1@Alfa基准面"

                  ''

                Dim ii, jj

                Dim SwApp As SldWorks.SldWorks, SwDraw As DrawingDoc, SwModel As ModelDoc2

               

                Set SwApp = Application.SldWorks

                Set SwDraw = SwApp.ActiveDoc

               

                Dim vSheets, SwSheet As Sheet, SwView As View, SwDim As Dimension

                Dim Str As String, tmp

               

                With SwDraw

                 

                  vSheets = .GetSheetNames

                  For ii = 0 To 0 'UBound(vSheets)

                    .ActivateSheet vSheets(ii)

                    Set SwSheet = .GetCurrentSheet

                    For jj = 0 To UBound(Arr)

                      If Not IsEmpty(Arr(jj)) Then

                        Set SwDim = .Parameter(Arr(jj))

                       

                        Str = Arr(jj) & "@" & .GetTitle & "@v1"

                        Debug.Print Str

                        tmp = SwDraw.Extension.SelectByID2(Str, "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)

                        .HideDimension

                      End If

                    Next jj

                  Next ii

                End With

                

              End Sub

                • Re: How to hide dimension?
                  Yong Ning

                  ''

                  ''

                  Private Sub del20150119()

                     ''

                     Dim Xls As Excel.Application, Rng As Range

                        Set Xls = GetObject(, "Excel.Application")

                        Set Rng = Xls.Selection

                        Set Rng = Rng.CurrentRegion

                     Dim RegExp As New RegExp, Str As String

                       

                        For ii = 1 To Rng.Rows.Count

                           Str = Str & Rng(ii, 1) & "|"

                        Next ii

                        RegExp.Pattern = Left(Str, Len(Str) - 1)

                       

                     ''

                     Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                        Set SwApp = Application.SldWorks

                        Set SwModel = SwApp.ActiveDoc

                     Dim SwSelMgr As SelectionMgr, SwLayerMgr As LayerMgr

                        Set SwSelMgr = SwModel.SelectionManager

                        Set SwLayerMgr = SwModel.GetLayerManager

                        SwLayerMgr.SetCurrentLayer "尺寸线"

                     Dim SwDraw As DrawingDoc, vSheet, SwView As View

                        Set SwDraw = SwModel

                        vSheet = SwDraw.GetSheetNames

                        For ii = 0 To UBound(vSheet)

                           SwDraw.ActivateSheet vSheet(ii)

                          

                           Set SwView = SwDraw.GetFirstView

                           Set SwView = SwView.GetNextView

                           Do While Not SwView Is Nothing

                                 RegExpDelDim SwModel, SwView, RegExp

                                 Set SwView = SwView.GetNextView

                           Loop

                        Next ii

                       

                  End Sub

                  ''

                  Function RegExpDelDim(SwModel As ModelDoc2, SwView As View, RegExp As RegExp)

                     Dim SwDispDim As DisplayDimension, SwDim As Dimension, SwAnn As Annotation

                        Set SwDispDim = SwView.GetFirstDisplayDimension

                        Do While Not SwDispDim Is Nothing

                           Set SwDim = SwDispDim.GetDimension

                           'Debug.Print SwDim.FullName

                           If RegExp.Test(SwDim.FullName) = False Then

                              Set SwAnn = SwDispDim.GetAnnotation

                              SwAnn.Select True

                           End If

                           Set SwDispDim = SwDispDim.GetNext

                        Loop

                        SwModel.EditDelete

                       

                  End Function