Jump to content

Output to command line during code execution


Recommended Posts

Posted
51 minutes ago, jameslitvak said:

I'm not quite sure why you put the (terpri) lines in there, but they're doing nothing in the code.

I also wrote code using the terpri function many years ago so when switching to the Text Screen only lines output from my lisp was visible. It hasn't functioned like that for many versions of AutoCAD as it can no longer add multiple blank lines.

 

Lisp code often work different when replying to very old threads.

Posted (edited)

(terpri) starts a new line.

 

These all act the same.

(defun C:Scratch ()
  (prompt (strcat "Pre Loop " (itoa (getvar 'MILLISECS))))
  (princ)
  (command "_.delay" 2000) ;; delay for 2s
  (prompt (strcat "Post Loop " (itoa (getvar 'MILLISECS))))
  (princ)
)

(defun C:Scratch ()
  (prompt (strcat "Pre Loop " (itoa (getvar 'MILLISECS))))
  (terpri)
  (command "_.delay" 2000) ;; delay for 2s
  (prompt (strcat "Post Loop " (itoa (getvar 'MILLISECS))))
  (princ)
) 

(defun C:Scratch ()
  (prompt (strcat "Pre Loop " (itoa (getvar 'MILLISECS))))
  (command "_.delay" 2000) ;; delay for 2s
  (prompt (strcat "\nPost Loop " (itoa (getvar 'MILLISECS)))) ;\n starts new line
  (princ)
)

 

Edited by mhupp
  • Like 1
Posted

Makes sense. I only got into lisp programming about a decade ago. Like most people brand new to the language, I couldn't understand why (princ "Hello world!") resulted in Hello world!"Hello world!" on the command line. A quick search explained the concept of a function return, and suggested (terpri) to prevent the return from being displayed. Not sure how long after it was (although it was fairly quick), but I read elsewhere that (terpri) was basically a deprecated function, and that a simple (princ) at the end of a function would private a silent return. From that point I abandoned (terpri). I can see how others who have been programming with lisp much longer would keep using it out of habit. 

Posted
3 minutes ago, mhupp said:

These all act the same.

 

Interestingly, the first version, the one I shared, was the only one that was working for me before. However, now it is only working sometimes. Same goes for the others. So I am just as baffled as everyone else from four years ago why the pre-loop message doesn't display before the delay. 

Posted

Sometimes when trouble shooting/editing lisp to much stuff gets left in memory and starts acting weird. when that happens I usually save and exit out of the program and reopen. then stuff starts working like it should again.

 

: SCRATCH
Pre Loop 1782600171
: _.delay
Milliseconds to delay: 2000
Post Loop 1782602796

 

This isn't really user friendly its displaying two big numbers. Something you can read at a glance is better.

 

(defun C:Scratch (/ start end)
  (setq start (getvar "MILLISECS"))
  (setvar 'cmdecho 0)
  (command "_.delay" 2000) ;; delay for 2s
  (setq end (getvar "MILLISECS"))
  (setvar 'cmdecho 1)
  (prompt (strcat "\nLoop Time: " (itoa (- end start))))
  (princ)
)

 

: SCRATCH

Loop Time: 2609

Posted (edited)
On 11/16/2017 at 12:08 AM, BIGAL said:

My $0.05 you will see something happening.

 

Wow inflation has really hit big time, just last year it was 2¢

Edited by dan20047
  • Funny 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...