My First Real Lisp Routine

Discussion in 'AutoCAD' started by John, Apr 30, 2004.

  1. John

    John Guest

    This is my first routine with help from this NG. the routine work great but
    I have a question.
    When it ask for plot scale and if i just hit enter nothing happing:
    Command: splot
    Plot Scale: Full/Half/Quarter/<Full>:
    Command:

    I thougth I don't have to type "full" if want to plot full scale since it in
    <full>

    If type full it work great.... Any idea? Thank you for your help.

    (defun C:SPlot ()
    (setvar "CMDECHO" 1)
    (initget "Full Half Quarter")
    (setq type (getkword "\nPlot Scale: Full/Half/Quarter/<Full>: "))
    (cond
    ((= type "Full") (command "plot" "no" "" "1050C (24X36)" "" "n" "n" "y"))
    ((= type "Half") (command "plot" "no" "" "1050C (18X24)" "" "n" "n" "y"))
    ((= type "Quarter") (command "plot" "no" "" "1050C (12X18)" "" "n" "n"
    "y"))
    )
    (princ)
    )
     
    John, Apr 30, 2004
    #1
  2. John,

    Here is my favorite way to handle that. That happens because (getkword)
    returns nil if only <Enter> is hit.

    BTW, "type" is a bad idea for a variable name. That duplicates a function
    name. It is also not very descriptive.

    (initget "Full Half Quarter")
    (setq plotType (cond ((getkword "\nPlot Scale: Full/Half/Quarter/<Full>:
    ")) ("Full")))


    P.S. Localize those variables!

    --
    R. Robert Bell


    This is my first routine with help from this NG. the routine work great but
    I have a question.
    When it ask for plot scale and if i just hit enter nothing happing:
    Command: splot
    Plot Scale: Full/Half/Quarter/<Full>:
    Command:

    I thougth I don't have to type "full" if want to plot full scale since it in
    <full>

    If type full it work great.... Any idea? Thank you for your help.

    (defun C:SPlot ()
    (setvar "CMDECHO" 1)
    (initget "Full Half Quarter")
    (setq type (getkword "\nPlot Scale: Full/Half/Quarter/<Full>: "))
    (cond
    ((= type "Full") (command "plot" "no" "" "1050C (24X36)" "" "n" "n" "y"))
    ((= type "Half") (command "plot" "no" "" "1050C (18X24)" "" "n" "n" "y"))
    ((= type "Quarter") (command "plot" "no" "" "1050C (12X18)" "" "n" "n"
    "y"))
    )
    (princ)
    )
     
    R. Robert Bell, Apr 30, 2004
    #2
  3. John

    PG. Guest

    Programmer should handle this situation.

    (initget "Full Half Quarter")
    (setq type (getkword "\nPlot Scale: Full/Half/Quarter/<Full>: "))
    (if (= type nil)
    (setq type "Full")
    )
     
    PG., Apr 30, 2004
    #3
  4. John

    Jamie Duncan Guest

    Hey John,

    here is another approach that uses assoc and lists.


    (defun c:splot (/ the_list the_choice the_plot)
    (setvar "cmdecho" 0)
    (initget "Full Half Quarter")
    (setq the_list (list (cons "Full" "1050C (24X36)" )
    (cons "Half" "1050C (18X24)" )
    (cons "Quarter" "1050C (12X18)" )
    )
    the_choice (cond ((getkword "\nPlot Scale: Full/Half/Quarter/<Full>:"))
    ("Full"))
    )
    ;;;(princ the_list)
    (command "-plot" "no" (cdr (assoc the_choice the_list)) "n" "n" "y")
    (setvar "cmdecho" 1)
    (princ)
    )

    note the -plot so that the command line version of plt will run.

    as well returns cmdecho to on

    Jamie Duncan
     
    Jamie Duncan, Apr 30, 2004
    #4
  5. John

    Rudy Tovar Guest

    Just in case you didn't understand Robert about the localize variables. He's
    talking about when ever you use a variable to cancel it out or it will
    remain global.

    (defun c:<name> (/ <variable1> <variable2>) <--

    By localize, it will be made nil or without face value that you've assigned.
    Or pay the consequences later should you ever use the same variable or use
    too many, and limit your memory node space. Also don't use reserved
    variables assigned by visual lisp 'type' is one and so is 'T'. Use the
    'vlide' editor so you can see which are reserved and which are not. by
    default within the visual lisp editor they are color coated blue, strings
    are red and variables are black.
    --

    AUTODESK
    Authorized Developer
    http://www.Cadentity.com
    MASi
     
    Rudy Tovar, Apr 30, 2004
    #5
  6. John

    Jamie Duncan Guest

    Or, even more interesting:


    (defun c:splot (/ the_list the_choice the_plot)
    (setvar "cmdecho" 0)
    (initget "Full Half Quarter")
    (setq the_list (list (cons "Full" "1050C (24X36)" )
    (cons "Half" "1050C (18X24)" )
    (cons "Quarter" "1050C (12X18)" )
    (cons nil "1050C (24X36)" )
    )
    the_choice (getkword "\nPlot Scale: Full/Half/Quarter/<Full>:")
    )
    (command "-plot" "no" (cdr (assoc the_choice the_list)) "n" "n" "y")
    (setvar "cmdecho" 1)
    (princ)
    )


    neat eh? Not one conditional.


    Jamie Duncan
     
    Jamie Duncan, Apr 30, 2004
    #6
  7. John

    Jürg Menzi Guest

    John

    (defun C:SPlot ( / type)
    (setvar "CMDECHO" 1)
    (initget "Full Half Quarter")
    (setq type (getkword "\nPlot Scale: Full/Half/Quarter/<Full>: "))
    ;;;If you've A2k+ and prefer to use the right click context:
    ;;;(setq type (getkword "\nPlot Scale [Full/Half/Quarter] <Full>: "))
    (cond
    ((= type "Half") (command "plot" "no" "" "1050C (18X24)" "" "n" "n" "y"))
    ((= type "Quarter") (command "plot" "no" "" "1050C (12X18)" "" "n" "n" "y"))
    (T (command "plot" "no" "" "1050C (24X36)" "" "n" "n" "y"))
    )
    (princ)
    )

    This small changements will help...

    Cheers
     
    Jürg Menzi, May 1, 2004
    #7
  8. John

    Juerg Menzi Guest

    John

    (defun C:SPlot ( / type)
    (setvar "CMDECHO" 1)
    (initget "Full Half Quarter")
    (setq type (getkword "\nPlot Scale: Full/Half/Quarter/<Full>: "))
    ;;;If you've A2k+ and prefer to use the right click context:
    ;;;(setq type (getkword "\nPlot Scale [Full/Half/Quarter] <Full>: "))
    (cond
    ((= type "Half") (command "plot" "no" "" "1050C (18X24)" "" "n" "n" "y"))
    ((= type "Quarter") (command "plot" "no" "" "1050C (12X18)" "" "n" "n" "y"))
    (T (command "plot" "no" "" "1050C (24X36)" "" "n" "n" "y"))
    )
    (princ)
    )

    This small changements will help...

    Cheers
     
    Juerg Menzi, May 3, 2004
    #8
  9. John

    John Guest

    Thank you for your reply. I was testing these codes at coomand line but I'm
    getting this result

    Command: _.PAGESETUP
    Command: Specify opposite corner:
    Command: (defun c:splot (/ the_list the_choice the_plot)
    (_> (setvar "cmdecho" 0)
    (_> (initget "Full Half Quarter")
    (_> (setq the_list (list (cons "Full" "1050C (24X36)" )
    (((_> (cons "Half" "1050C (18X24)" )
    (((_> (cons "Quarter" "1050C (12X18)" )
    (((_> (cons nil "1050C (24X36)" )
    (((_> )
    ((_> the_choice (getkword "\nPlot Scale: Full/Half/Quarter/<Full>:")
    ((_> )
    (_> (command "-plot" "no" (cdr (assoc the_choice the_list)) "n" "n" "y")
    (_> (setvar "cmdecho" 1)
    (_> (princ)
    (_> )
    C:SPLOT

    Command: splot

    Plot Scale: Full/Half/Quarter/<Full>:
    Unknown command "N". Press F1 for help.
    Unknown command "N". Press F1 for help.
    Unknown command "Y". Press F1 for help.
     
    John, May 3, 2004
    #9
  10. John

    John Guest

    Thank you all for your reply. I've decided to give it a try all codes.

    John
     
    John, May 3, 2004
    #10
  11. John

    Jamie Duncan Guest

    the queries for the plot command vary according to the setting of the expert
    sysvar. I would suggest you decide on an expert setting, run the command in
    commandline mode (-plot) and record all the yesses and nos, and then adjust
    accordingly.

    Also there should be a test whether the layout you want actually exists.

    I would look under help for the command tblsearch .

    Hope this helps.

    oh, and for the expert variable, you could save it at the beginning
    (setq my_expert (getvar "expert")) (setvar "expert" 'the value you want')

    then at the end of the routine

    (setvar "expert" my_expert)
    (princ)
    )


    just like the cmdecho var.


    Jamie Duncan
     
    Jamie Duncan, May 3, 2004
    #11
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.