3 Replies Latest reply on Apr 12, 2018 5:01 PM by John Alexander

    Position data of centermarks in the API

    David Nobes

      I would like to retrieve the position data of centermarks using VB and the API. There does not appear to be a straight forward way to do this, especially including linked or joined centermarks. Centermarks appear now to be a annotation. Does anyone know how to do this?

        • Re: Position data of centermarks in the API
          John Alexander

          2012 SOLIDWORKS API Help - GetPosition Method (IAnnotation)

           

          'declare variables

          set swAnnotation = swCenterMark

          position = swAnnotation.GetPosition()

           

          If that doesn't work, you can try getting a reference to the hole feature's (circular) edge via 2012 SOLIDWORKS API Help - GetAttachedEntities3 Method (IAnnotation)

           

          'declare variables

          set swAnnotation = swCenterMark

          entities = swAnnotation.GetAttachedEntities()

          foreach Entity entity in entities

               'check if entity is an Edge, if it's an Edge, try to get the underlying curve, check if it's circular, get the circleParams out of it. One of those      circleparams will be the centerpoint.

          next entity

          2012 SOLIDWORKS API Help - CircleParams Property (ICurve)

            • Re: Position data of centermarks in the API
              David Nobes

              John,

              Thanks for the reply.

              You first approach does not really work. It appear to locate the right edge (3 o'clock position) of the hole.

              Also, it dos not deal with two joined CenterMarks (two hole pattern).

              Have not tried your second approach, but is seems a long way around. I was hoping there might be a more simpler way, especially for a large hole pattern with joined CenterMarks.

                • Re: Position data of centermarks in the API
                  John Alexander

                  I have this function that I modified from a recent project. I haven't tested it but it should get you 95% of the way there if it works.

                   

                  Private Function GetEdgeFromCenterMark(swCenterMark As SldWorks.CenterMark) As SldWorks.Edge

                      Dim swAnnotation    As SldWorks.Annotation

                      Dim swSurface       As SldWorks.Surface

                      Dim swFeature       As SldWorks.Feature

                      Dim swEntity        As SldWorks.Entity

                      Dim swFace          As SldWorks.Face2

                      Dim swEdge          As SldWorks.Edge

                     

                      Dim vCenterMark As Variant

                      Dim vEntities As Variant

                      Dim i As Integer

                     

                      Set swAnnotation = swCenterMark.GetAnnotation

                      vEntities = swAnnotation.GetAttachedEntities3

                      For i = 0 To swAnnotation.GetAttachedEntityCount3 - 1

                          Set swEntity = vEntities(i)

                          Dim swSketchSegment As SldWorks.SketchSegment

                          Set swEdge = swEntity

                          If Not swEdge Is Nothing Then

                              Set swFace = swEdge.GetTwoAdjacentFaces2(0)

                              Set swFeature = swFace.GetFeature

                              If StrComp(swFeature.GetTypeName2, "HoleWzd") = 0 Then

                                  Set swSurface = swFace.GetSurface

                                  If swSurface.IsCylinder Then

                                      Set GetEdgeFromCenterMark = swEdge

                                      Exit Funciton

                                  End If

                              Else

                                  Set swFace = swEdge.GetTwoAdjacentFaces2(1)

                                  Set swFeature = swFace.GetFeature

                                  If StrComp(swFeature.GetTypeName2, "HoleWzd") = 0 Then

                                      Set swSurface = swFace.GetSurface

                                      If swSurface.IsCylinder Then

                                          Set GetEdgeFromCenterMark = swEdge

                                          Exit Funciton

                                      End If

                                  End If

                              End If

                          End If

                      Next i

                  End Function

                   

                  If that returns the Edge consistently, it is <very> likely to be a hole surface edge. All you would need to do is get the Curve from the Edge (GetCurve) and then check the CircleParams values for the center point. I'm not sure what coordinate system the centerpoint will be reported with respect to.