2 Replies Latest reply on Oct 28, 2014 3:29 PM by Jacob Corder

    Get endpoints of a DisplayDimension

    Matt Groening

      How can I get the endpoints (of the arrows) of a DisplayDimension? I need the xyz coordinates.


      I also need the coordinates of the text.

        • Re: Get endpoints of a DisplayDimension
          Jacob Corder



          First you need to get thie IDisplayDimension Object.


          Then IDisplayDimension.GetAnnotation which gives you the Annotation Object.

          Dim ThisDisplayDimension as DisplayDimension

          ThisDisplayDimension = ' however you are getting the DisplayDimension


          Dim This Ann as annotation

          ThisAnn = ThisDisplayDImension.GetAnnotation

          'The XYZ Location of the text is found by


          Dim AnnPos as object =ThisAnn.GetPosition

          'The AnnPos object will Return XYZ coordinates for the Posiiton of the annotation.

          'IMPORTANT. The Location is different based on the SwAnnotationType_e or ThisAnn.GetType

          'See Annotation Position below. The Fun part is measuring the size of the text if you want the bounding box of the annotation.

          Dim AnnLeaderPos as object

          Dim LeaderPositions(ThisAnn.GetLeaderCount-1) as object

          For i = 0 to ThisAnn.getLeaderCount -1

               AnnLeaderPos(i) = ThisAnn.GetLeaderPointsAtIndex(i)

               'The Return is formatted below based on the Leader Style see  ANNOTATION GET POINT AT INDEX below


          Now you have gotten all of the leader Points. See API Reference Below..



          The retval is an array of 3 doubles, the x, y, z origin of the annotation.

          If this method is not successful in retrieving the position of the annotation in Visual Basic for Applications (VBA), then the VARIANT SafeArray is empty (OLE Automation only), or the status value is S_false (COM only). Make sure that you check this value before using the returned position.

          The following table lists the types of annotations that this method supports and the position of the x, y, z origin. In a drawing, the x, y, z origin is relative to the origin of the drawing sheet (the lower-left corner of the sheet).


          Type of AnnotationPosition of XYZ Origin
          Datum Feature SymbolsPoint where leader hits symbol
          Datum Target SymbolsCenterpoint of the circle that is attached to the leader
          DimensionsUpper-left corner of the text box of the dimension
          Geometric TolerancesUpper-left corner of the symbol
          NotesUpper-left corner of the text box
          Surface Finish SymbolsLower-left point of symbol
          Table AnnotationPosition of x,y,z determined by ITableAnnotation::AnchorType
          Weld SymbolsLeft endpoint of the main horizontal line in the symbol



          If you use this method on any other types of annotations, SolidWorks takes no action and returns false.


          The index value is 0-based. Therefore, a valid index value is greater than or equal to 0, but less than the number of leaders on this annotation.

          Use IAnnotation::GetLeaderCount to find out how many leaders are on this annotation. If the index value is invalid in Visual Basic for Applications (VBA), SolidWorks returns an empty SafeArray or S_false.

          You must determine the number of points in the leader to use the data returned by this method. The number of points is a function of the number of segments in the leader. There can be one or two segments in a leader line, depending on whether or not it is a straight, bent, or underlined leader. Use IAnnotation::GetLeaderStyle
          to determine the number of points in the leader.

          • If IAnnotation::GetLeaderStyle returns swNO_LEADER, then the number of points = 0.
          • If IAnnotation::GetLeaderStyle returns swSTRAIGHT and swUNDERLINED then the number
            of points = 2.
          • If IAnnotation::GetLeaderStyle returns swBENT, then the number of points = 3.

          Additionally, for the COM interface, you must determine the number of points to allocate
          the appropriate size array for the return value. The number of points must also be
          passed to the method to help prevent overwrite problems if you have not allocated
          an array that is the correct size. If the number of points passed does not match
          what is found, SolidWorks does not return any point information and returns S_false.

          The format of the return array is:

          retval[0] = X-coordinate of first leader point (at the arrowhead)

          retval[1] = Y-coordinate of first leader point

          retval[2] = Z-coordinate of first leader point


          retval[3] = X-coordinate of second leader point

          retval[4] = Y-coordinate of second leader point

          retval[5] = Z-coordinate of second leader point


          retval[6] = X-coordinate of third leader point

          retval[7] = Y-coordinate of third leader point

          retval[8] = Z-coordinate of third leader point

          You cannot directly set the leader coordinate information. The leader coordinates are computed based on the annotations text and attachment points. Use IAnnotation::GetPosition and IAnnotation::SetPosition to get and set the text point.

          1 person found this helpful
          • Re: Get endpoints of a DisplayDimension
            Jacob Corder

            if you are looking for the Attachment points for Linear, ordinate, and Chamfer dimensions use this.


            Dim IDim as dimension

            IDim = IDisplayDimension.GetDimension2(0)

            'IMPORTANT if it is a chamfer Dimension you need to get both IDimension objects using IDisplayDimension.GetDimension2(0) and           'IDisplayDimension.GetDimension2(1) as there are 2 IDimension Objects in a chamfer dimension


            Dim RefPts as object = IDim.ReferencePoints

            RefPts will always return 3 math points.

            For linear dimensions they will be the 2 points where they are attached and the 3rd math points ArrayData will be (0,0,0)



            RefPts(0).ArrayData(0) = First Point X

            RefPts(0).ArrayData(1)= First Point Y

            RefPts(0).ArrayData(2) = First Point Z


            RefPts(1).ArrayData(0) = Second Point X

            RefPts(1).ArrayData(1)= Second Point Y

            RefPts(1).ArrayData(2) = Second Point Z

            1 person found this helpful