Add message box to lisp code

Add message box to lisp code

Mike_Y2
Advocate Advocate
1,634 Views
10 Replies
Message 1 of 11

Add message box to lisp code

Mike_Y2
Advocate
Advocate

Hi,

 

Apologies in advance... I have very little experience of writing lisp code...

 

I have the lisp code below that runs a script file. The script file take a few minutes to run and it is not obvious to the user when the script file has finished running.

 

How do I add a simple message box into the lisp code, that displays after the Script file has finished running??? 

 

(defun C:Run_Script ()
(if (findfile "C:/Block data/A2 Data Output/1 Data Output.scr")
(command "_script" "C:/Block data/A2 Data Output/1 Data Output.scr")
); end if
); end function

0 Likes
Accepted solutions (2)
1,635 Views
10 Replies
Replies (10)
Message 2 of 11

john.uhden
Mentor
Mentor

@Mike_Y2 ,

The simplest way is to use the (alert) function, as in...

(alert "You picked the wrong horse, idiot!")

The alert dialog stretches (to a point) to fit your full line of text into its width, but if you think or find that it doesn't, then you can break your line into two or more lines by adding "\n" for each line feed like...

(alert "There once was a girl named Bright\nWhose speed was much faster than light.\nShe set off one day,\nIn her usual way\nAnd returned on the previous night.")

BTW, "The Man from Nantucket" is NOT the same as "The young man from Pawtucket."

The former can be told in public, but the latter should probably be reserved for adult guys only.

John F. Uhden

0 Likes
Message 3 of 11

komondormrex
Mentor
Mentor
Accepted solution

hi,

try this

(defun C:Run_Script ()
(if (findfile "C:/Block data/A2 Data Output/1 Data Output.scr")
		(progn
			(command "_script" "C:/Block data/A2 Data Output/1 Data Output.scr")
			(alert "Script completed.")
		)
); end if
); end function
0 Likes
Message 4 of 11

Mike_Y2
Advocate
Advocate

@komondormrex  Thanks for giving me the full code. I have just tested it and the message box appear immediately (before the script file has finished running). Is there a way to alter the message box so it appears after the script file has completed?

0 Likes
Message 5 of 11

Moshe-A
Mentor
Mentor
Accepted solution

@Mike_Y2  hi,

 

it's true, AutoCAD runs the script that comes from lisp as the last command and all codes after will be in front (as you see 😀) the solution to this is to put the call to (alert) function message as  the last line in the script file.

 

Moshe

 

0 Likes
Message 6 of 11

john.uhden
Mentor
Mentor

@komondormrex ,

You could shorten that a little...

(defun C:Run_Script ( / file)
(if (setq file (findfile "C:/Block data/A2 Data Output/1 Data Output.scr"))
		(progn
			(command "_script" file)
			(alert "Script completed.")
		)
); end if
); end function

John F. Uhden

0 Likes
Message 7 of 11

komondormrex
Mentor
Mentor

hey Mike,

think this can work also. @john.uhden counted.

(defun C:Run_Script ()
	(if (setq file (findfile "C:/Block data/A2 Data Output/1 Data Output.scr"))
			(progn
				(command "_script" file)
				(vla-postcommand (vla-get-activedocument (vlax-get-acad-object)) (alert "Script completed."))
			)
	); end if
); end function

 

0 Likes
Message 8 of 11

john.uhden
Mentor
Mentor

@komondormrex ,

I counted what?

John F. Uhden

0 Likes
Message 9 of 11

komondormrex
Mentor
Mentor

@john.uhden 

your remark has been taken into account, thus you've been counted too. 

0 Likes
Message 10 of 11

john.uhden
Mentor
Mentor

@komondormrex ,

I am only one.

You have reminded me of an incident decades ago with a friend's very young twin brothers.

Mom had allowed them to have one M&M each.  One twin accused the other of taking two M&Ms.

The accused replied, "Hey, I only took one."  Then he opened his hand and said, "Here, count it!"

I laughed for days.

John F. Uhden

0 Likes
Message 11 of 11

Sea-Haven
Mentor
Mentor

You can also use Vslide for a fancy message with a Delay

 

(command "Vslide" "d:\\acadtemp\\yesitsfinished.sld")
(delay 1000)
(command "regen")

 

0 Likes