7 Replies Latest reply on Jul 2, 2017 5:51 AM by Yong Ning

    How to determine the vertical size, or horizontal size.

    Yong Ning

      2GetAttachedEntities2.jpg

      follow code, don't determine oriate.

       

      Private Sub ll1()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

             Set SwApp = Application.SldWorks

             Set SwModel = SwApp.ActiveDoc

         Dim SwSelMgr As SelectionMgr

             Set SwSelMgr = SwModel.SelectionManager

         Dim SwDispDim As DisplayDimension, SwDim As Dimension

         Dim SwAnn As Annotation

             Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

             With SwDispDim

                 Debug.Print .VerticalJustification, .HorizontalJustification

                 Set SwDim = .GetDimension

                 Set SwAnn = .GetAnnotation

                 Set Ss = SwDim.ExtensionLineDirection

             End With

             SwModel.ForceRebuild3 True

      End Sub

       

       

       

       

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

      Get Display Dimension Type - API | SOLIDWORKS Forums  https://forum.solidworks.com/message/317119#comment-317119

        • Re: How to determine the vertical size, or horizontal size.
          Viktor Bovzdarenko

          Hi Yong,

          VerticalJustification and HorizontalJustification are related to text inside the dimension. These properties do not tell if the dimension is horizontal or vertical.

          Try to use: value = IDisplayDimension.Type2

          the value will give more info about the dimension itself.

           

          swDimensionType_e

           

          swHorLinearDimension11 = Horizontal linear dimension
          swHorOrdinateDimension7 = Horizontal ordinate dimension
          swLinearDimension2 = Linear dimension type
          swOrdinateDimension1 = Base ordinate and its subordinates are of this type
          swRadialDimension5 = Radial dimension
          swScalarDimension13
          swVertLinearDimension12 = Vertical linear dimension

           

          Regards

          Viktor

            • Re: How to determine the vertical size, or horizontal size.
              Yong Ning

              Thank your replay post.

              in Smart Dimenstin,  Type2 is 2

               

              Dim.jpg

               

               

               

              Private Sub ll1()

                 Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                     Set SwApp = Application.SldWorks

                     Set SwModel = SwApp.ActiveDoc

                 Dim SwSelMgr As SelectionMgr

                     Set SwSelMgr = SwModel.SelectionManager

                 Dim SwDispDim As DisplayDimension, SwDim As Dimension

                 Dim SwAnn As Annotation, SwLine As SketchLine, Sw As SketchSegment

                     Set SwDispDim = SwSelMgr.GetSelectedObject5(1)

                     With SwDispDim

                         Debug.Print .Type2  ' → result is 2

                     End With

                     SwModel.ForceRebuild3 True

              End Sub

                • Re: How to determine the vertical size, or horizontal size.
                  Viktor Bovzdarenko

                  Hi Yong,

                  then maybe you can try to get the vector for dimension? see the example:

                   

                  Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                  Sub main()

                      Set SwApp = Application.SldWorks

                      Set SwModel = SwApp.ActiveDoc

                      Dim SwDispDim As DisplayDimension: Set SwDispDim = SwModel.SelectionManager.GetSelectedObject5(1)

                      Dim SwDim As Dimension: Set SwDim = SwDispDim.GetDimension2(0)

                      Dim SwDimVector As MathVector: Set SwDimVector = SwDim.DimensionLineDirection

                      Debug.Print SwDimVector.ArrayData(0) & " : " & SwDimVector.ArrayData(1) & " : " & SwDimVector.ArrayData(2)

                  End Sub

                   

                  For horizontal dimension I got: X = 1 Y = 0 Z = 0

                  vertical : X = 0 Y = 1 Z = 0

                    • Re: How to determine the vertical size, or horizontal size.
                      Yong Ning

                      Thank you reply, with the DimensionLineDirection method, to determine the direction

                       

                       

                      Function DimLineDirect(SwDispDim As DisplayDimension)

                          Dim SwDim As Dimension

                               Set SwDim = SwDispDim.GetDimension

                               Dim SwDimVector As MathVector

                               Set SwDimVector = SwDim.DimensionLineDirection

                               Debug.Print SwDim.FullName, SwDim.Value

                               Debug.Print "    Manipulating MathVector → " & _

                                SwDimVector.ArrayData(0) & " : " & SwDimVector.ArrayData(1) & " : " & SwDimVector.ArrayData(2)

                      End Function

                       

                      Private Sub ll()

                           Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                               Set SwApp = Application.SldWorks

                               Set SwModel = SwApp.ActiveDoc

                           Dim SwDraw As DrawingDoc

                               Set SwDraw = SwModel

                           Dim SwView As View, SwDispDim As DisplayDimension

                               Set SwView = SwDraw.GetFirstView

                               Do While Not SwView Is Nothing

                                   Set SwDispDim = SwView.GetFirstDisplayDimension

                                   Do While Not SwDispDim Is Nothing

                                       Debug.Print SwView.Name,

                                       DimLineDirect SwDispDim

                                       Set SwDispDim = SwDispDim.GetNext

                                   Loop

                                   Set SwView = SwView.GetNextView

                               Loop

                      End Sub

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

                      Result is

                      鞍座F主视图   Delta4@Sketch@垫板.Part      8

                          Manipulating MathVector → .902678611255778 : -.430315378276608 : 0

                      鞍座F主视图   D1@h@鞍座F.Assembly          200

                          Manipulating MathVector → 0 : -1 : 0

                      鞍座F主视图   ArcLen@Sketch@垫板.Part      1180

                          Manipulating MathVector → 0 : 0 : 0

                      鞍座F主视图   ShellR@Sketch@垫板.Part      524

                          Manipulating MathVector → 0 : 0 : 0

                      鞍座F左视图   D1@b4@垫板.Part              350

                          Manipulating MathVector → 0 : 0 : 1

                      鞍座F左视图   D1@e@垫板.Part               70

                          Manipulating MathVector → 0 : 0 : -1

                      Section View A2-A2          l1@Sketch@底板F.Part         760

                          Manipulating MathVector → 1 : 0 : -3.65204942310907E-17

                      Section View A2-A2          b1@Sketch@底板F.Part         170

                          Manipulating MathVector → 0 : 0 : 1

                      Section View A2-A2          cutD@Sketch@底板F.Part       24

                          Manipulating MathVector → 0 : 0 : 0

                      Section View A2-A2          l2@Sketch@底板F.Part         600

                          Manipulating MathVector → -1 : 0 : 0

                       

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

                      2012 SOLIDWORKS API Help - Get Extension Line Direction Example (VBA)  http://help.solidworks.com/2012/english/api/sldworksapi/get_extension_line_direction_example_vb.htm

                       

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

                       

                      Dim SwApp                   As SldWorks.SldWorks

                      Dim SwModel                 As SldWorks.ModelDoc2

                      Dim SwDraw                  As SldWorks.DrawingDoc

                      Dim SwView                  As SldWorks.View

                      Dim SwDispDim               As SldWorks.DisplayDimension

                      Dim SwDim                   As SldWorks.Dimension

                      Dim SwAnn                   As SldWorks.Annotation

                      Dim swDisplayDimension      As SldWorks.DisplayDimension

                       

                      Sub main()

                          Set SwApp = Application.SldWorks

                          Set SwModel = SwApp.ActiveDoc

                          Set SwDraw = SwModel

                          Set SwView = SwDraw.GetFirstView

                          While Not SwView Is Nothing

                              Set SwAnn = SwView.GetFirstAnnotation3

                              While Not SwAnn Is Nothing

                                  Debug.Print " "

                                  Debug.Print "Annotation name = " & SwAnn.GetName

                                  If SwAnn.GetType = swAnnotationType_e.swDisplayDimension Then

                                      Debug.Print "  Is a display dimension? True"

                                      Set swDisplayDimension = SwAnn.GetSpecificAnnotation

                                      Select Case (swDisplayDimension.Type2)

                                         Case swDimensionType_e.swOrdinateDimension

                      Debug.Print "  Display dimension type = " & GetOrientation(swDisplayDimension) & " ordinate and its subordinates"

                                         Case swDimensionType_e.swLinearDimension

                      Debug.Print "  Display dimension type = " & GetOrientation(swDisplayDimension) & " linear"

                                         Case swDimensionType_e.swAngularDimension

                      Debug.Print "  Display dimension type  = angular"

                                         Case swDimensionType_e.swArcLengthDimension

                      Debug.Print "  Display dimension type = arc length"

                                         Case swDimensionType_e.swRadialDimension

                      Debug.Print "  Display dimension type = radial"

                                         Case swDimensionType_e.swDiameterDimension

                      Debug.Print "  Display dimension type = diameter"

                                         Case swDimensionType_e.swHorOrdinateDimension

                      Debug.Print "  Display dimension type = horizontal ordinate"

                                         Case swDimensionType_e.swVertOrdinateDimension

                      Debug.Print "  Display dimension type = vertical ordinate"

                                         Case swDimensionType_e.swZAxisDimension

                      Debug.Print "  Display dimension type = z-axis"

                                         Case swDimensionType_e.swChamferDimension

                      Debug.Print "  Display dimension type = chamfer dimension"

                                         Case swDimensionType_e.swHorLinearDimension

                      Debug.Print "  Display dimension type = horizontal linear"

                                         Case swDimensionType_e.swVertLinearDimension

                      Debug.Print "  Display dimension type = vertical linear"

                                         Case swDimensionType_e.swScalarDimension

                      Debug.Print "  Display dimension type = scalar"

                                         Case Else

                      Debug.Print "  Display dimension type = unknown"

                                      End Select

                                  End If

                                  Set SwAnn = SwAnn.GetNext3

                              Wend

                              Set SwView = SwView.GetNextView

                          Wend

                      End Sub

                       

                      Function GetOrientation(swDisplayDimension As DisplayDimension) As String

                          Dim SwDim As SldWorks.Dimension

                          Set SwDim = swDisplayDimension.GetDimension '2(0)

                          Dim swMathVec As SldWorks.MathVector

                          Dim vDir As Variant

                       

                          GetOrientation = ""

                       

                          Set swMathVec = SwDim.DimensionLineDirection

                          vDir = swMathVec.ArrayData

                       

                          If IsCollinear(vDir(0), 1) And IsCollinear(vDir(1), 0) Then

                              GetOrientation = "horizontal"

                          ElseIf IsCollinear(vDir(1), 1) And IsCollinear(vDir(0), 0) Then

                              GetOrientation = "vertical"

                          End If

                      End Function

                       

                      Function IsCollinear(val As Variant, vector As Double) As Boolean

                          Const TOL = 0.00000001

                          IsCollinear = Abs(Abs(val) - Abs(vector)) < TOL

                      End Function

                        • Re: How to determine the vertical size, or horizontal size.
                          Yong Ning

                          Function GetOrientation(swDisplayDimension As DisplayDimension) As String

                              Dim SwDim As SldWorks.Dimension

                              Set SwDim = swDisplayDimension.GetDimension '2(0)

                              Dim swMathVec As SldWorks.MathVector

                              Dim vDir As Variant

                           

                              GetOrientation = ""

                           

                              Set swMathVec = SwDim.DimensionLineDirection

                              vDir = swMathVec.ArrayData

                           

                              If IsCollinear(vDir(0), 1) And IsCollinear(vDir(1), 0) Then

                                  GetOrientation = "HOR"

                              ElseIf IsCollinear(vDir(1), 1) And IsCollinear(vDir(0), 0) Then

                                  GetOrientation = "VER"

                              End If

                          End Function

                           

                          Function IsCollinear(val As Variant, vector As Double) As Boolean

                              Const TOL = 0.00000001

                              IsCollinear = Abs(Abs(val) - Abs(vector)) < TOL

                          End Function

                           

                           

                           

                           

                           

                           

                          Function DispDimType(SwDispDim As DisplayDimension)

                                    Select Case SwDispDim.Type2

                                             Case swDimensionType_e.swOrdinateDimension

                                                   Debug.Print "" & GetOrientation(SwDispDim) & " ordinate and its subordinates"

                                             Case swDimensionType_e.swLinearDimension

                                                   Debug.Print "" & GetOrientation(SwDispDim) & " linear"

                                             Case swDimensionType_e.swAngularDimension

                                                   Debug.Print "  Display dimension type  = angular"

                                             Case swDimensionType_e.swArcLengthDimension

                                                   Debug.Print "arc length"

                                             Case swDimensionType_e.swRadialDimension

                                                   Debug.Print "radial"

                                             Case swDimensionType_e.swDiameterDimension

                                                   Debug.Print "diameter"

                                             Case swDimensionType_e.swHorOrdinateDimension

                                                   Debug.Print "horizontal ordinate"

                                             Case swDimensionType_e.swVertOrdinateDimension

                                                   Debug.Print "vertical ordinate"

                                             Case swDimensionType_e.swZAxisDimension

                                                   Debug.Print "z-axis"

                                             Case swDimensionType_e.swChamferDimension

                                                   Debug.Print "chamfer dimension"

                                             Case swDimensionType_e.swHorLinearDimension

                                                   Debug.Print "horizontal linear"

                                             Case swDimensionType_e.swVertLinearDimension

                                                   Debug.Print "vertical linear"

                                             Case swDimensionType_e.swScalarDimension

                                                   Debug.Print "scalar"

                                             Case Else

                                                   Debug.Print "unknown"

                                   

                                    End Select

                          End Function

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

                          DisplayDimension::Type2

                          This method gets the type of dimension.

                          retval = DisplayDimension.Type2 (VB Get property)

                          Type of dimension as defined by swDimensionType_e

                           

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

                          swDimensionType_e

                          swDimensionTypeUnknown - Dimension type could not be determined

                          swOrdinateDimension - Base ordinate and its subordinates are of this type

                          swLinearDimension - Linear dimension type

                          swAngularDimension - Angular dimension type

                          swArcLengthDimension - Arc length dimension type

                          swRadialDimension - Radial and diametric dimensions are of this type

                          swDiameterDimension

                          swHorOrdinateDimension - Horizontal ordinate dimension

                          swVertOrdinateDimension - Vertical ordinate dimension

                          swZAxisDimension

                          swChamferDimension

                          swHorLinearDimension - Horizontal linear dimension

                          swVertLinearDimension - Vertical linear dimension

                          swScalarDimension

                          DisplayDimension::Type2

                          This method gets the type of dimension.

                          retval = DisplayDimension.Type2 (VB Get property)

                           

                          Type of dimension as defined by swDimensionType_e

                        • Re: How to determine the vertical size, or horizontal size.
                          Yong Ning

                          For horizontal dimension I got: X = 1 Y = 0 Z = 0

                          vertical : X = 0 Y = 1 Z = 0

                           

                          [cos0,    -sin0,   x0-(cos0*x0 - sin0*y0)]

                          [sin0,     cos0,   y0-(sin0*x0 + cos0*y0)]

                          [   0,        0,                       1 ]

                           

                           

                          3x3 Matrix Rotation in C++ - Stack Overflow  https://stackoverflow.com/questions/16663647/3x3-matrix-rotation-in-c?noredirect=1

                           

                           

                           

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

                           

                          Function HorVerArr(SwModel As ModelDoc2, SwMathUtil As MathUtility, SwView As View, SwDispDim As DisplayDimension)

                             Dim SwXForm As MathTransform

                                 Set SwXForm = SwView.ModelToViewTransform

                             Dim SwDim As Dimension

                             Dim SwAnn As Annotation, SwAnn1 As Annotation

                             Dim Ss, oScale, ii, Str

                             Dim MathPt As MathPoint

                             Dim SwNote As Note

                                 With SwDispDim

                                     Set SwDim = .GetDimension

                                     'Debug.Print SwDim.FullName

                                     Set SwAnn = .GetAnnotation

                                     Ss = SwDim.ReferencePoints

                                     oScale = 1

                                     For ii = 0 To 2

                                         Set MathPt = Ss(ii)

                                         Set MathPt = MathPt.MultiplyTransform(SwXForm)

                                         With MathPt

                                                  Debug.Print "   xy(" & ii & "," & 0 & ")=" & Round(.ArrayData(0), 6) & ":",

                                                  Debug.Print "   xy(" & ii & "," & 1 & ")=" & Round(.ArrayData(1), 6)

                                                  tmp = SwModel.Extension.SelectByID2("", "VERTEX", .ArrayData(0), .ArrayData(1), .ArrayData(2), False, 0, Nothing, 0)

                                                  Str = SwDim.Name & "-" & ii

                                                  Str = Str & vbCr & " (" & Round(.ArrayData(0), 4) & "," & Round(.ArrayData(1), 4) & ",0)"

                                         End With

                                         ''

                                     Next ii

                                 End With

                             Dim MathVext As MathVector, Pt(2) As Double

                                 Set MathVect = SwDim.DimensionLineDirection

                                 vDir = MathVect.ArrayData

                                 Str = "("

                                 For jj = 0 To 2

                                      Str = Str & Round(vDir(jj), 5) & ","

                                 Next jj               ''

                                 Str = Left(Str, Len(Str) - 1) & ")" & vbCrLf

                                 Str = Str & GetOrientation(SwDispDim) & "-" & SwDim.Name

                                 ''

                                 SwAnn.Select True

                                 SwModel.EditDimensionProperties2 0, 0, 0, "", "", 1, 9, 2, 1, 11, 11, "", "", 1, "", Str, 1

                                 'SwModel.GraphicsRedraw2

                          End Function

                           

                           

                          Private Sub SheetDimensionHorVer()

                              Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                                   Set SwApp = Application.SldWorks

                                   Set SwModel = SwApp.ActiveDoc

                              Dim SwMathUtil As MathUtility

                                   Set SwMathUtil = SwApp.GetMathUtility

                              Dim SwDraw As DrawingDoc

                                   Set SwDraw = SwModel

                              Dim vSheets, SwSheet As Sheet

                              Dim SwView As View

                                

                              Dim SkSketch As Sketch, SkPtArr

                              Dim SwDispDim As DisplayDimension

                              Dim SwNote As Note, SwAnn As Annotation, Anns

                                   vSheets = SwDraw.GetSheetNames

                                   For ii = UBound(vSheets) To 0 Step -1

                                       SwDraw.ActivateSheet vSheets(ii)

                                       Set SwSheet = SwDraw.GetCurrentSheet

                                       Set SwView = SwDraw.GetFirstView             ''

                                       Set SwView = SwView.GetNextView

                                       ''

                                       Do While Not SwView Is Nothing

                                             SwModel.ClearSelection2 True

                                             Set SwNote = SwView.GetFirstNote

                                             Do While Not SwNote Is Nothing

                                                 'Debug.Print SwNote.GetText

                                                 Set SwAnn = SwNote.GetAnnotation

                                                 SwAnn.Select True

                                                 Set SwNote = SwNote.GetNext

                                             Loop

                                             ''

                                             SwModel.EditDelete

                                             SwModel.ClearSelection2 True

                                             ''

                                             Set SwDispDim = SwView.GetFirstDisplayDimension

                                             Do While Not SwDispDim Is Nothing

                                                 With SwDispDim

                                                     If .Type2 = 2 Or .Type2 = 11 Or .Type2 = 12 Then

                                                         Arr = HorVerArr(SwModel, SwMathUtil, SwView, SwDispDim)

                                                     End If

                                                 End With

                                                 Set SwDispDim = SwDispDim.GetNext

                                             Loop

                                             Set SwView = SwView.GetNextView

                                       Loop

                                   Next ii

                          End Sub

                        • Re: How to determine the vertical size, or horizontal size.
                          Viktor Bovzdarenko

                          Please note that sometimes the value of the vector could be negative (e.g. -1 ot +1). But still in both cases the dimension is pointing the same direction