What's wrong with this

Discussion in 'AutoCAD' started by jclaidler, Apr 15, 2004.

  1. jclaidler

    jclaidler Guest

    What's wrong with this code:

    (if (and (<= (tblsearch "LAYER" "99"))(>= (tblsearch "LAYER" "10")))(alert "yes")(alert "no"))

    I always get "yes", even if there are no layers between 10 and 99.

    Thanks for any help.
     
    jclaidler, Apr 15, 2004
    #1
  2. Try geting down to the actual "TEXT" of the layername

    (cdr (assoc 2 (tblsearch "LAYER" "99")))

    and perhaps convert to a real number

    (atof (cdr (assoc 2 (tblsearch "LAYER" "99"))))
     
    Bruce Sheldon, Apr 15, 2004
    #2
  3. jclaidler

    jclaidler Guest

    I still get the same result.
     
    jclaidler, Apr 15, 2004
    #3
  4. jclaidler

    bob.at Guest

    Its not yet clear, what you really want to test. But your code has some errors:

    1. with tblsearch you search, if layer "99"/"10" exists. You get nil if not or the entitylist of the layer if it exists.

    2. <= comparse to values but you have only one. In this case, <= resp. >= always returns T (= true). So you get (and T T) and this is always true -> (alert "yes") is executed.

    Try this. You get an alert for each layer in the drawing wiht "yes" when its name is between 10 and 99

    (setq l (tblnext "LAYER" T))
    (while l
    (setq la (cdr (assoc 2 l)))
    (if (and (<= la "99") (>= la "10"))(alert (strcat la ": yes"))(alert (strcat la ": no")))
    (setq l (tblnext "LAYER"))
    )

    and with that you get one "yes" if at least one layer is between 10 and 99:

    (setq l (tblnext "LAYER" T) haveit nil)
    (while l
    (setq la (cdr (assoc 2 l)))
    (if (and (<= la "99") (>= la "10"))(setq haveit T))
    (setq l (tblnext "LAYER"))
    )
    (if haveit (alert "yes") (alert "no"))

    attention: aou also get "yes" if layer "9" exists, because string "9" is greater than string "10" !! To avoid this you must convert layer strings to numbers!
     
    bob.at, Apr 15, 2004
    #4
  5. jclaidler

    jclaidler Guest

    thanks for your help... I'm going to try to take the program into a different direction.
     
    jclaidler, Apr 15, 2004
    #5
  6. jclaidler

    Jamie Duncan Guest

    if layer 99 doesn't exist you get nil
    if layer 10 doesn't exist you get nil
    you haven't asked about any other layers - only these two.

    if they exist you get an entity name, not a string or integer.

    finally the if is incomplete - you are asking if this entity handle, if
    layer 99 exists is <= nothing - which will always be true.


    --
    Jamie Duncan

    "How wrong it is for a woman to expect the man to build the world she wants,
    rather than to create it herself."
    - Anais Nin (1903-1977)
     
    Jamie Duncan, Apr 16, 2004
    #6
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.