Batch Run lisps on multiple drawings

Batch Run lisps on multiple drawings

Joe.Gio
Advocate Advocate
4,822 Views
8 Replies
Message 1 of 9

Batch Run lisps on multiple drawings

Joe.Gio
Advocate
Advocate

Hi All,

I'm wondering if there's a lisp out there that will let me run an existing lisp I have on multiple drawings just be referencing it's command? It would be good if I could change the command name if I wanted to batch run another lisp or even run a couple at a time. I haven't been able to find anything that doesn't require a script or 3rd party program.

Thanks.

0 Likes
4,823 Views
8 Replies
Replies (8)
Message 2 of 9

xuantientutungXUK6E
Advocate
Advocate

add lisp to startup file cad, and  it  will run when drawing open.

after finish job. erase the code in startup file cad.

it is simple way i do know.

 

 

0 Likes
Message 3 of 9

maratovich
Advisor
Advisor

AutoViewport - Automatic creation layouts and viewport

Running a lisp is the built-in function of the program.

runlisp.png

 

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 4 of 9

Joe.Gio
Advocate
Advocate

Hi Maratovich,

I can't use a 3rd party piece of software, we're locked down here on what we can use so hoping to find a LISP solution.

Thanks.

0 Likes
Message 5 of 9

dbhunia
Advisor
Advisor

Do as below.......

   1.   First add your Existing LISP in Startup Suite.

   2.   Make a LISP file by placing the command (of Existing LISP) in sequential form as you want.

   3.   Then place that NEW command in the attached LISP Below (At Blue colored Line in LISP).

   4.   Now put all the Drawings in a single Folder & Run the attached LISP Below.

   5.   When the below LISP will ask for Folder then Select the folder containing all Drawings.

 

Do this all in SDI mode (ie. only single drawing should in open condition)....... else LISP will bounce.......

 

(defun C:TEST ( / sh folder folderobject result SDI_Val LISPI_Val Files_Folder n)
	(defun *error* ( msg )
		(vl-cmdf "SDI" SDI_Val)
		(vl-cmdf "LISPINIT" LISPI_Val)
		(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
			(princ (strcat "\nOops an Error : " msg " occurred."))
		)
		(princ)
	)
	(vl-load-com)
	(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
	(setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
	(vlax-release-object sh)
	(setq SDI_Val (getvar "SDI"))
	(setq LISPI_Val (getvar "LISPINIT"))
	(if folder
		(progn
			(vl-cmdf "SDI" 1)
			(vl-cmdf "LISPINIT" 0)
			(setq folderobject (vlax-get-property folder 'Self))
			(setq result (vlax-get-property FolderObject 'Path))
			(vlax-release-object folder)
			(vlax-release-object FolderObject)
			(setq Files_Folder (vl-directory-files result "*.dwg"))
			(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
			(setq n 0)
			(while (< n (length Files_Folder))
				(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
				(Place your command)
				(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
				(setq n (+ 1 n))
			)
			(vl-cmdf "SDI" SDI_Val)
			(vl-cmdf "LISPINIT" LISPI_Val)
		)
	)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
Message 6 of 9

xuantientutungXUK6E
Advocate
Advocate
(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")

these code is not run.

"y" command autocad can understand. 

0 Likes
Message 7 of 9

dbhunia
Advisor
Advisor

For the line.......

(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")

You use .......

(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")))

 

About the Code, this is a valid/working Code........ Did you check it properly..........

 

For trial Check the below code over multiple Drawings (into a Folder), only by selecting the Folder (containing the Drawings)......... This Code will draw a line from 0,0,0 to 1000,1000,1000 into each Drawing into the Folder.......

 

(defun C:TEST ( / sh folder folderobject result SDI_Val LISPI_Val Files_Folder n)
	(defun *error* ( msg )
		(vl-cmdf "SDI" SDI_Val)
		(vl-cmdf "LISPINIT" LISPI_Val)
		(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
			(princ (strcat "\nOops an Error : " msg " occurred."))
		)
		(princ)
	)
	(vl-load-com)
	(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
	(setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
	(vlax-release-object sh)
	(setq SDI_Val (getvar "SDI"))
	(setq LISPI_Val (getvar "LISPINIT"))
	(if folder
		(progn
			(vl-cmdf "SDI" 1)
			(vl-cmdf "LISPINIT" 0)
			(setq folderobject (vlax-get-property folder 'Self))
			(setq result (vlax-get-property FolderObject 'Path))
			(vlax-release-object folder)
			(vlax-release-object FolderObject)
			(setq Files_Folder (vl-directory-files result "*.dwg"))
			; (command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
			(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")))
			(setq n 0)
			(while (< n (length Files_Folder))
				(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
					(command "line" "0,0,0" "1000,1000,1000" "")
				(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
				(setq n (+ 1 n))
			)
			(vl-cmdf "SDI" SDI_Val)
			(vl-cmdf "LISPINIT" LISPI_Val)
		)
	)
)

 

You check you Attached lines into the Code.......

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 8 of 9

Joe.Gio
Advocate
Advocate

Hi Debashis,

 

Sorry for the late reply, for some reason I haven't been getting e-mail notifications when someone comments on this thread.

 

I tried you're code setting SDI to 1 at the start and I have my command LISP in my startup suite but it's not working. I get the following text:

 

Enter new value for SDI <1>: 1
Command: LISPINIT
Enter new value for LISPINIT <0>: 0
Command: save Save drawing as <\\Desktop\Test\Test (1).dwg>: \\Desktop\Test\Test (1).dwg A drawing with this name already exists.
Do you want to replace it? <N> Y
Command: fileopen
Enter name of drawing to open <\\Test\Test (1).dwg>: \\Desktop\Test\Test (1).dwg
Opening an AutoCAD 2013/LT 2013 format file.
Regenerating layout.

Command:

Command: BLOCKVISIBILITY Unknown command "BLOCKVISIBILITY". Press F1 for help.


Command: save Save drawing as <\\Test\Test (1).dwg>: \\Test\Test (1).dwg A drawing with this name already exists.
Do you want to replace it? <N> fileopen
Yes or No, please.

Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.A drawing with this name already exists.
Do you want to replace it? <N> A drawing with this name already exists.
Do you want to replace it? <N> *Cancel*
*Cancel*

 

I may have not set it up correctly as I'm unsure what you mean by your 2nd point when setting up the LISP.

 

Any thoughts on what I might be doing wrong? In your LISP I have my command as: (command "BLOCKVISIBILITY")

 

Thanks.

0 Likes
Message 9 of 9

dbhunia
Advisor
Advisor

As I get from your last post ....... you are going right way.......

 

And also the "TEST" LISP working good....... Use this.......

 

(defun C:TEST ( / sh folder folderobject result Files_Folder n)
	(defun *error* ( msg )
		(setvar "SDI" 0)
		(setvar "LISPINIT" 1)
		(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*"))
			(princ (strcat "\nOops an Error : " msg " occurred."))
		)
		(princ)
	)
	(vl-load-com)
	(setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ))
	(setq folder (vlax-invoke-method sh 'BrowseForFolder 0 "" 0 ))
	(vlax-release-object sh)
	(if folder
		(progn
			(setvar "SDI" 1)
			(setvar "LISPINIT" 0)
			(setq folderobject (vlax-get-property folder 'Self))
			(setq result (vlax-get-property FolderObject 'Path))
			(vlax-release-object folder)
			(vlax-release-object FolderObject)
			(setq Files_Folder (vl-directory-files result "*.dwg"))
			(command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
			(setq n 0)
			(while (< n (length Files_Folder))
				(command "fileopen" (strcat result "\\" (nth n Files_Folder)))
					(command "line" "0,0,0" "1000,1000,1000" "");;;This is an example...Place your command as you needed
				(vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
				(setq n (+ 1 n))
			)
			(setvar "SDI" 0)
			(setvar "LISPINIT" 1)
		)
	)
)

 

Only thing what I get ....... I think "BLOCKVISIBILITY" is called your customized LISP.......if so then you can not call it like (command "BLOCKVISIBILITY") from in side another LISP.......

 

Call it like Either (BLOCKVISIBILITY) or (C:BLOCKVISIBILITY) or (XXX:BLOCKVISIBILITY) from inside a LISP.......

 

Another thing set your Default SDI Mode to "0" and LISPINIT to "1".......

 

Otherwise post your customized LISP....... which you want to call from inside other LISP.......

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes