Displaying Messages

AutoCAD AutoLISP & Visual LISP

 
Displaying Messages
 
 
 

When entered from VLISP, the prompt function displays a message (a string) in the AutoCAD Command window and returns nil to the VLISP Console window. The princ, prin1, and print functions all display an expression (not necessarily a string) in the AutoCAD Command window and return the expression to the VLISP Console window. Optionally, these functions can send output to a file. The differences are as follows:

  • princ displays strings without the enclosing quotation marks.
  • prin1 displays strings enclosed in quotation marks.
  • print displays strings enclosed in quotation marks but places a blank line before the expression and a space afterward.

The following examples demonstrate the differences between the four basic output functions and how they handle the same string of text. If you enter the examples from VLISP, the text following prints is what you see at the AutoCAD Command prompt; text following returns appears within the VLISP Console window or within an application. See Control Characters in Strings for an explanation of the control characters used in the example.

(setq str "The \"allowable\" tolerance is \261 \274\"")
(prompt str)  printsThe "allowable" tolerance
is1/4"
and returns  nil
(princ str)   printsThe "allowable" tolerance
is1/4"
and returns  "The \"allowable\" tolerance is 1/4\""
(prin1 str)   prints"The \"allowable\"
tolerance is1/4""
and returns  "The \"allowable\" tolerance is  1/4\""
(print str)   prints<blank line>
      "The \"allowable\"
tolerance is
      1/4""
      <space>
    
and returns  "The \"allowable\" tolerance is  1/4\""

Note that the write-char and write-line functions can also display output to a Command window. Refer to the AutoLISP Reference for information on these functions.