how to execute lisp over multiple drawings

how to execute lisp over multiple drawings

Anonymous
Not applicable
10,508 Views
31 Replies
Message 1 of 32

how to execute lisp over multiple drawings

Anonymous
Not applicable

TEMPLATE BEFORE USING LISP LOOKS LIKE THIS template.PNG

 

AFTER GIVING LISP COMMAND THIS DIALOGUE WILL OPEN

DIALOGUE BOX.PNG

 

THE OUTPU WILL BE LIKE THISCHECK.PNG

 

Finally What my aim is to change this similar templates in multiple drawings in one folder as per input given in dialogue box at a time..

please help me

0 Likes
10,509 Views
31 Replies
Replies (31)
Message 2 of 32

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

to run a series of commands on a list of drawings you can use >> script pro 2.0 << but i think the lisp to invoked should not have a dialog box interface (cause the script can not be paused) but run from command line or make a none interface version of your lisp.

 

moshe

 

0 Likes
Message 3 of 32

doaiena
Collaborator
Collaborator

I think >>this<< will solve your problem, but as @Moshe-A  mentioned, you should get rid of the UI and supply your data as arguments to the function. An even better way of batch processing of *.dwg files is by using .NET and writing a plugin to edit the database.

0 Likes
Message 4 of 32

Anonymous
Not applicable

Multi-batch is another program for working with batch files. The program can open a drawing, call the lisp, run the lisp and then save,close and go on to the next drawing.  I have used it for about two months now and have been happy with it. 

 

Here's the link:  http://www.multi-batch.com/

 

 

0 Likes
Message 5 of 32

dbhunia
Advisor
Advisor

You assign a counter with preset value and then change the counter value at the time of closing each drawing (while you looping through the drawings).

 

Now make a condition into your LISP if the counter is your preset value (it will happened only 1st time) then LISP will call the DCL & stores all the user inputs (into DCL) into variables Else LISP will not call the DCL only use the stored values into the variables through out the rest drawings.

 

 

 


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

Anonymous
Not applicable

Can you please tell me briefly...

I can't catch ur point... @dbhunia 

0 Likes
Message 7 of 32

dbhunia
Advisor
Advisor

For demonstration purpose I used a code from <<HERE>> ....... check the link.......

 

And added a DCL for demonstration only into that LISP ...... the DCL will ask for user input....... after that it will show the values as alert message for each drawing.......

 

 

 


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

pbejse
Mentor
Mentor

@Anonymous wrote:

Finally What my aim is to change this similar templates in multiple drawings in one folder as per input given in dialogue box at a time..

please help me


 

This helpful tip comes from Andrea Andreetti.

I've seen many AutoCAD users try to run LISP in batches. Some have created huge tools
or used script, opening their drawings one by one, which wastes time. Some use ODBX,
which I think is good but limited. Then there is my contribution: Why not use the Publish command?
Yes, you can do just about whatever you want using the Publish command. Just write your desired
commands in a LISP file, then put the LISP file in the Appload Startup Suite, and run Publish
with any configuration you want. I use DWF to prevent wasting paper. Be sure to remove your LISP
from the Startup Suite when you have finished. You can also purge, create objects, add blocks,
etc., and because you are using Publish, you can get a print of the document at the same time.
At the end of your LISP code be sure to save the drawing file with this code:

     (vl-cmdf "._qsave")

That’s it! Enjoy!

Now, all you need is a working version of your code your golden. Smiley Very Happy

 

 

 

 

Message 9 of 32

Anonymous
Not applicable

I don't want lisp,, but I wanna learn and teach...

My exact aim is...

If you see the Title block what I posted earlier..

which contains info about "job no"  "date" "phase no" "detailer" etc.....

When  I will do a new job the total tiltle block info will be changed...

Please find the attached lisp,dcl and drawing... which I wrote to change the INFO of my opened drawing (ATTACHED)..

NOW what I want to do is...

STEP1 : INITIALLY SHOULD OPEN A DRAWING OTHERTHAN DWG. FOR DESTINATION FOLDER.

STEP2 : WHEN I GIVE COMMAND "TEMP"... A DIALOGUE OPEN AND ASKS FOR INPUT... 

STEP3: AFTERCLICK "RUN" IT SHOULD ASK FOR  SELECT A DRAWING FROM FOLDER (folder contains drawings in which title block to be updated as per input in dcl)

STEP4: THEN IT SHOULD RUN DRAWING ONE BY ONE IN THAT FOLDER AND UPDATE TEMPLATE.. QSAVE CLOSE..

 

FIRST YOU LOAD MY LISP AND TEST IN THE ATTACHED DRAWING IT WILL WORK PERFECTLY... I WANT THE SAME FOR MULTIPLE DRAWINGS (LIKE I ATTACHED WITH TEMPLATES OF DIFFERENT "DATES" "job no.s")  IN A FOLDER ..

 

hope you help... but please suggest with auto lisp.... still I have not learned VL commands like "VL-APPLY"  ETC.

0 Likes
Message 10 of 32

Anonymous
Not applicable

and also please give me error trap when we are using DCL  in lisp...

and If you use scripting it should not created script file evary time in destination folder

0 Likes
Message 11 of 32

Anonymous
Not applicable

Please any one reply........

0 Likes
Message 12 of 32

maratovich
Advisor
Advisor

Your title block is a block with attributes.
Then you just need to change the attributes in several files.
Then you need to use this:

 

 

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

Anonymous
Not applicable

NO.... My title block has no attributes...

once please go through my lisp...

0 Likes
Message 14 of 32

Moshe-A
Mentor
Mentor

@pbejse   Patrick,
Just to make this more clear, you are saying that if you want to run a series of command on multiple drawings, let's say i want to audit + purge multiple files i can put these commands in a lisp file add it to startup suite and run publish, do a dummy prints and on the way it will clean my files?
wow this is all new to me...does this appears anywhere in autodesk documentation?
thanks
moshe
This helpful tip comes from Andrea Andreetti. I've seen many AutoCAD users try to run LISP in batches. Some have created huge tools or used script, opening their drawings one by one, which wastes time. Some use ODBX, which I think is good but limited. Then there is my contribution: Why not use the Publish command? Yes, you can do just about whatever you want using the Publish command. Just write your desired commands in a LISP file, then put the LISP file in the Appload Startup Suite, and run Publish with any configuration you want. I use DWF to prevent wasting paper. Be sure to remove your LISP from the Startup Suite when you have finished. You can also purge, create objects, add blocks, etc., and because you are using Publish, you can get a print of the document at the same time. At the end of your LISP code be sure to save the drawing file with this code: (vl-cmdf "._qsave") That’s it! Enjoy!

Now, all you need is a working version of your code your golden. Smiley Very Happy

 

 

 

 


 

0 Likes
Message 15 of 32

maratovich
Advisor
Advisor

Attach an example of your file with the title block.

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

Anonymous
Not applicable

take a look at  above attachments ## lisp dcl dwg

0 Likes
Message 17 of 32

maratovich
Advisor
Advisor

If I have time, then on the weekend I will make the launch of the Lisp as well as on the video.

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

CADaSchtroumpf
Advisor
Advisor

Try to run this code in a script or in arconsole, or ....

Change variable by default, are the same that in your exemple

((lambda ( / n_job n_phase who_draw who_chk q_date ss_job ss_phase ss_draw ss_check ss_date)
;;; fix your string here
	(setq
		n_job "JS-18-395"
		n_phase "10"
		who_draw "TRK"
		who_chk "SVS"
		q_date "14.03.19"
	)
;;; end of fix var
	(command "_.zoom" "_window" '(298 1) '(420 53))
	(setq
		ss_job (ssget "_W" '(375 20) '(415 12) '((0 . "TEXT") (8 . "FRAME TXT")))
		ss_phase (ssget "_W" '(365 10) '(378 3) '((0 . "TEXT") (8 . "FRAME TXT")))
		ss_draw (ssget "_W" '(415 35) '(400 40) '((0 . "TEXT") (8 . "FRAME TEXT")))
		ss_check (ssget "_W" '(400 32) '(415 27) '((0 . "TEXT") (8 . "FRAME TEXT")))
		ss_date (ssget "_W" '(320 52) '(340 47) '((0 . "TEXT") (8 . "FRAME TEXT")))
	)
	(mapcar
		'(lambda (x y)
			(cond
				(x
					(setq dxf_ent (entget (ssname x 0)))
					(entmod (subst (cons 1 y) (assoc 1 dxf_ent) dxf_ent))
				)
			)
		)
		(list ss_job ss_phase ss_draw ss_check ss_date)
		(list n_job n_phase who_draw who_chk q_date)
	)
	(prin1)
))
0 Likes
Message 19 of 32

dbhunia
Advisor
Advisor

@Anonymous  you can try like this with single drawing open in the current session of Autocad....... (Hopefully you can manage the rest)

 

(defun c:test ( / docs doclst sh folder folderobject result SDI_Val LISPI_Val cmd osm ddiag);;;Put Temp Variables
(vl-load-com)
(setq docs (vla-get-documents(vlax-get-acad-object)))
(vlax-for item docs
   (setq doclst (cons (vla-get-name item) doclst))
)
(if (= 1 (length doclst))
   (progn
     (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
		 (setq folderobject (vlax-get-property folder 'Self))
		 (setq result (vlax-get-property FolderObject 'Path))
		 (vlax-release-object folder)
		 (vlax-release-object FolderObject)

		 (SETQ DCL_ID (LOAD_DIALOG "D:\\DEEPAK\\LISP\\SMITH.dcl"));;;Change the path as required
		 (IF (/= DCL_ID -1) 
		     (PROGN 
			(NEW_DIALOG "TEMPLATE" DCL_ID)
			(MODE_TILE "JN" 2)
			(SET_TILE "name" "Developed By B Jnana Deepak")
			(ACTION_TILE "JN" "(SETQ JN $VALUE)")
			(ACTION_TILE "PN" "(SETQ PN $VALUE)")
			(ACTION_TILE "DET" "(SETQ DET $VALUE)")
			(ACTION_TILE "CHK" "(SETQ CHK $VALUE)")
			(ACTION_TILE "DA" "(SETQ DA $VALUE)")			      
			(action_tile "accept" "(done_dialog 1)")
			(action_tile "cancel" "(done_dialog 2)")
			(setq ddiag (start_dialog))
			(unload_dialog dcl_id)
		     )
		  )

		 (if (= ddiag 1)
		     (progn
			  (setq Files_Folder (vl-directory-files result "*.dwg"))
			  (command "save" (strcat (getvar "dwgprefix") (getvar "dwgname")) "Y")
			  (setq n 0)
			  (setq SDI_Val (getvar "SDI"))
			  (setq LISPI_Val (getvar "LISPINIT"))
			  (vl-cmdf "SDI" 1)
			  (vl-cmdf "LISPINIT" 0)

			     (while (< n (length Files_Folder))
				 (command "fileopen" (strcat result "\\" (nth n Files_Folder)))
				 (setq cmd (GETVAR "CMDECHO") osm (GETVAR "OSMODE"))
				 (SETVAR "CMDECHO" 0) (SETVAR "OSMODE" 0)
				 (command "tilemode" 1)
				 (COMMAND "ZOOM" "E")
				 (if (and (/= nil (SETQ SS1 (SSGET "_W" '(375 20) '(415 12)))) (/= nil JN))
					(progn
					(SETQ A1 (ENTGET (SSNAME SS1 0)))
					(SETQ B1 (CDR (ASSOC 1 A1)))
					(ENTMOD (SUBST (CONS 1 (STRCAT JN)) (CONS 1 B1) A1))
					)
				 )
				 (if (and (/= nil (SETQ SS2 (SSGET "_W" '(365 10) '(378 3)))) (/= nil PN))
					(progn
					(SETQ A2 (ENTGET (SSNAME SS2 0)))
					(SETQ B2 (CDR (ASSOC 1 A2)))
					(ENTMOD (SUBST (CONS 1 (STRCAT PN)) (CONS 1 B2) A2))
					)
				 )
				 (if (and (/= nil (SETQ SS3 (SSGET "_W" '(415 35) '(400 40)))) (/= nil DET))
					(progn
					(SETQ A3 (ENTGET (SSNAME SS3 0)))
					(SETQ B3 (CDR (ASSOC 1 A3)))
					(ENTMOD (SUBST (CONS 1 (STRCAT DET)) (CONS 1 B3) A3))
					)
				 )
				 (if (and (/= nil (SETQ SS4 (SSGET "_W" '(400 32) '(415 27)))) (/= nil CHK))
					(progn
					(SETQ A4 (ENTGET (SSNAME SS4 0)))
					(SETQ B4 (CDR (ASSOC 1 A4)))
					(ENTMOD (SUBST (CONS 1 (STRCAT CHK)) (CONS 1 B4) A4))
					)
				 )
				 (if (and (/= nil (SETQ SS5 (SSGET "_W" '(320 52) '(340 47)))) (/= nil DA))
					(progn
					(SETQ A5 (ENTGET (SSNAME SS5 0)))
					(SETQ B5 (CDR (ASSOC 1 A5)))
					(ENTMOD (SUBST (CONS 1 (STRCAT DA)) (CONS 1 B5) A5))
					)
				 )
				 (vl-cmdf "save" (strcat result "\\" (nth n Files_Folder)))
				 (setq n (+ 1 n))
				 (SETVAR "CMDECHO" cmd)
				 (SETVAR "OSMODE" osm)
				 (princ)
			     )
			  (vl-cmdf "SDI" SDI_Val)
			  (vl-cmdf "LISPINIT" LISPI_Val)
		     )
		 )
		 (if (= ddiag 2) (alert "...TEMPLATE Cancelled..."))
	)
     )
   )
   (alert "Multiple Drawing has opened in the Current Session.")
)
(princ)
)

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

pessi.symb
Contributor
Contributor

Any example on how to use the lisp in PUBLISH command in autocad?

our office is restricting us to install softwares like ScriptPro and the like

0 Likes