2 Replies Latest reply on Jul 28, 2015 1:40 PM by Aj Jones

    Get Circle's (Arc) X And Y Coordinates And Display Dimension Name With API

    Aj Jones

      I have one sketch that has multiple circles drawn in it.  Each circle has a dimension for it, and the dimensions are named by letters (A, B, C, D, etc.)  I'm looking to see if anyone knows a way for me to get a circle's (arc) radius, and x and y coordinates from the origin, and the name of the dimension that is attached to it.  My end goal is to be able to run my program and have it output something like:


      Circle A: Radius = 3; X Coordinate From Origin = 5; Y Coordinate From Origin = 8 

      Circle B: Radius = 2.5; X Coordinate From Origin = -5; Y Coordinate From Origin = 3

      Circle C: Radius = 7; X Coordinate From Origin = 2; Y Coordinate From Origin = -8 


      I've tried this by iterating through the display dimension names in the sketch, but then I don't know how to get the center point locations of the arcs they are attached too.  I've also tried from the other direction, by finding all of the arcs in the sketch, and I've been able to get the center points and radius for each arc, but then I can't find the name of the dimension attached to them using:






      Does anyone know a way I can loop through the display dimensions, or Arcs in the sketch and get the dimension name, x & y coordinates from the origin of the entire model to the circle (arc) center, and radius?



        • Re: Get Circle's (Arc) X And Y Coordinates And Display Dimension Name With API
          Simon Turner

          Iterate through all the DisplayDimensions in the sketch by getting a Feature object from the sketch and then using Feature.GetFirstDisplayDimension  and Feature.GetNextDisplayDimension

          From each DisplayDimension, get the Annotation object and useGetAttachedEntities3 to check what it is attached to.


            • Re: Get Circle's (Arc) X And Y Coordinates And Display Dimension Name With API
              Aj Jones

              Simon, thanks for the help!

              In case anyone needs to see how this was done, below is the code that I came up with for my particular case.





              Option Explicit



                  Dim swApp As SldWorks.SldWorks

                  Dim Model As SldWorks.ModelDoc2

                  Dim selMgr As SldWorks.SelectionMgr

                  Dim CurAnnotation As SldWorks.Annotation

                  Dim CurFeature As SldWorks.Feature

                  Dim DispDim As SldWorks.DisplayDimension

                  Dim vSkSegArr As Variant

                  Dim swSkSeg As SldWorks.SketchSegment

                  Dim swSkArc As SldWorks.SketchArc

                  Dim swCtrPt As SldWorks.SketchPoint




              Sub main()


                  'Attach the program to SolidWorks application

                  Set swApp = CreateObject("SldWorks.Application")


                  'Get the model

                  Set Model = swApp.ActiveDoc

                  Set selMgr = Model.SelectionManager


                 ' Get the already selected sketch

                  Set CurFeature = selMgr.GetSelectedObject5(1)



                  'Get the first DisplayDimension in the selected sketch

                  Set DispDim = CurFeature.GetFirstDisplayDimension


                  'Iterate through all of the display dimensions in the sketch

                  Do While Not DispDim Is Nothing



                      'Retrieve the annotation from display dimension

                      Set CurAnnotation = DispDim.GetAnnotation


                      'Set the sketch segment array

                      vSkSegArr = CurAnnotation.GetAttachedEntities3


                      'The sketch segment is always an arc for this particular model

                      Set swSkArc = vSkSegArr(0)

                      Set swCtrPt = swSkArc.GetCenterPoint2

                      Debug.Print "The X distance is " & swCtrPt.X

                      Debug.Print "The Y Distance is " & swCtrPt.Y

                      Debug.Print "The Radius is " & swSkArc.GetRadius

                      Debug.Print "The Dimension Name is: " & CurAnnotation.GetName

                      Debug.Print "----------------------------------------"

                      'Get the next display dimension

                      Set DispDim = CurFeature.GetNextDisplayDimension(DispDim)





              End Sub