defaults in my lisp

Discussion in 'AutoCAD' started by sepult, Sep 15, 2004.

  1. sepult

    sepult Guest

    I am having a difficult time trying to understand the default option in a lisp.
    I have written a lisp that prompts the user for a block, or text. I would like the default to be text.

    I did not write a cond, just did it the easy way.
    Do I specify the default with (defun deflt)???

    here is the lower portion of the code:

    (initget "27 29 30 Dt")
    (if (setq ANS (getkword "\n27/29/30/Dt>: "))
    (if (= ANS "27")
    (command "._Insert" "M:/-ACAD/DFCM_SYM/N27" "r" "0" "_s" (getvar "UserR1"))
    (if (= ANS "29")
    (command "._Insert" "M:/-ACAD/DFCM_SYM/N29" "r" "0" "_s" (getvar "UserR1"))
    (if (= ANS "30")
    (command "._Insert" "M:/-ACAD/DFCM_SYM/N30" "r" "0" "_s" (getvar "UserR1"))
    (if (= ANS "Dt")
    (command "dtext" "r" "0" "")

    (Princ)

    )
    )
    )
    )
    )
    )
    Can someone explain??
    please?
     
    sepult, Sep 15, 2004
    #1
  2. sepult

    T.Willey Guest

    You could do it this way.

    (initget "27 29 30 Dt")
    (setq ANS (getkword "\n27/29/30/<Dt>: "))
    (if (not ANS)
    (setq ANS "Dt")
    )

    Then run the rest of you things after, and IMO I think a cond would be easier then what you have, and it might be a little bit faster.

    Tim
     
    T.Willey, Sep 15, 2004
    #2
  3. sepult

    Paul Turvill Guest

    Sorry, but multiple nested (if ...) statements are simply *not* the "easy"
    way.

    (initget "27 29 30 Dt")
    (setq ans (getkword "\n27/29/30/Dt: "))
    (cond
    ((= ans "27")(command "._Insert" "M:/-ACAD/DFCM_SYM/N27" "r" "0" "_s"
    (getvar "UserR1")))
    ((= ans "29")(command "._Insert" "M:/-ACAD/DFCM_SYM/N29" "r" "0" "_s"
    (getvar "UserR1")))
    ((= ans "30")(command "._Insert" "M:/-ACAD/DFCM_SYM/N30" "r" "0" "_s"
    (getvar "UserR1")))
    (T (command "_.dtext" "_r" "0" ""))
    )

    This snippet will insert the appropriate block for responses 27, 29, and 30;
    it will default to the DTEXT command if the user presses D, Dt or just ENTER
    (null response).
    ___
     
    Paul Turvill, Sep 15, 2004
    #3
  4. sepult

    Tom Smith Guest

    (initget "27 29 30 Dt")
    I agree, and if the all the answers except Dt use like-named blocks, you
    could add:

    (setq prefix "M:/-ACAD/DFCM_SYM/N")
    (if (= ANS "Dt")
    (command "dtext" "r" "0" "")
    (command "._Insert" (strcat prefix ans) "r" "0" "_s" (getvar
    "UserR1"))
    )

    I don't like long series of nearly identical if's. Unless the routine can be
    broken down to an either/or situation as above, I'd also lean toward a cond.
     
    Tom Smith, Sep 15, 2004
    #4
  5. sepult

    sepult Guest

    That works!
    I never would have thought of that.
    I am new to this, so mostly it's trial and error, with the help of ; you know what I mean.
    I tried the cond, but I would keep getting errors, so i just continued what worked.

    Thanks for your help.
     
    sepult, Sep 15, 2004
    #5
  6. sepult

    sepult Guest

    Paul, I tried that cond, but my downfall was starting with
    (cond
    (if(= ans "27")(command ".......
    Your code works great.
    Thanks so much for your help and speedy responses!!
     
    sepult, Sep 15, 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.