How to store a list in a dictionary?

Discussion in 'AutoCAD' started by tsigwing, Mar 1, 2005.

  1. tsigwing

    tsigwing Guest

    I am trying to work with the layoutswitched event in VBA. What I would like to do is store a list of layers that are on and not frozen in a viewport. I did this with A2002 using Ldata, but we are moving to 2005 and that mehod is out. So, is there a good method for storing a list and associating it with a viewport?
     
    tsigwing, Mar 1, 2005
    #1
  2. Hi,

    You should be able to do this quite easily by created a new dictionary and
    storing the layer name data as a comma separated string, from which you can
    easily return it to an array with the Split command.

    You will find sample code for all you need in the help files.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au

    like to do is store a list of layers that are on and not frozen in a
    viewport. I did this with A2002 using Ldata, but we are moving to 2005 and
    that mehod is out. So, is there a good method for storing a list and
    associating it with a viewport?
     
    Laurie Comerford, Mar 1, 2005
    #2
  3. Pardon this, but let's not promote unsound practices like
    name-based references. The people who designed AutoCAD's
    database gave a lot of thought to this, and it would be good
    if programmers took advantage of it.

    For starters, if you persist references to layers by storing
    their names as strings, AutoCAD doesn't know they're layer
    names.

    Practically, what that means is that if a user were to
    subsequently RENAME a layer,your string contining the old
    layer name is no longer valid.

    A reference to a layer can be stored in XDATA, or as an
    object ID reference in an xrecord, in a way that is not
    name-dependent.

    "Name-dependent reference", means that a reference to
    something like a layer, is made by storing the name of the
    referenced object.

    Name-dependent references are bad.

    In contrast, a name-independent reference is where somthing
    in a draiwng is referenced by storing something other than the
    referenced object's name, such as its object id.

    The important thing about that is that if a user renames
    something that is referenced by its name, the reference is
    broken.

    Conversely, if a reference to something is not name-dependent
    (e.g., via object an id), the reference is not broken when the
    referenced object's name is changed.
     
    Tony Tanzillo, Mar 2, 2005
    #3
  4. You can store layer names in extended entity data, or
    you can store the object ids of layers in an xrecord that
    is stored in the viewport's extension dictionary.

    The bad thing about storing the names of layers is that
    the layers can be renamed. In that case, you would no
    longer have a valid reference. By storing the object id
    of a layer (or a layer in the xdata layer group), you do
    not have to concern yourself with breaking references
    if a layer is renamed.

    This is certainly not as easy as LDATA or storing a comma
    delimited string somewhere. I've found that more often
    than not, the easiest way to do something is also not the
    best/proper way. I've also found that when you take the
    easy way out, you don't realize that it was a bad decision
    until its way too late to do an about-face.

    You will need to familiarize yourself with XRECORDS and/or
    XDATA to do this. XRecords are generally a better way to
    attach data to objects, in contrast to LDATA.

    If you're unsure about how to proceed, feel free to
    post back, and/or search the newsgroups using keys like
    'XRECORD', SetXRecordData, GetXRecordData, etc.
     
    Tony Tanzillo, Mar 3, 2005
    #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.