prints twice on command line

Discussion in 'AutoCAD' started by dflynn0001, Jun 2, 2004.

  1. dflynn0001

    dflynn0001 Guest

    Below is a lisp program that finds the area bounded by different crossing objects. It puts the answer in an alert message (this part works fine) and then displays the answer again in the command line (so I can cut and paste the answer), this is where the problem lies, it prints it twice. I have tried "print" "princ" etc., nothing seems to make a difference. Any suggestions? Here's the code. Thanks. Don

    (defun c:ae (/ pnt1 area1 text1 text2)
    (setq pnt1 (getpoint "\nPick Point in Void To Find Area... "))
    (command "color" 2)
    (command "-boundary" pnt1 "")
    (command "_area" "object" "l")
    (setq area1 (getvar "area"))
    (command "color" "bylayer")
    (setq text1
    (strcat
    "The Void Area You Were Looking For Is... "
    (rtos area1)
    " sq. ft. \n\n or "
    (rtos (/ area1 43560))
    " acres"
    )
    )
    (setq text2 (strcat "The Void Area Is... "
    (rtos area1)
    " sq. ft. or "
    (rtos (/ area1 43560))
    " acres"
    )
    )
    (alert text1)
    (command "erase" "l" "")
    (print_text)
    )

    (defun print_text ()
    (princ text2)
    )
     
    dflynn0001, Jun 2, 2004
    #1
  2. dflynn0001

    andywatson Guest

    This is from the Visual Lisp Developer's Guide:

    If you invoke the princ function without passing an expression to it, it displays nothing and has no value to return. So if you write an AutoLISP expression that ends with a call to princ without any arguments, the ending nil is suppressed (because it has nothing to return). This practice is called exiting quietly.

    Basically, the very last line in your code should be simply:
    (princ)
    ...this would go below your "(print_text..." line.
     
    andywatson, Jun 2, 2004
    #2
  3. dflynn0001

    ECCAD Guest

    Change:
    (alert text1)
    (command "erase" "l" "")
    (print_text)
    .. to
    (alert text1)
    (command "erase" "l" "")
    (print_text)
    (princ)

    Bob
     
    ECCAD, Jun 2, 2004
    #3
  4. dflynn0001

    dflynn0001 Guest

    Thank you both, this is so much easier than trial and error. I appreciate your time. Don
     
    dflynn0001, Jun 3, 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.