5 Replies Latest reply on Mar 22, 2018 7:26 PM by Michael Spens

    How to distinguish between vertical and horizontal dimensions?

    William Cruz

      Is there a way in the SolidWorks API to distinguish between a vertical and horizontal dimension?

       

        • Re: How to distinguish between vertical and horizontal dimensions?
          Matthew Cempa

          Try this it uses the direction of the dimension line since I couldn't get anything other than linear dimension from the type2 property:

           

          Dim Part As ModelDoc2
          Dim boolstatus As Boolean
          Dim longstatus As Long, longwarnings As Long
          Dim swSelMgr As SldWorks.SelectionMgr

           

          Sub main()

          Dim swDispDim As SldWorks.DisplayDimension
          Dim swDim As SldWorks.Dimension
          Dim arrData(2) As Double
          Dim hVector As SldWorks.MathVector
          Dim vVector As SldWorks.MathVector

          Dim swMathUtil As SldWorks.MathUtility

           

          Set swApp = Application.SldWorks
          Set Part = swApp.ActiveDoc
          Set swSelMgr = Part.SelectionManager
          Set swMathUtil = swApp.GetMathUtility

           

          arrData(0) = 1: arrData(1) = 0: arrData(2) = 0
          Set hVector = swMathUtil.CreateVector((arrData))

          arrData(0) = 0: arrData(1) = 1: arrData(2) = 0
          Set vVector = swMathUtil.CreateVector((arrData))

           

          Set swDispDim = swSelMgr.GetSelectedObject6(1, -1)

          Select Case swDispDim.Type2
              Case SwConst.swDimensionType_e.swLinearDimension
                  Debug.Print ("Linear Dimension")
                 
                  'try to figure it out using the dimension line direction
                  Set swDim = swDispDim.GetDimension2(0)
                  If swDim.DimensionLineDirection.Dot(hVector) > 0 And swDim.DimensionLineDirection.Dot(vVector) > 0 Then
                      Debug.Print (" ->Neither Horizontal nor Vertical Linear Dimension")
                  ElseIf swDim.DimensionLineDirection.Dot(hVector) > 0 Then
                      Debug.Print (" ->Horizontal Linear Dimension")
                  ElseIf swDim.DimensionLineDirection.Dot(vVector) > 0 Then
                      Debug.Print ("-> Vertical Linear Dimension")
                  End If
                 
              Case SwConst.swDimensionType_e.swHorLinearDimension
                  Debug.Print ("Horizontal Linear Dimension")
                 
              Case SwConst.swDimensionType_e.swVertLinearDimension
                  Debug.Print ("Vertical Linear Dimension")
             
              Case Else
                  Debug.Print ("Dimension type #" & swDispDim.Type2)
          End Select

          End Sub

          • Re: How to distinguish between vertical and horizontal dimensions?
            Jacob Corder

            Yes.

             

            First.

            Get the DisplayDimension

            Dim DispDim as displaydimension

            this can be retrieved many ways. IView.GetFirstDisplayDimension then Loop

            so

            it could also be from a selected object too.

             

            DispDim = ThisView.GetFirstDisplayDimension

            Do Until DispDim is nothing

                 Select case DispDim.Type2

                      Case SwDimensionType_e.swHorLinearDimension

                                Here is a horizontal Dimension

                      case SwDimensionType_e.swVertLinearDimension

                                here is a vertical dim

                      case SwDimensionType_e.SwLinearDimension

                                if you return this type, you have to look at the MathVector for the DimensionLineDirection

                                so.... if that happens let me know. it gets more complex.

                                Dim ThisDim as dimenison

                                ThisDim = dispdim.getdimension2(0)

                                 Dim DimDir() as double

                                dimdir = thisdim.dimensionlineDirection.arraydata

                                so dimdir relates to the direction of the dimension line, not the extension line.

                               

                 End Select

                 dispdim = dispdim.getNext5

            loop

              • Re: How to distinguish between vertical and horizontal dimensions?
                William Cruz

                Thanks for the help. I was able to figure it out using "DimensionLineDirection" that you mention above. See below in C#

                 

                /*USE THIS TO FIGURE OUT IF THE DIM
                                                    IS A HORIZONTAL OR VERTICAL DIM.
                                                    IF tmpDimLineDirection[0] = 1 THEN IT'S A HORIZONTAL DIM
                                                    IF tmpDimLineDirection[1] = 1 THEN IT'S A VERTICAL DIM*/
                                                    Dimension TempDim = dispDim.GetDimension2(0);
                                                    tmpDimLineDirection = (double[])TempDim.DimensionLineDirection.ArrayData;
                
              • Re: How to distinguish between vertical and horizontal dimensions?
                Michael Spens

                Added to cross-reference a new post with information about distinguishing between vertical and horizontal DisplayDimensions on drawings.

                Align drawing dimensions macro

                 

                Mike