2 Replies Latest reply on Sep 21, 2018 1:12 PM by Niels Raahauge

    Change precision in flatpattern view

    Niels Raahauge

      use of value = instance.SetPrecision2(Primary, Dual, PrimaryTol, DualTol) when swDispDim = swSubFeat.GetNextDisplayDimension(swDispDim)

       

      I want to change all dimension precisions on the flat pattern view..

      something wrong with the instance - I think I am not familiar with the use of the objects.  Can somebody help?

       

       

      '-----------------------------------------------------------------------------------------

      'open a drawing with a flatpattern view: DefaultSM-FLAT-PATTERN
      'Macro find the view name with the flatpattern
      'Scan all dimensions
      'I want to change precision on all the dimensions in the view
      'value = swDispDim.SetPrecision2(1, 1, 1, 1)

      Option Explicit

      Sub main()
          Dim swApp                   As SldWorks.SldWorks
          Dim swModel                 As SldWorks.ModelDoc2
          Dim swFeat                  As SldWorks.Feature
          Dim swSubFeat               As SldWorks.Feature
          Dim swDispDim               As SldWorks.DisplayDimension
          Dim swDim                   As SldWorks.Dimension
          Dim swAnn                   As SldWorks.Annotation
          Dim bRet                    As Boolean
          Dim swDraw As SldWorks.DrawingDoc
          Dim swView As SldWorks.View
          Dim FlatPatternView As String
         
          Dim instance As IDisplayDimension
          Dim value As Integer
         
          Set swApp = CreateObject("SldWorks.Application")
          Set swModel = swApp.ActiveDoc
          Set swFeat = swModel.FirstFeature
          Set swDraw = swModel

      '---find flat pattern view
         Set swView = swDraw.GetFirstView
          ' Get first drawing view in first sheet
          Set swView = swView.GetNextView
          Do While Not swView Is Nothing
              If swView.ReferencedConfiguration = "DefaultSM-FLAT-PATTERN" Then
              Debug.Print "Flat patternview:  " & swView.Name
              FlatPatternView = swView.Name
              End If
              Set swView = swView.GetNextView
          Loop
      '---

          Do While Not swFeat Is Nothing
         
              Set swSubFeat = swFeat.GetFirstSubFeature
              Do While Not swSubFeat Is Nothing

      If swSubFeat.Name = FlatPatternView Then

                  Set swDispDim = swSubFeat.GetFirstDisplayDimension

                  Do While Not swDispDim Is Nothing
                      Set swAnn = swDispDim.GetAnnotation
                      Set swDim = swDispDim.GetDimension
                      Debug.Print "          [" & swDim.FullName & "] = " & swDim.GetSystemValue2("")
                      ' FAULT presisition are not set ?
                       value = swDispDim.SetPrecision2(1, 1, 1, 1)
                      'value = instance.SetPrecision2(Primary, Dual, PrimaryTol, DualTol)
                       Set swDispDim = swSubFeat.GetNextDisplayDimension(swDispDim)
                  Loop
      End
      End If
                  Set swSubFeat = swSubFeat.GetNextSubFeature
              Loop
             
              Set swDispDim = swFeat.GetFirstDisplayDimension
              Do While Not swDispDim Is Nothing

                  Set swAnn = swDispDim.GetAnnotation
                  Set swDim = swDispDim.GetDimension
                  Debug.Print "    [" & swDim.FullName & "] = " & swDim.GetSystemValue2("")
                  Set swDispDim = swFeat.GetNextDisplayDimension(swDispDim)
      instance = swDim

              Loop
             
              Set swFeat = swFeat.GetNextFeature

          Loop

      End Sub

        • Re: Change precision in flatpattern view
          Fifi Riri

          Hello,

          It might be because you skip the view with the GetNextView just after the GetFirstView

          Try this:

           

          Option Explicit

          Sub main()

              Dim swApp As SldWorks.SldWorks

              Dim swDispDim As SldWorks.DisplayDimension

              Dim swDim As SldWorks.Dimension

              Dim swDraw As SldWorks.DrawingDoc

              Dim swView As SldWorks.View

              Set swApp = Application.SldWorks

              Set swDraw = swApp.ActiveDoc

              Set swView = swDraw.GetFirstView

              Do While Not swView Is Nothing

                  If swView.IsFlatPatternView Then

                      Debug.Print "Flat patternview:  " & swView.Name

                      Set swDispDim = swView.GetFirstDisplayDimension

                      While Not swDispDim Is Nothing

                          Set swDim = swDispDim.GetDimension

                          Debug.Print "   [" & swDim.FullName & "] = " & swDim.GetSystemValue2("")

                          swDispDim.SetPrecision3 1, 1, 1, 1

                          Set swDispDim = swDispDim.GetNext

                      Wend

                      Exit Do 'assuming there is only one flat pattern view

                  End If

                  Set swView = swView.GetNextView

              Loop

          End Sub

          • Re: Change precision in flatpattern view
            Niels Raahauge

            So near Thank you Fifi Riri