not or null who help

Discussion in 'AutoCAD' started by tader, Oct 29, 2004.

  1. tader

    tader Guest

    hi, couple of quest. this routine is supposed to check 2 endpoints of diff lines to see if they lie on the same point.

    (defun c:ce ()
    (setvar "cmdecho" 0)

    (while (not (setq ent (entsel "\nPick line 1 (near endpoint)"))))
    ;quest. if the "not" returns true if nothing's selected then y DOESN'T it quit the loop when nothing's selected?
    (setq z (car ent))
    (redraw z 3)
    (setq a (cdr ent)
    b (car a)
    end1 (osnap b "endp"))
    ; the following is where the prob is. if nothing's selected it's supposed to go to nothing selected.
    ; neither of the conditions work

    (while (or (equal z (setq ent1 (entsel "\nPick line 2 (near endpoint)")) (car ent1)) (not ent1)) ;or
    (alert
    (cond ((null ent1) "Nothing Selected")
    (T "You've Picked the same Line")
    );cond
    ) ;alert
    ) ;while


    (setq a1 (cdr ent1)
    b1 (car a1)
    end2 (osnap b1 "endp"))

    (if
    (equal end1 end2)
    (print "Endpoints are Equal")
    (progn
    (setq east (rtos (- (car end1) (car end2)) 2 4)
    north (rtos (- (cadr end1) (cadr end2)) 2 4)
    de (strcat "Diff E=" east)
    dn (strcat "Diff N=" north))
    (alert (strcat "Endpoints are Not Equal!!"
    "\n"de
    "\n"dn))))
    (redraw z 4)



    (princ)
    )

    TIA, Shawn
     
    tader, Oct 29, 2004
    #1
  2. tader

    tader Guest

    (while (not (setq ent (entsel "\nPick line 1 (near endpoint)"))))
    it quit the loop when nothing's selected?
    ***Because while continues as long as the test results in a non-nil value
    (including true).

    "while continues" does that mean that it exits the loop and continues to the next line? Or continues looping?
    If i understand correctly if I select nothing it will return a nil which "not" will return a "T" value and satisfy the loop; thereby continueing on with the remainder of the program. But this isn't what happens. If i click nothing it still asks to select line one. Don't get me wrong it acts correctly, I just don't understand why.

    The second loop still doesn't work.

    Shawn
     
    tader, Oct 29, 2004
    #2
  3. tader

    James Allen Guest

    Hi Shawn, see inline comments. HTH
    --
    James Allen, EIT
    Malicoat-Winslow Engineers, P.C.
    Columbia, MO

    diff lines to see if they lie on the same point.
    it quit the loop when nothing's selected?
    ***Because while continues as long as the test results in a non-nil value
    (including true).
    supposed to go to nothing selected.
    ***I haven't tested to see if there is more, but it looks like the whole
    setq statement should be in the (car ), like
    ***(equal z (car (setq ent1 (entsel "\nPick line 2 (near endpoint)"))))
     
    James Allen, Oct 29, 2004
    #3
  4. tader

    MP Guest

    (while
    (not ;--------------------------------------while I haven't picked
    anything....
    (setq ent ;---------------------------------keep trying to pick
    something....
    (entsel "\nPick line 1 (near endpoint)")
    )
    )
    ;------------------------------------------once I have picked something,
    i'm done in the loop
    )
    ;------------------------------------------and continue with the rest of
    the program

    the next line?

    no, continue doesn't mean exit the loop, it means continue the loop....
    :)
    continues looping
    in the case of the while function, satisfaction means keep looping
    "Keep looping while this is true"
    "as long as I keep getting satisfied by something I'll keep doing it"
    :)

    read the description of the while function in the help files, maybe that
    will clear it up

    it will continue looping as long as it's test is true
    which in your case is as long as you haven't picked something
    in other words your loop says,
    while I haven't picked something, keep trying to pick something
    as soon as I *have* picked something, then get out of the loop and
    continue with the rest of the program

    what happens. If i click nothing it still asks to > select line one. Don't
    get me wrong it acts correctly, I just don't understand why.
    hope that clarifys it
    Mark
     
    MP, Oct 29, 2004
    #4
  5. tader

    diemaker Guest

    while trUE, continUE

    The second loop doesn’t work because your comparing 3 things with the equal. This works:
    (or (equal Z (setq ENT1 (car (entsel "\nPick line 2 (near endpoint)"))))
    (not ENT1)
    ) ;or

    But if your only checking lines, don’t you want to make sure ENT is a line? Using osnap to get an endpoint is flaky because you could get either end depending on which side of middle you pick. You need to look into (entget (car (entsel)))
     
    diemaker, Oct 29, 2004
    #5
  6. tader

    tader Guest

    Thnx so much guys, I really appreciate your time.

    Shawn.
     
    tader, Oct 29, 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.