2 Replies Latest reply on Sep 27, 2018 4:31 PM by Lars Ahlzen

    Vertical or Horizontal linear dimensions, can the API get this? (drawing).

    Lars Ahlzen

      Hi

       

      Well, it seems I have yet another problem that needs assistance. So I am trying to figure out how the API can know if a drawing dimension is vertical or horizontal.

      Like the picture:

      VERTorHorizont.JPG

       

       

       

       

       

       

       

       

       

       

       

       

      I have taken some advice from this API help script http://help.solidworks.com/2019/english/api/swdimxpertapi/get_dimxpert_display_dimensions_and_feature_example_vb.htm and this thread Horizontal or Vertical Dimension?

       

      What I thought would work is this:

       

      Dim DisplayDim As SldWorks.DisplayDimension

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

           Set currDim = vDimensions(i)

           Set DisplayDim = currDim.GetSpecificAnnotation

           DimName = currDim.GetName

       

           Select Case (DisplayDim.Type2)

                Case swDimensionType_e.swLinearDimension

                Debug.Print DimName & "  Display dimension type = linear"

       

                Case swDimensionType_e.swHorLinearDimension

                Debug.Print DimName & "  Display dimension type = horizontal linear"

       

                Case swDimensionType_e.swVertLinearDimension

                Debug.Print DimName & "  Display dimension type = vertical linear"

       

           Case Else

                Debug.Print DimName & "  Display dimension type = unknown"

           End Select

      Next

       

      But even though I am intentionally putting in a vertical dimension and a horizontal dimension instead of using the smart dimension tool it returns as only linear. Maybe the drawing environment doesn't know if it is vertical or horizontal and just use linear all the time compared to the part environment that is more specific when it comes to linear dimensions. Maybe?

       

      I have also tried to find the arrows positions to see if the x values of both the arrows are the same (then it is vertical) or the y values are the same (then it is horizontal). But I guess you can't get those coordinates... If anybody else has any smart solution to this I am all ears.

       

      P.S If anybody has seen my previous posts I can tell you that I am still working on the same script and it is getting quite good wiyh the help I have gotten from the community, so thank you for that.

        • Re: Vertical or Horizontal linear dimensions, can the API get this? (drawing).
          Lars Ahlzen

          Maybe somebody knows a way to get the coordinates of either the arrows or the dimension line (2 sets of coordinates)? that would probably work

          • Re: Vertical or Horizontal linear dimensions, can the API get this? (drawing).
            Lars Ahlzen

            Probably took me way to long to find these commands but I finally got it..

             

            Dim vDimensions As Variant

            vDimensions = swView.GetAnnotations

             

            Dim currDim As SldWorks.Annotation

            Dim DisplayData As SldWorks.DisplayData

            Dim ArrowHeadPos As Variant

            Dim ArrowHeadDir As Variant

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

                 Set currDim = vDimensions(i)

                 Set DisplayData = currDim.GetDisplayData

                 ArrowHeadPos = DisplayData.GetArrowHeadAtIndex2(0)

                 ArrowHeadDir = DisplayData.GetArrowHeadAtIndex2(1)

                 Debug.Print "AH pos X =  " & ArrowHeadPos(0) & "  AH dir X = " & ArrowHeadDir(0)

                 Debug.Print "AH pos Y =  " & ArrowHeadPos(1) & "  AH dir Y = " & ArrowHeadDir(1)

            Next

             

            Output:

            AH tip X =  6.10563121398763E-02  AH dir X = 6.10563121398763E-02

            AH tip Y =  0.139419233527157  AH dir Y = 9.49692335271574E-02

            the vertical one

             

            AH tip X =  0.100855106760877  AH dir X = 0.202455106760877

            AH tip Y =  7.29692335271573E-02  AH dir Y = 7.29692335271573E-02

            the horizontal one