How to find if a dictionary exists

Discussion in 'AutoCAD' started by Tom Berning, Nov 23, 2004.

  1. Tom Berning

    Tom Berning Guest

    I am working on a lisp routine to modify a layer state, but I need to verify
    the ACAD_LAYERSTATES dictionary exists in the drawing first. I can't figure
    out how to search for a dictionary without getting an error at the command
    line. A new drawing doesn't contain this dictionary until a layer state is
    saved.

    Tom
     
    Tom Berning, Nov 23, 2004
    #1
  2. Tom Berning

    Joe Burke Guest

    Tom,

    Use member or vl-position...

    ;returns: a list of dictionary names
    (defun ListDictionaries ( / dicts lst )
    (setq dicts
    (vla-get-dictionaries
    (vla-get-activedocument
    (vlax-get-acad-object))))
    (vlax-for x dicts
    (if (vlax-property-available-p x 'Name)
    (setq lst (cons (vlax-get x 'Name) lst))
    )
    )
    ) ;end

    Joe Burke
     
    Joe Burke, Nov 24, 2004
    #2
  3. Hi Joe,

    I thought about trying to answer this question but
    with all the different ways layer states are stored
    these days (lman, views, layer manager) I was a
    bit unsure as to which the OP needs and also how
    each method differs in storage/retrieval.

    I don't think the layer states dictionary is accessible
    with the method you demonstrated, at least not with
    the quick tests I did this afternoon after initially
    reading this thread. Perhaps you know differently?

    Also, regarding your sample code, testing for the
    existence of a single object within a collection I'd
    use vla-item instead of vlax-for. (assuming that is
    the OP's actual requirements)

    On an additional note, have you run into times where
    a dictionary doesn't have a name property? Just
    curious about your use of vlax-property-available-p
    in this case.

    (feeling long-winded)
     
    Jason Piercey, Nov 24, 2004
    #3
  4. Tom Berning

    Jeff Mishler Guest

    Jason,
    If you (vlax-for through the dictionary collection, the very first item in
    the collection is the Groups collection. I have no idea why it is a part of
    the Dictionaries, but it does not have a Name property and will cause any
    function to fail that tries to list it.

    ; IAcadGroups: The collection of all groups in the drawing
    ; Property values:
    ; Application (RO) = #<VLA-OBJECT IAcadApplication 00a8a730>
    ; Count (RO) = 0
    ; Document (RO) = #<VLA-OBJECT IAcadDocument 0104b71c>
    ; Handle (RO) = "D"
    ; HasExtensionDictionary (RO) = 0
    ; ObjectID (RO) = 1074277480
    ; ObjectName (RO) = "AcDbDictionary"
    ; OwnerID (RO) = 1074277472

    Jeff
     
    Jeff Mishler, Nov 24, 2004
    #4
  5. Tom Berning

    Joe Burke Guest

    Hi Jason,

    You guessed it. I'm clueless regarding layer states. :) In a sense, I took Tom's
    question at face value.

    Agreed, the item method is more direct when you know an object can be retrieved, or
    checked for, that way. But I was aware not all dictionaries return a name. Which
    seems strange given the "named object dictionary". That's why the property available
    check.

    So my thought was provide a list of all available dictionary names. Then see where
    things went from there.

    Besides what Jeff mentioned, the ACAD_LAYOUT and ACAD_PLOTSETTINGS dictionaries also
    don't return a name.

    Joe Burke
     
    Joe Burke, Nov 24, 2004
    #5
  6. Jeff, Joe,

    Thanks for pointing out the lack of a name property
    on some dictionary objects. Funny I glanced at my
    toolbox functions for dictionaries this morning, and
    guess what? (vlax-property-available-p) is used
    when grabbing the names. Guess I just forgot :)
     
    Jason Piercey, Nov 24, 2004
    #6
  7. Tom Berning

    Joe Burke Guest

    Jason,

    If I could remember everything I once knew... I'd be a freaking genius. :)

    Pushing 55, it gets harder every day. Though I don't find that to be particularly
    discouraging. Just another challenge, similar to learning in the first place.

    Joe
     
    Joe Burke, Nov 24, 2004
    #7
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.