Results 1 to 5 of 5

Thread: Entities and Handles

  1. #1
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Entities and Handles

    How do you pull an entity if you know it's handle?
    ex.
    dim myArc as AcadArc

    set myArc = ????

    or it it is not possible, I have actually trimmed a circle and I am now trying to find out it's end points. "myEntity.EndPoint" does not work.

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Entities and Handles

    ThisDrawing.HandleToObject()

    It would be helpful if you were to show a little more code than "myEntity.EndPoint".
    C:> ED WORKING....


    LinkedIn

  3. #3
    100 Club
    Join Date
    2002-10
    Posts
    154
    Login to Give a bone
    0

    Default Re: Entities and Handles

    Below is a simple version of what I am trying to do. I am stuck at the bottom to Testing. I trimmed a circle and now I am trying to get the arc's end points.


    'before running test, draw a closed Poly Line and a Circle centered at the end
    Sub Testing()
    Dim myCircle As AcadCircle, myPolyLine As AcadPolyline
    Dim tempObj As AcadObject, basePt As Variant

    'selectCircle lets the user select a existing circle
    Set myCircle = selectCircle

    'set the base point to the circle's center
    basePt = myCircle.Center
    'delete the circle because we do not need it
    myCircle.Delete


    Set tempObj = selectPolyLine(basePt)
    On Error GoTo NO_POLYLINE

    If tempObj.EntityName = "" Then GoTo NO_POLYLINE
    On Error GoTo 0


    'modify drawing
    Dim circle1 As AcadCircle, circle2 As AcadCircle, circle3 As AcadCircle
    Dim line1 As AcadLine, tempEntity As AcadEntity, arc1 As AcadArc
    Dim TrimSide As Variant, trimString As String

    TrimSide = ThisDrawing.Utility.GetPoint(, "Select outside of objects.")
    Set circle3 = dCircle(basePt, 2#)
    Set line1 = dLine(basePt, TrimSide)

    trimString = Trim(Str(TrimSide(0))) & "," & _
    Trim(Str(TrimSide(1))) & "," & _
    Trim(Str(TrimSide(2)))

    ThisDrawing.SendCommand "_trim" & vbCr & vbCr & trimString & vbCr & vbCr

    TrimSide = line1.EndPoint
    If TrimSide(0) = basePt(0) And _
    TrimSide(1) = basePt(1) Then TrimSide = line1.StartPoint

    trimString = Trim(Str(TrimSide(0))) & "," & _
    Trim(Str(TrimSide(1))) & "," & _
    Trim(Str(TrimSide(2)))

    Set line1 = Nothing
    'it will not let me use "line1.Delete" (because you just set line1 to Nothing) Therefore use undo
    ThisDrawing.SendCommand "u u "

    Set tempEntity = dCircle(basePt, 2#)
    ThisDrawing.SendCommand "_trim" & vbCr & vbCr & trimString & vbCr & vbCr

    'I need to get the endpoints of the circle which is now an arc and then delete the arc.
    'debug.Print tempEntity.EndPoing(0) 'does not work
    'debug.Print tempEntity.Center(0) 'does not work
    'Once you trim the circle, there is no more circle, it gets deleted and an arc is created.
    'Therefore, tempEntity is no longer set.
    'You could use basept to select the arc like you selected the poly earlier or use Last.

    Exit Sub
    NO_POLYLINE:
    MsgBox "Interior object is not a Poly Line. Program Haulted!!!"

    End Sub




    '***Select Commands

    Public Function selectCircle() As AcadObject
    Dim myCircle As AcadObject, basePnt As Variant

    Set selectCircle = Nothing

    On Error Resume Next

    RETRY:
    Err = 123
    While Err <> 0
    Err.Clear
    ThisDrawing.Utility.GetEntity selectCircle, basePnt, "Select an Circle:"
    Wend

    If selectCircle.EntityName = "AcDbCircle" Then
    'DO NOTHING
    Else
    MsgBox "The object is not a Circle. Please select a Circle."
    GoTo RETRY
    End If
    On Error GoTo 0
    End Function

    Public Function selectPolyLine(basePnt As Variant) As AcadEntity ' AcadObject 'AcadPolyline
    Dim SS As AcadSelectionSet, myObj As AcadEntity ' AcadObject

    On Error Resume Next

    Set SS = ThisDrawing.SelectionSets.Add("SS001")
    SS.SelectAtPoint (basePnt)

    Set selectPolyLine = SS.Item(0)
    SS.Delete

    ' Set selectPolyLine = myObj
    ' selectPolyLine.Layer = "hello"
    If Err = 0 Then
    If selectPolyLine.EntityName = "AcDbPolyline" Then
    'do nothing
    Else
    Set selectPolyLine = Nothing
    Set selectPolyLine = SS
    End If
    End If
    End Function


    '***Drawing commands
    Public Function dLine(FirstPoint As Variant, SecondPoint As Variant) As AcadLine

    Set dLine = ThisDrawing.ModelSpace.AddLine(FirstPoint, SecondPoint)
    End Function

    Public Function dCircle(CenterPoint As Variant, CircleRadius As Double) As AcadCircle
    Set dCircle = ThisDrawing.ModelSpace.AddCircle(CenterPoint, CircleRadius)
    End Function
    Last edited by Ed Jobe; 2004-09-23 at 08:37 PM.

  4. #4
    Active Member
    Join Date
    2000-12
    Location
    Las Vegas
    Posts
    68
    Login to Give a bone
    0

    Default Re: Entities and Handles

    Try using the following with the actual handle you have for the object. If you know the actual object type you can also dimension it as such.

    Dim SomeObj As AcadObject
    Set SomeObj = ThisDrawing.HandleToObject("3dch5")

    This Will make SomeObj = to the object of the noted handle. So if the handle belongs to a circle SomeObj will be that circle etc. This is good because handles are good from session to session.

  5. #5
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,419
    Login to Give a bone
    0

    Default Re: Entities and Handles

    See my comments in Red within your post.
    C:> ED WORKING....


    LinkedIn

Similar Threads

  1. Replies: 0
    Last Post: 2014-12-27, 08:59 PM
  2. Help with Handles!
    By dupuy77362646 in forum AutoLISP
    Replies: 11
    Last Post: 2013-03-03, 10:52 PM
  3. 2009: Differentiate text entities from mtext entities
    By samirjoshi in forum AutoCAD General
    Replies: 4
    Last Post: 2012-01-16, 11:08 AM
  4. Replies: 1
    Last Post: 2006-04-23, 06:16 PM
  5. Replies: 0
    Last Post: 2005-07-08, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •