Hold String Message in Command Line for 5 Seconds

Hold String Message in Command Line for 5 Seconds

ebsoares
Collaborator Collaborator
1,053 Views
13 Replies
Message 1 of 14

Hold String Message in Command Line for 5 Seconds

ebsoares
Collaborator
Collaborator

Hi, all.

I would like to learn how to hold a string message on the command line (the main, active line) for a set time like, say, 5 full seconds.

I've used the "delay" command, as well as another set of code but it is not working as expected. Here are the code lines I have used so far.

Using "delay":

(defun C:test1 ()
    (princ "\nHold this message")
    (command "delay" 5000)
    (princ "\nEnd")
    (princ)
)

But the command line did the delay first, then the two "princ" lines (out of order then)...

 

I also found a different way to accomplish the delay without using the "command" function:

(defun C:test2 ()
    (princ "\nHold this message")
    (wait 5)
    (princ "\nEnd")
    (princ)
)
(defun wait (seconds / stop)
    (setq stop (+ (getvar "DATE") (/ seconds 86400.0)))
    (while (> stop (getvar "DATE")))
)

But the result was exactly the same. Here's what appeared on the command line:

Command: TEST2 <<this line was delayed for 5 seconds. Really, just "Command: TEST2" for 5 seconds>>
Hold this message
End
Command:

 

Do you see what I am doing wrong? I would like to have "Hold this message" delayed in the command line for 5 (or however many) seconds...

Thanks in advance!

0 Likes
Accepted solutions (1)
1,054 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

I don't know how much use this that I stumbled on will be to you, because while it seems to work as expected most of the time, it occasionally has the same problem you describe.

 

(defun C:test1 ()
  (prompt "\nHold this message")
  (princ)
  (setvar 'cmdecho 0)
  (command "delay" 5000)
  (setvar 'cmdecho 1)
  (princ)
  (prompt "\nEnd")
  (princ)
)

 

It doesn't seem to matter whether I use (prompt) or (princ), nor whether or not I shut off command echoing, but the extra (princ) functions seem to at least improve the percentage of times that it works, if that might give you some further direction.

Kent Cooper, AIA
Message 3 of 14

ebsoares
Collaborator
Collaborator

Thanks, @Kent1Cooper.

I used that code on my end and had mixed results as well - it randomly decided at which line to stop and hold... gotta love it when you can't know what AutoCAD will do with your code...

I put that whole code as you typed above in a "repeat" function, to repeat 10 times, on half a second loops, and it's almost funny that each time it was different 😂

Either way, it might not be a solution per se, but at least it should get a "kudos" 😉

Thanks a bunch, Kent!

0 Likes
Message 4 of 14

john.uhden
Mentor
Mentor

@ebsoares , @Kent1Cooper 

Try this one...

 

(defun @delay (seconds / *error* cmdecho start)
  (setq cmdecho (getvar "cmdecho")
        start (getvar "date")
  )
  (setvar "cmdecho" 0)
  (defun *error* (error)
    (setvar "cmdecho" cmdecho)
    (if error (princ error))
    (princ)
  )
  (while (< (* 86400 (- (getvar "date") start)) seconds)
    (command ".expert" (getvar "expert"))
  )
  (*error* nil)
)

 

John F. Uhden

Message 5 of 14

ebsoares
Collaborator
Collaborator

Hi, @john.uhden. Thanks for the different take on the issue!

Unfortunately the result is the same... sometimes it will hold the message in the command line, sometimes it won't - it's random too...

Thanks either way 👍

0 Likes
Message 6 of 14

Sea-Haven
Mentor
Mentor

It wont close but maybe Alert would be easier, (alert "press when ready\nLine2 \line3")

 

I use a dcl which displays a company logo etc then closes. The term_dialog is critical as it closes, Sorry it was Rlx or Ronjonp that helped me.

 

One option in a dcl is a text box 

 

 

(defun wait (sec / stop) (setq stop (+ (getvar "DATE") (/ sec 86400.0))) (while (> stop (getvar "DATE"))))

(defun Splash (w / dcl-fn dcl-fp dcl-id)
(vl-load-com)
(setq dcl-fp (open (setq dcl-fn (vl-filename-mktemp "" "" ".dcl")) "W"))
(write-line  "Hello : dialog {" dcl-fp)
(write-line (strcat "label = " (chr 34) "Alert" (chr 34) " ; ") dcl-fp)
(write-line "spacer_1 ;" dcl-fp)
(write-line ": text { " dcl-fp)
(write-line  (strcat "label = " (chr 34) msg (chr 34) ";") dcl-fp)
(write-line  "}" dcl-fp)
(write-line "spacer_1 ;" dcl-fp)
(write-line "spacer_1 ;" dcl-fp)
(write-line "ok_only ;" dcl-fp)
(write-line "}"  dcl-fp)
(close dcl-fp)
(setq dcl_id (load_dialog dcl-fn))
(if (not (new_dialog "Hello" dcl_id))
(exit)
)
(wait w)
(term_dialog)
(if dcl-id (unload_dialog dcl-id))
(vl-file-delete dcl-fn)
(princ)
)

(setq msg "a message from AlanH")
(splash 4)

 

 

0 Likes
Message 7 of 14

hmsilva
Mentor
Mentor
Accepted solution

@ebsoares wrote:

Hi, all.

I would like to learn how to hold a string message on the command line (the main, active line) for a set time like, say, 5 full seconds.

....


Something like this perhaps...

;;Ex (_pause 5 "Waiting 5 seconds...")
(defun _pause (time msg /)
  (setq date (getvar "date"))
  (acet-ui-progress-init msg 100)
  (while (> time (setq i (* 86400 (- (getvar "date") date))))
    (acet-ui-progress-safe (/ (* i 100) time))
  )
  (acet-ui-progress-done)
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 8 of 14

john.uhden
Mentor
Mentor
@hmsilva
That's pretty cool! Took me a while to find where it showed, but still
pretty keen.

John F. Uhden

0 Likes
Message 9 of 14

hmsilva
Mentor
Mentor

@john.uhden wrote:
@hmsilva
That's pretty cool! Took me a while to find where it showed, but still
pretty keen.

Thanks!

EESignature

0 Likes
Message 10 of 14

ebsoares
Collaborator
Collaborator

Ok... that was actually really cool! It is much better than what I asked for!

 

Thanks a bunch, @hmsilva!!!

Message 11 of 14

hmsilva
Mentor
Mentor

You're welcome, @ebsoares 
Glad I could help

Henrique

EESignature

0 Likes
Message 12 of 14

Sea-Haven
Mentor
Mentor

Another good acet function is progress bar.

 

Nothing happened in Bricscad using above

This works Autocad

(defun wait ()
(setvar "modemacro" "Put your message here")
(princ)
(command "delay" 5000)
(setvar "modemacro" " ")
)
(wait)

 

Message 13 of 14

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

....

...
(setvar "modemacro" "Put your message here")
(princ)
(command "delay" 5000)
(setvar "modemacro" " ")
....

 


Interesting concept, though it puts the message in a place people may not be as likely to notice [the status bar, rather than the command line].  BUT many people actually use the MODEMACRO System Variable to put information into the status bar [I have it set to display the positional Snap value when I have Snap turned on], so at the very least I would save the current contents first, and restore them later:

(defun wait (/ mm)
  (setq mm (getvar 'modemacro))
  (setvar 'modemacro "Put your message here")
  (command "_.delay" 5000)
  (setvar 'modemacro mm)
  (princ)
)

Consider adding command-echo suppression so you don't see the DELAY command go by in the command line.

 

But even then, I find it doesn't behave the same way every time.  The message sometimes doesn't appear right away, but only after 2 or 3 seconds.  But the total time from calling (wait) until the message goes away seems fairly consistent [in very limited trials].  That seems to be true of the original in Message 1, too, so this may not be an improvement.

Kent Cooper, AIA
Message 14 of 14

ebsoares
Collaborator
Collaborator

Thanks, @Sea-Haven, for the new approach. But like @Kent1Cooper said, it still has the same shortcomings caused by the uncertain "delay" command.

Still worth some kudos, though, as it showed me a cool new tool (modemacro) that has tons of potential!

Thanks, y'all!

0 Likes