LISP script giving me double return value

Discussion in 'AutoCAD' started by Scott B, Oct 8, 2004.

  1. Scott B

    Scott B Guest

    Hi all, I have banged my head against the wall trying to figure out
    what the heck is going on with my script, but to no avail. All I want
    is for this script to have as a return value "PORTTRAI" or "LANDSCAPE"
    (without the quotes).
    Instead, I get anything but, depending on the specifics of the coding.
    The closest I can get it is to output PORTRAIT"PORTRAIT" or
    LANDSCAPE"LANDSCAPE"
    WTF?! I guess I'm just not understanding how LISP (or AutoLISP more
    specifically) returns funtion values to the command line.
    Here's my code:

    ; Define the function (the program).
    (defun c:ORIENT ( / LMAX LMIN OLDCE OLDTE X1 Y1 RES)
    ; Save the current value of cmdecho then redefine it.
    (setq OLDCE (getvar "cmdecho"))
    (setvar "cmdecho" 1)
    ; Save the current value of texteval then set it to 1
    (setq OLDTE (getvar "texteval"))
    (setvar "texteval" 1)

    ; OPERATION - store the result in LMAX.
    (setq LMAX (GETVAR "EXTMAX"))

    ; OPERATION - store the result in LMIN.
    (setq LMIN (GETVAR "EXTMIN"))

    (setq x1 (- (car LMAX) (car LMIN)))
    (setq y1 (- (cadr LMAX) (cadr LMIN)))

    (if (< x1 y1) (setq res "PORTRAIT") (setq res "LANDSCAPE"))

    ; Reset "cmdecho" to previous value.
    (setvar "cmdecho" OLDCE)
    ; Reset "texteval" to previous value.
    (setvar "texteval" OLDTE)
    ; Reset *error* to previous definition.

    (princ res)
    )

    Basically, I want the plain text string outputted so that I can
    transparently call it from a scripted plot command, so it will
    automatically plot according to what the drawings dimensions are.
    I won't go into too much detail here, since it seems as though this is
    just a basic Autolisp question.
    How do I have the value of my "orient" function be just PORTRAIT or
    LANDSCAPE, without doing this strange double thing?
    Thanks for any help!
    Scott
     
    Scott B, Oct 8, 2004
    #1
  2. Scott B

    Paul Turvill Guest

    Add another (princ) at the end:

    ....
    (princ res)
    (princ)
    )
    ___
     
    Paul Turvill, Oct 8, 2004
    #2
  3. Scott B

    Scott B Guest

    Hi Paul,
    Thanks for the info. That's weird, I could swear up and down that I
    tried that, but apparently not. Now it works. That is, it works like
    I thought I wanted it to work.
    What I am trying to do here is to be able to type "'orient" at the
    orientation prompt of the -plot text dialog, and have it in essence
    "type in" the portrait/landscape setting for me, depending on the
    drawing extents. Does this make sense? So, I type "'orient" (without
    the double quotes, but with the single quote, which, if I am correct,
    is supposed to run a lisp command transparently, yes?), but the same
    orientation prompt keeps getting slung back at me, with no apparent
    effect.
    Interestingly, when I type (setq var1 orient) at the autocad prompt, I
    get nil as a response. the variable var1 is subsequently equal to
    nil, so it seems as though the return value of "orient" is still nil,
    even though it now correctly echos the text string I want when I run
    it alone. Am I simply doing this wrong? (I am a lisp beginner).
    Thanks again.
    Scott
     
    Scott B, Oct 8, 2004
    #3
  4. Scott B

    Paul Turvill Guest

    Nope. LISP commands don't run transparently. Only specified "native"
    commands.

    In order to do what you're describing, your best bet would be to use LISP to
    redefine the PLOT command, and include your "orient" routine as a
    subroutine. Then there's no need for the mixing of script, LISP and typing
    required to get the required inputs:

    (command "_.undefine" "PLOT")
    (defun C:pLOT (/ ...)
    (<<your custom orientation and PLOT routine goes here>>)
    )

    ___
     
    Paul Turvill, Oct 8, 2004
    #4
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.