Beginner LISP question

Discussion in 'AutoCAD' started by Xolo, Sep 16, 2004.

  1. Xolo

    Xolo Guest

    Hey there,

    Kind of a stupid question, but I don't have my LISP reference material in
    front of me right now.....If I'm adding a distance to a variable, how can I
    use the user input to allow that distance to be the default for another
    variable....

    EG.

    (setq shlod (getreal "\nWhat is the distance of this thingie?: ")
    hod (getreal "\nWhat is the distance of this other thingie?" )

    I want hod to give the user the option to enter a number or just hit enter
    to allow 'hod' to be equal to 'shlod'.......I can't pick this out of my
    brain for some reason, but I know I have examples of this on my other
    computer (which I don't have access to right at the moment).

    Thanks for the info and help,

    Xolo
     
    Xolo, Sep 16, 2004
    #1
  2. Xolo

    Xolo Guest

    Witt,

    Will this show the previous number inserted in the command line? Like this;

    What is the distance of this other thingie?: <input1>

    That's kind of what I'm looking for, to have the default in the brackets
    (like AutoCAD commands have) but still allow to have a different input
    allowed.

    Thanks for the start,

    Xolo

    (if (= hod nil)(setq hod shlod))?
     
    Xolo, Sep 16, 2004
    #2
  3. Xolo

    C Witt Guest

    (if (= hod nil)(setq hod shlod))?
     
    C Witt, Sep 16, 2004
    #3
  4. Xolo

    T.Willey Guest

    (setq shlod (getreal "\nWhat is the distance of this thingie?: ")
    hod (getreal "\nWhat is the distance of this other thingie? or enterfor same value." )
    (if (not hod)
    (setq hod shlod)
    )

    Tim
     
    T.Willey, Sep 16, 2004
    #4
  5. Xolo

    C Witt Guest

    (setq shlod (getreal "\nWhat?: ")
    hod (getreal (strcat "\nWhat2? < " (rtos shlod) ">")))
    )
    (if (= hod nil)(setq hod shlod))
     
    C Witt, Sep 16, 2004
    #5
  6. Something like:

    (setq shlod (getreal "\nWhat is the distance of this thingie?: ")
    hod (getreal (strcat "\nWhat is the distance of this other thingie? <"
    shlod ">: "))
    )
    (if (= hod nil)(setq hod shlod))

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Sep 16, 2004
    #6
  7. Xolo

    C Witt Guest

    one to many ")"..

    (setq shlod (getreal "\nWhat?: ")
    hod (getreal (strcat "\nWhat2? < " (rtos shlod) ">"))
    )
    (if (= hod nil)(setq hod shlod))
     
    C Witt, Sep 16, 2004
    #7
  8. C. Witt beat me to it, and is correct that it should be (rtos shlod)
    concatenated into the middle of the prompt, not just shlod as I did too
    hastily.

    Kent Cooper, AIA


    ...
     
    Kent Cooper, AIA, Sep 16, 2004
    #8
  9. Xolo

    Tom Smith Guest

    Use a global variable (one not declared loacl) to store a value in the
    drawing till the routine is run again. You'll need to set it to a fall-back
    default the first time it's used. Then you can feed that to the next prompt.

    (defun c:testing (/ shold hod)
    ;set sholddefault to default <number> if it's nil
    (if (not sholddefault)
    (setq sholddefault <number>)
    )

    ;set shold to sholddefault on a null response
    (if (not (setq shold (getreal (strcat "\nFirst distance <" (rtos
    sholddefault) ">: "))))
    (setq shold sholddefault)
    )

    ;use shold as default for hod
    (if (not (setq hod (getreal (strcat "\nSecond distance <" (rtos shold)
    ">: "))))
    (setq hod shold)
    )

    ;save sholddefault for future use
    (setq sholddefault shold)

    ;show input
    (print shold)
    (print hod)
    (princ)
    )
     
    Tom Smith, Sep 16, 2004
    #9
  10. Xolo

    Xolo Guest

    Hey Witt,

    Seems there's still some distance to go on that one.....it keeps giving me
    the;

    an error has occurred inside the *error* functionAutoCAD variable setting
    rejected: "CMDECHO" nil

    It keeps breaking at the < " (rtos shlod) ">")) part.....am I missing
    something? Should there be another something or other??

    Xolo

    one to many ")"..

    (setq shlod (getreal "\nWhat?: ")
    hod (getreal (strcat "\nWhat2? < " (rtos shlod) ">"))
    )
    (if (= hod nil)(setq hod shlod))
     
    Xolo, Sep 16, 2004
    #10
  11. Xolo

    Xolo Guest

    Tom,

    You've gone too far....I just want the variable local for the running of the
    routine. I don't need it to be global for re-running the routine, but thanks
    for going the extra distance,

    Xolo

    "Tom Smith" <nospam> wrote in message Use a global variable (one not declared loacl) to store a value in the
    drawing till the routine is run again. You'll need to set it to a fall-back
    default the first time it's used. Then you can feed that to the next prompt.

    (defun c:testing (/ shold hod)
    ;set sholddefault to default <number> if it's nil
    (if (not sholddefault)
    (setq sholddefault <number>)
    )

    ;set shold to sholddefault on a null response
    (if (not (setq shold (getreal (strcat "\nFirst distance <" (rtos
    sholddefault) ">: "))))
    (setq shold sholddefault)
    )

    ;use shold as default for hod
    (if (not (setq hod (getreal (strcat "\nSecond distance <" (rtos shold)
    ">: "))))
    (setq hod shold)
    )

    ;save sholddefault for future use
    (setq sholddefault shold)

    ;show input
    (print shold)
    (print hod)
    (princ)
    )
     
    Xolo, Sep 16, 2004
    #11
  12. Xolo

    Tom Smith Guest

    No prob, maybe I read too much into it. The best interface depends on the
    application.

    Sometimes you always want the same default -- in which case you'd eliminate
    my sholddefault and simply replace it with the fixed <number>. In other
    cases, users will prefer having the last number they used as the default,
    the next time they run the routine.

    Save it away, sooner or later you'll have the second scenario to deal with
    :)
     
    Tom Smith, Sep 16, 2004
    #12
  13. Xolo

    C Witt Guest

    the code works here.. i don't know why you would be getting an error..
    not to mention that error.. (we aren't even using cmdecho here..)
     
    C Witt, Sep 16, 2004
    #13
  14. Xolo

    C Witt Guest

    don't know if it matters.. but what version of cad are you using?
     
    C Witt, Sep 16, 2004
    #14
  15. Xolo

    Xolo Guest

    Witt,

    Using AutoCAD 2002.....would that make a huge difference?

    Xolo
    don't know if it matters.. but what version of cad are you using?
     
    Xolo, Sep 16, 2004
    #15
  16. Xolo

    Xolo Guest

    Tom,

    True enough....I've been thinking about a routine that I would like to have
    that happen exactly what you described, but I'd run it from a DCL dialog and
    therefore the code would be a lot different.

    Xolo
    "Tom Smith" <nospam> wrote in message No prob, maybe I read too much into it. The best interface depends on the
    application.

    Sometimes you always want the same default -- in which case you'd eliminate
    my sholddefault and simply replace it with the fixed <number>. In other
    cases, users will prefer having the last number they used as the default,
    the next time they run the routine.

    Save it away, sooner or later you'll have the second scenario to deal with
    :)
     
    Xolo, Sep 16, 2004
    #16
  17. Xolo

    Xolo Guest

    Oops, sorry Witt,

    Just run load & run the Vessel.lsp and the others will run automatically
    (called out) without having to load them too as long as they are all in a
    supported file path.

    Xolo
    don't know if it matters.. but what version of cad are you using?
     
    Xolo, Sep 16, 2004
    #17
  18. Xolo

    C Witt Guest

    in vessel.lsp
    change these 2 lines:
    OD (getdist "\nEnter the outside diameter of the head in inches: <"
    (rtos shlod) ">")
    HTHK (getdist "\nEnter the thickness of the vessel head in inches: <"
    (rtos shlthk) ">")

    to this:
    OD (getdist (strcat "\nEnter the outside diameter of the head in inches:
    <" (rtos shlod) ">"))
    HTHK (getdist (strcat "\nEnter the thickness of the vessel head in
    inches: <" (rtos shlthk) ">"))


    you didn't add in the strcat part..
     
    C Witt, Sep 16, 2004
    #18
  19. Xolo

    Xolo Guest

    Witt,

    I knew it was something small and simple, but as always, I overlook the
    obvious....thanks.

    Xolo
    in vessel.lsp
    change these 2 lines:
    OD (getdist "\nEnter the outside diameter of the head in inches: <"
    (rtos shlod) ">")
    HTHK (getdist "\nEnter the thickness of the vessel head in inches: <"
    (rtos shlthk) ">")

    to this:
    OD (getdist (strcat "\nEnter the outside diameter of the head in inches:
    <" (rtos shlod) ">"))
    HTHK (getdist (strcat "\nEnter the thickness of the vessel head in
    inches: <" (rtos shlthk) ">"))


    you didn't add in the strcat part..
     
    Xolo, Sep 16, 2004
    #19
  20. Xolo

    David Bethel Guest

    ;|I think I'd used (initget) & (getdist) calls|;

    (defun gethod (/ def)
    (setq def 10)
    (initget 7)
    (setq shlod (getdist "\n1st Thing: "))
    (initget 6)
    (setq hod (getdist (strcat "\n2nd Thing <" (rtos def 2) ">: ")))
    (and (not hod)
    (setq hod shlod)))


    ;|-David
     
    David Bethel, Sep 16, 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.