4 Replies Latest reply on Aug 7, 2017 8:32 AM by Nishihama Sayuri

    How to get the second entity attached to an annotation? (VBA)

    Nishihama Sayuri

      I drew an annotation by pointing two entities on .slddrw file.


      And I want to get second entity attached to the annotation using VBA.

      2016 SOLIDWORKS API Help - Get Types of Entities Attached to Selected Annotation Example (VBA)


      [GetAttachedEntities3] method returns entities, but entity order is at random.

      How do I get the second entity?


      vAttEntArr = swAnn.GetAttachedEntities3
      vAttEntTypeArr = swAnn.GetAttachedEntityTypes2

      If Not IsEmpty(vAttEntTypeArr) Then
          For i = 0 To UBound(vAttEntTypeArr)
               ' I want to get the second entity only. but entity order is at random.
               '  It is not always true "that i=1 entity is the second entity".
           Next i
      End If


      HELP me.

        • Re: How to get the second entity attached to an annotation? (VBA)
          Manikandan Babu

          Hi Sayuri,


          I have tried with below to code finding the second entity.

          Even i have tried for multiple dimension,it is working fine.


          Dim swApp As SldWorks.SldWorks

          Dim swmodel As SldWorks.ModelDoc2

          Dim swdraw As SldWorks.DrawingDoc

          Dim swview As SldWorks.View

          Dim Annotations As Variant

          Dim swann As SldWorks.Annotation

          Dim swentity As SldWorks.Entity

          Dim vAttEntTypeArr As Variant


          Sub main()

          Set swApp = Application.SldWorks

          Set swmodel = swApp.ActiveDoc

          Set swdraw = swmodel

          Set swview = swdraw.GetFirstView

          Set swview = swview.GetNextView

          Annotations = swview.GetAnnotations

          Set swann = Annotations(1)

          vAttEntArr = swann.GetAttachedEntities3

          Set swentity = vAttEntArr(1)

          swentity.Select True

          End Sub