Testing for entity existence

Discussion in 'AutoCAD' started by z26y25, Apr 1, 2005.

  1. z26y25

    z26y25 Guest

    I have a list of entities that I want to go through one by one and test for the existence of that entity. The idea is that I am saving a tab name and a viewport entity name in a list. When I retrieve the entity name I would like to be able to test for it's existence before manipulating it, this way I could test to see if it had been erased.

    I've tried several versions of:
    (ssget "x" (list '(-1 . entity)))
    and
    (ssget "x" (list (cons -1 entity)))
    Where entity is the entity name.

    Does anyone have any suggestions on how to perform this test?
     
    z26y25, Apr 1, 2005
    #1
  2. Not sure I completely understand what you are
    trying to do exactly, but can't you just use (entget)?


    Command: (setq ename (car (entsel)))

    Select object: <Entity name: 79d727a0>

    Command: (entdel ename)
    <Entity name: 79d727a0>

    Command: (entget ename)
    nil


    --
    Autodesk Discussion Group Facilitator



    for the existence of that entity. The idea is that I am saving a tab name
    and a viewport entity name in a list. When I retrieve the entity name I
    would like to be able to test for it's existence before manipulating it,
    this way I could test to see if it had been erased.
     
    Jason Piercey, Apr 1, 2005
    #2
  3. z26y25

    Don Ireland Guest

    There is only one item in the list so "nth 0" works in THIS case. Develop
    as needed.

    (setq testList(list "LINE"))
    (ssget "x" (list(cons 0 (nth 0 testList))))
     
    Don Ireland, Apr 1, 2005
    #3
  4. z26y25

    Tom Smith Guest

    Interesting -- according to help, ssget will ignore enames, handles, and xdata codes in filter lists, so you'll have to take another approach. Sorry I don't have a suggestion.
     
    Tom Smith, Apr 1, 2005
    #4
  5. z26y25

    Don Ireland Guest

    You CAN use variables in the filter lists--just not using the abbreviated
    list notation. By "abbreviated list notation, I mean using the apostrophe
    instead of typing out list.

    i.e.
    ;the following WILL work--I just did it (using Acad2k5)
    (ssget "x" (list(cons 0 (nth 0 testList))))

    ;the following will NOT work
    (ssget "x" '(cons 0 (nth 0 testList)))
     
    Don Ireland, Apr 1, 2005
    #5
  6. z26y25

    Don Ireland Guest

    Misunderstood what OP was looking for. But I DO have a solution for him.
     
    Don Ireland, Apr 1, 2005
    #6
  7. z26y25

    Don Ireland Guest

    SORRY misunderstood what you were asking for.

    ;retrieve EVERY element in the file
    (setq entlist(ssget "x"))

    ;if entity is in entlist then returns the ename
    ;otherwise returns nil
    (ssmemb entity entlist)
     
    Don Ireland, Apr 1, 2005
    #7
  8. z26y25

    Don Ireland Guest

    And remember the ename will change every time you reopen the file.
     
    Don Ireland, Apr 1, 2005
    #8
  9. z26y25

    Tom Smith Guest

    I understand the differences in filter list syntax. The single-apostrophe is not just an abbreviated format. The apostrophe is shorthand for the lisp "quote" function, which has the purpose of suppressing evaluation of an atom or list.

    '(1 2 3) is identical to (quote (1 2 3)) -- they both return the unevaluated list (1 2 3). You can't quote (supress evaluation of) any list which contains a variable that needs to be evaluated. If you (setq var 1), then '(var 2 3) will return (VAR 2 3) whereas (list var 2 3) will return (1 2 3).

    I was simply repeating what the A2K4 help docs state -- that entity names and handles are not allowed, and are ignored, in ssget filter lists. It's not a matter of notation, it's a matter of what criteria you can filter upon. The OP had a syntax error, yes. But that wasn't the basic problem. In A2K4, at least, you can't filter on entity names, period.

    Your solution of tesing the members of the ename list against the whole drawing sset looks like a clever way to work around this cruel fact, though it might be punishingly slow in a large file. Maybe it will work out for the OP.
     
    Tom Smith, Apr 2, 2005
    #9
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.