entsel help...

Discussion in 'AutoCAD' started by C Witt, Jun 29, 2004.

  1. C Witt

    C Witt Guest

    I have this snip of code..

    (while (or (= hatchObject nil)(/= (cdr (assoc 0 (entget hatchObject)))
    "HATCH"))
    (setq hatchObject (car (entsel "\nselect a hatch object: ")))
    )

    The problem being that, I want to add in the option of letting the user
    enter "N" as a valid responce to "select a hatch object:". but I don't
    want the user to be able to select more than one object..

    What should I be doing?
     
    C Witt, Jun 29, 2004
    #1
  2. C Witt

    Rudy Tovar Guest

    Example:

    (setq loop t)
    (prompt (strcat "\nCurrent Chamfer Dist1 = "(rtos (getvar "chamfera")
    (getvar"lunits") 4)", Dist2 = "(rtos (getvar "chamferb") (getvar"lunits")
    4)))
    (while loop
    (initget "d")
    (setq con1 (entsel"\nDistance<Select first line>:"))
    (if (or (= con1 "d")(= con1 "D"))
    (progn
    )
    )
    (if (or (= con1 nil)(= (type con1) 'LIST))(setq loop nil))
    )
    --

    AUTODESK
    Authorized Developer
    http://www.Cadentity.com
    MASi
     
    Rudy Tovar, Jun 30, 2004
    #2
  3. C Witt

    T.Willey Guest

    (initget "U")
    (setq ob1 (nentselp "\nSelect an annotation object or [Undo]:"))

    This is how I did it so that the user could type in "u" to do something.

    Tim
     
    T.Willey, Jun 30, 2004
    #3
  4. C Witt

    C Witt Guest

    (initget "d")

    how many initget options are there? (and were can i get a list of them?)

    Thanks, BTW.
     
    C Witt, Jun 30, 2004
    #4
  5. C Witt

    C Witt Guest

    nevermind ;P
     
    C Witt, Jun 30, 2004
    #5
  6. While I'm not certain of all the criteria for your
    application this is my favorite way to handle
    continuous prompting for selection until you are
    satisfied with the input. Hope this gives you some
    idea of how to proceed.


    (setvar "errno" 0)

    (while (/= 52 (getvar "errno"))

    ; not sure what the 'N' stands
    ; for in your post. Change all
    ; references accordingly.

    (initget "No-idea eXit")
    (setq result (entsel "\n[No-idea/eXit]select a hatch object <exit>: "))

    (cond

    ((= result "No-idea")
    (alert "doing No-idea stuff now")
    (setvar "errno" 52) )


    ; exit if the user keyed-in or
    ; used the right-click menu to
    ; select 'exit'

    ((= result "eXit") (setvar "errno" 52))


    ; didn't select anything

    ((= 7 (getvar "errno"))
    (princ "\nmiss pick")
    (setvar "errno" 0) )


    ; (and
    ; something was selected
    ; get the entity list
    ; is it a Hatch entity?
    ; )

    ((and
    result
    (setq data (entget (car result)))
    (= "HATCH" (cdr (assoc 0 data))) )

    (alert "doing HATCH stuff now")
    (setvar "errno" 52) )


    ; at this point, you already know
    ; something was selected otherwise
    ; 'data' would be nil.

    (data (princ "\nselection was not a hatch"))


    ; exit if the user accepted the
    ; default of <exit>

    (t nil)

    )
    )
     
    Jason Piercey, Jun 30, 2004
    #6
  7. C Witt

    Joe Burke Guest

    Hi Jason,

    Good stuff. Just one minor question. Does the cond (T nil) at the end serve some
    purpose here, given the fact cond returns nil when none of the previous conditions
    return T? I've seen this done in other programs posted here.

    Just curious...
    Joe Burke
     
    Joe Burke, Jun 30, 2004
    #7
  8. Hi Joe,

    Yes, it does serve a purpose.

    Run that code, a select something that is
    not a hatch, then press enter accepting
    the default of <exit>.

    Perhaps a more effcient way to handle it
    would be to (setq data nil) upon selecting
    something that isn't a hatch object.
     
    Jason Piercey, Jun 30, 2004
    #8
  9. Hmm... guess I'm "all wet" with part of that.
     
    Jason Piercey, Jun 30, 2004
    #9
  10. Ok! More coffee....

    If you were to change

    (data (princ "\nselection was not a hatch"))

    to

    (result (princ "\nselection was not a hatch"))

    then

    (t nil)

    does serve a purpose (I sure thought it did).


    So, for the sake of any lurkers and future readers.

    (setvar "errno" 0)

    (while (/= 52 (getvar "errno"))

    ; not sure what the 'N' stands
    ; for in your post. Change all
    ; references accordingly.

    (initget "No-idea eXit")
    (setq result (entsel "\n[No-idea/eXit]select a hatch object <exit>: "))

    (cond

    ((= result "No-idea")
    (alert "doing No-idea stuff now")
    (setvar "errno" 52) )


    ; exit if the user keyed-in or
    ; used the right-click menu to
    ; select 'exit'

    ((= result "eXit") (setvar "errno" 52))


    ; didn't select anything

    ((= 7 (getvar "errno"))
    (princ "\nmiss pick")
    (setvar "errno" 0) )


    ; (and
    ; something was selected
    ; get the entity list
    ; is it a Hatch entity?
    ; )

    ((and
    result
    (setq data (entget (car result)))
    (= "HATCH" (cdr (assoc 0 data))) )

    (alert "doing HATCH stuff now")
    (setvar "errno" 52) )


    ; at this point, you already know
    ; something was selected otherwise
    ; 'result' would of been addressed
    ; by the previous conditions.

    (result (princ "\nselection was not a hatch"))


    ; exit if the user accepted the
    ; default of <exit>

    (t nil)

    )
    )
     
    Jason Piercey, Jun 30, 2004
    #10
  11. Just because I like to talk to myself <g>
    it does appear that (t nil) could be
    omitted and it still functions the same.

    Thanks, Joe.
     
    Jason Piercey, Jun 30, 2004
    #11
  12. We're listening. <g>

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jun 30, 2004
    #12
  13. Good to know that I am not alone in my
    little padded room ;)
     
    Jason Piercey, Jun 30, 2004
    #13
  14. C Witt

    C Witt Guest

    thank you.
     
    C Witt, Jun 30, 2004
    #14
  15. You're welcome. Hope all of my gibberish
    didn't point you in the wrong direction.
     
    Jason Piercey, Jun 30, 2004
    #15
  16. Wish mine was padded.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jun 30, 2004
    #16
  17. C Witt

    Joe Burke Guest

    Jason,

    Sorry to leave you talking to yourself. Work has been crazy lately, leaving little
    time to play here.

    Joe Burke
     
    Joe Burke, Jun 30, 2004
    #17
  18. Same here, busy busy!.....
     
    Jason Piercey, Jun 30, 2004
    #18
  19. C Witt

    Joe Burke Guest

    Jason,

    Please bear with me. I'm a little unclear. Did we eventually decide (T nil) at the
    end of any cond statement is superfluous?

    Sorry if it looks like I'm nit picking posted code. Just trying to get a handle on
    what's efficient.

    Plus I'm in a weird time zone, HST. So I'm generally out-of-sync with activity here.

    Aloha
    Joe
     
    Joe Burke, Jul 1, 2004
    #19
  20. C Witt

    ECCAD Guest

    Joe,
    If you pick up the tab for plane, I'll jet out and tell ya what the (T nil) is all about.


    Ya, right. :)
    Bob
     
    ECCAD, Jul 1, 2004
    #20
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.