how to name an object in order to get it later by the name

Discussion in 'AutoCAD' started by youngman, Feb 24, 2004.

  1. youngman

    youngman Guest

    hi

    how to name an object in order to get it later by the name

    handle is a way to do so,but we can give an object handle all by ourselves.

    thank you
     
    youngman, Feb 24, 2004
    #1
  2. youngman

    youngman Guest

     
    youngman, Feb 24, 2004
    #2
  3. The handle property is exposed in vba for all entities. There is a HandleToObject method for selecting objects via there handle. If using the handle is inappropriate you could perhap use XDATA somehow.

    Regards - Nathan
     
    Nathan Taylor, Feb 24, 2004
    #3
  4. youngman

    youngman Guest

    HandleToObject method for selecting objects via there handle. If using the
    handle is inappropriate you could perhap use XDATA somehow.
    Thanks for your advice.

    but i mean we can not give an object a handle freely.

    it is inconvenient

    thanks
     
    youngman, Feb 25, 2004
    #4
  5. youngman

    wivory Guest

    If I understand you correctly, you could define a Dictionary (the VB kind not the AutoCAD kind - you will need a reference to the Scripting Runtime library for this) and create entries based on the name(s) you want to use and having the object handle in the Dictionary record. Then you could use HandleToObject as Nathan says to get the actual object.

    Example (straight out of my head - no syntax checking)

    Dim MyDict as New Dictionary

    Sub Main()
    Dim GeneralSolid as Acad3DSolid
    Dim GeneralLine as AcadLine
    ...
    Set GeneralSolid = ThisDrawing.ModelSpace.AddBox(pt1, 10, 20, 30)
    MyDict.Add "Brick", GeneralSolid.Handle
    Set GeneralLine = ThisDrawing.ModelSpace.AddLine(pt2, pt3)
    MyDict.Add "Rope", GeneralLine.Handle
    ...
    Set GeneralSolid = ObjectByName("Brick")
    Set GeneralLine = ObjectByName("Rope")
    End Sub

    Function ObjectByName(TheName As String) As AcadEntity
    Set ObjectByName = ThisDrawing.HandleToObject(MyDict(TheName))
    End Function

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Feb 25, 2004
    #5
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.