3 Replies Latest reply on Sep 27, 2018 11:33 AM by Lars Ahlzen

    3D dimension position Array (Drawing)

    Lars Ahlzen

      Hello Hello

       

      I am trying to create a 3D array that holds first which drawing view, second which dimensional annotation and third the (x, y, z) - coordinates for that annotation. I have to loop together this somehow since it is supposed to work for different drawings. I usually make 2D arrays like this (look down below) when I want, for example, an array with all the dimensional annotations and their coordinates from a predetermined view.

       

      2D Array

      Set swView = vViews(1)

      vDimensions = swView.GetAnnotations

      nrDim = swView.GetAnnotationCount

      ReDim allDimPos(0 To nrDim) As Variant

       

      If Not IsEmpty(vDimensions) Then

           For k = LBound(vDimensions) To UBound(vDimensions)

                Set currDim = vDimensions(k)

                DimPos = currDim.GetPosition

                d = Array(DimPos(0), DimPos(1), DimPos(2))

                allDimPos(k) = d

                For e = 0 To 2

                     'Debug.Print allDimPos(k)(e)

                Next

           Next

      End If

       

      But now I also have to include the view. To make a long story short I want this so I can make small changes to the position when running through configurations. The AlignDimensions(swAlignDimensionType_e.swAlignDimensionType_AutoArrange, 0.01) command does not produce the exact result I want. It still gets a little bit weird when I change configurations. I already have a script that aligns them good enough as long as I can get this array to work

       

      This is what I have so far:

      3D Array

       

      For i = 0 To UBound(vViews)                                                                        'maybe (1 To UBound(vViews))

           Set swView = vViews(i)

           vDimensions = swView.GetAnnotations

           nrDim = swView.GetAnnotationCount

           ReDim allDimPos(0 To nrView, 0 To nrDim) As Variant                          'Maybe  ReDim allDimPos(nrView, nrDim) As Variant

           allDimPos(i) = vDimensions

           For k = LBound(vDimensions) To UBound(vDimensions)         

                     ReDim allDimPos(0 To nrView, 0 To nrDim, 0 To 2) As Variant     ' Maybe ReDim allDimPos(nrView, nrDim, 2) As Variant

                     Set currDim = vDimensions(k)

                     DimPos = currDim.GetPosition

                     d = Array(DimPos(0), DimPos(1), DimPos(2))

                     allDimPos(i)(k) = d

                     For e = 0 To 2

                          Debug.Print allDimPos(i)(k)(e)

                     Next

             Next

      Next

       

      Usually get "Out of range error" at allDimPos(i) = vDimensions

       

      Any help is goood because I got tunnel vision now. Appreciate all the help I get and all the help I have gotten in the past

        • Re: 3D dimension position Array (Drawing)
          Lars Ahlzen

          Slept on it, decided to make two 2D arrays instead. One with all the X- coordinates and one with all the Y coordinates (one can make a third with all the z coordinates but since it is always zero it doesn't matter). So for every view all the Xpositions for every annotation is stored... If any one wanted to know or use this somehow in the future.

           

           

          Dim XDimension As Variant

          Dim YDimension As Variant

           

          nrView = swDrawing.GetViewCount

          ReDim allPos(0 To nrView) As Variant

          ReDim allOutline(0 To nrView) As Variant

          ReDim allScale(0 To nrView) As Variant

          ReDim XDimension(0 To nrView) As Variant

          ReDim YDimension(0 To nrView) As Variant

           

          Dim currDim As SldWorks.Annotation

          Dim DimName As String

          Dim DimPos As Variant

          Dim vDimensions As Variant

          Dim nrDim As Integer

          Dim DimensionX As Variant

          Dim DimensionY As Variant

           

          'Get all X and Y coordinates for all annotations in every view for the first config

          For i = 0 To UBound(vViews)

           

               'Sets all the first iterations to empty (zero) arrays, because sheet view is first view

               Set swView = vViews(i)

               If i = 0 Then

                    X = Array(0)

                    XDimension(i) = X

                    y = Array(0)

                    YDimension(i) = y

           

               'Sets all other views to X coordinates and Y coordinates arrays

               Else

                    vDimensions = swView.GetAnnotations

                    nrDim = swView.GetAnnotationCount

                    ReDim DimensionX(nrDim) As Variant

                    ReDim DimensionY(nrDim) As Variant

           

                    For k = LBound(vDimensions) To UBound(vDimensions)

                         Set currDim = vDimensions(k)

                         DimPos = currDim.GetPosition

                         DimensionX(k) = DimPos(0)

                         DimensionY(k) = DimPos(1)

                    Next

           

                    XDimension(i) = DimensionX

                    YDimension(i) = DimensionY

               End If

          Next