How to get the entityname in a closed polygon?

Discussion in 'AutoCAD' started by viswanathan, Dec 20, 2004.

  1. viswanathan

    viswanathan Guest

    Hi all,

    I am having one closed polygon . Inside that polygon there is a text entity, Point entity etc....?

    How to get the name of these all text and point entity inside a closed polygon?

    Regards,
    viswanathan.s
     
    viswanathan, Dec 20, 2004
    #1
  2. viswanathan

    m8shark Guest

    What do you mean by entityname? That makes sense in lisp, but not really in VBA, where you would use the Handle (persistent) or ObjectID (transient).

    You can process entities within a closed polygon with something like the following.

    Sub Bubba()
    Dim obj As AcadObject 'object selected with GetEntity
    Dim vpt 'pick point for GetEntity
    Dim vpts2 '2d array of lwpolyline coords
    Dim vpts3() As Double '3d array of coords for selection set
    Dim cnt As Integer 'count of lwpolyline coords
    Dim i As Integer 'iterator variable
    Dim ss As AcadSelectionSet
    Dim ent As AcadEntity 'iterator object

    'pick the lwpolyline
    Utility.GetEntity obj, vpt

    'must pick lwpolyline!
    If Not TypeOf obj Is AcadLWPolyline Then Exit Sub

    'convert 2d array to 3d array by first finding
    'number of coordinates in lwpolyline. then create
    '3d array with same number of coordinates and fill
    'it with 2d array values
    vpts2 = obj.Coordinates
    cnt = (UBound(vpts2) + 1) / 2
    ReDim Preserve vpts3((3 * cnt) - 1) As Double
    For i = 0 To cnt - 1
    vpts3(3 * i) = vpts2(2 * i) 'X
    vpts3(3 * i + 1) = vpts2(2 * i + 1) 'Y
    vpts3(3 * i + 2) = 0# 'Z
    Next

    'make/remake the selection set
    On Error GoTo ErrHandler
    Set ss = SelectionSets.Add("myss")

    'fill the selection set
    ss.SelectByPolygon acSelectionSetWindowPolygon, vpts3

    'loop thru selection set and do stuff
    For Each ent In ss
    'do cool stuff here
    Debug.Print ent.Handle
    Next

    'delete the selection set
    ss.Delete
    Exit Sub
    ErrHandler:
    If Err.Number = -2145320851 Then
    SelectionSets("myss").Delete
    Resume
    End If
    End Sub
     
    m8shark, Dec 20, 2004
    #2
  3. viswanathan

    viswanathan Guest

    Wow, Great. It is working fine.

    Regards,

    viswanathan.s
     
    viswanathan, Dec 21, 2004
    #3
  4. viswanathan

    m8shark Guest

    You're welcome.

    Cheers, Steve
     
    m8shark, Dec 21, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.