AbdRF Posted July 9, 2019 Posted July 9, 2019 Hi all, Is it possible to run lisp routines into multiple drawings simultaneously.Basically ,I have around 10 dwgs on which I want to run some routines on the block references (which are common in all the dwgs).Currently,I have to run the same lisp routine individually for each dwg. Can somebody guide me? Thanks Quote
maratovich Posted July 9, 2019 Posted July 9, 2019 3 minutes ago, Nardino said: what kind of program is this? AutoViewport - Automatic creation layouts and viewport Running a lisp is the built-in function of the program. Quote
Manila Wolf Posted July 10, 2019 Posted July 10, 2019 You could try using an AutoCAD script. I have had great success running lisps across multiple drawing using the following script compiler: - http://esurveying.net/land-survey/free-software-batch-run-script-lisp-multiple-drawings You will have to load the lisps in the order that you want to run them. I don't think you can sort the order of the lisps after you have added them. I prefer to create the script and then run the script manually afterwards. You can open a script file in Notepad to get some idea of how it works. For me I prefer my Single Drawing Interface (SDI) to be set at 1, so in my case I have to remember to set SDI to 0 before running a script. Quote
AbdRF Posted July 11, 2019 Author Posted July 11, 2019 @Nardino add objects to block and block counter programs Quote
Billy Ray Posted July 11, 2019 Posted July 11, 2019 For that I use an old and useful Lisp routine, Script Creator (Coomand prompt is "SCRS"). you appload the scrs lisp file (paste in notepad and save as .lsp) and also place the scrs dcl file (save as .dcl) in the same folder. Ensure that you add that file path to trusted sources under your AutoCAD options "Files" Tab and it runs smoothly. You can run a lot of commands on an entire directory of DWGs as long as you only have one dwg open and it automatically navigates to the working folder. It's even faster than batch plotting if you have a PDF lisp command.It requires no editing and it's very fast!Can put a lot of commands in one line by adding spaces in between them or seperate commands in each line, easy breezy! Cheers... scrs.lsp ;------------------------------------------------------------------------------- ; c:Scrs - Script Creator ;------------------------------------------------------------------------------- (defun c:Scrs (/ Dcl_Id% DwgName$ DxfName$ Filename% First FolderDwgs@ FolderDxfs@ Index# Item Loop Option PathFilename$ Return# Set_Vars: Var0$ Var1$ Var2$ Var3$ Var4$ Var5$ Var6$) (if (> (length (GetDwgsList)) 1) (alert (strcat "The Script Options for Folders can only be run\n" "in a Single Document Interface. For this option\n" "close all other open drawings and try again.") );alert );if ;----------------------------------------------------------------------------- ; Set_Vars: - Set dialog tiles and variables ;----------------------------------------------------------------------------- (defun Set_Vars: (VarName$) (set (read VarName$) $value) (if (and (/= Var2$ "") (/= Var3$ "") (/= Var4$ "") (/= Var5$ "")(/= Var6$ "")) (mode_tile "Next" 0) (mode_tile "Next" 1) );if (set_tile "Toggle0" Var0$) (if (= Var0$ "1") (progn (setq Var0$ "0") (setq Var2$ "" Var3$ "" Var4$ "" Var5$ "" Var6$ "" Index# 0) (setq *Script@ (list Var1$ Var2$ Var3$ Var4$ Var5$ Var6$)) (set_tile "Text1" (strcat "Page " (itoa (/ (+ Index# 5) 5)) " of " (itoa (/ (length *Script@) 5)))) (set_tile "Edit2" Var2$) (set_tile "Edit3" Var3$) (set_tile "Edit4" Var4$) (set_tile "Edit5" Var5$) (set_tile "Edit6" Var6$) (mode_tile "Back" 1) (mode_tile "Next" 1) );progn );if );defun Set_Vars: ;----------------------------------------------------------------------------- ; Set Default Variables and List Values ;----------------------------------------------------------------------------- (if (= (length (GetDwgsList)) 1) (setq Option "2") (setq Option "1") );if (if (not *Script@) (setq *Script@ (list Option "" "" "" "" "")) );if (setq Var0$ "0" Var1$ (nth 0 *Script@) Var2$ (nth 1 *Script@) Var3$ (nth 2 *Script@) Var4$ (nth 3 *Script@) Var5$ (nth 4 *Script@) Var6$ (nth 5 *Script@) Loop t Index# 0 );setq ;----------------------------------------------------------------------------- ; Load Dialog ;----------------------------------------------------------------------------- (while Loop (if (= (length *Script@)(1+ Index#)) (setq *Script@ (append *Script@ (list "" "" "" "" ""))) );if (setq Var1$ (nth 0 *Script@) Var2$ (nth (+ Index# 1) *Script@) Var3$ (nth (+ Index# 2) *Script@) Var4$ (nth (+ Index# 3) *Script@) Var5$ (nth (+ Index# 4) *Script@) Var6$ (nth (+ Index# 5) *Script@) );setq (setq Dcl_Id% (load_dialog "Scrs.dcl")) (new_dialog "Scrs" Dcl_Id%) ;--------------------------------------------------------------------------- ; Set Dialog Initial Settings ;--------------------------------------------------------------------------- (set_tile "Title" " Script Creator") (set_tile "Radio1" Var1$) (set_tile "Text1" (strcat "Page " (itoa (/ (+ Index# 5) 5)) " of " (itoa (/ (length *Script@) 5)))) (set_tile "Edit2" Var2$) (set_tile "Edit3" Var3$) (set_tile "Edit4" Var4$) (set_tile "Edit5" Var5$) (set_tile "Edit6" Var6$) (if (= Index# 0) (mode_tile "Back" 1) );if (if (and (= Var2$ "") (= Var3$ "") (= Var4$ "") (= Var5$ "")(= Var6$ "")) (mode_tile "Next" 1) );if (if (> (length (GetDwgsList)) 1) (progn (mode_tile "2" 1) (mode_tile "3" 1) );progn );if ;--------------------------------------------------------------------------- ; Dialog Actions ;--------------------------------------------------------------------------- (action_tile "Toggle0" "(Set_Vars: \"Var0$\")") (action_tile "Radio1" "(Set_Vars: \"Var1$\")") (action_tile "Edit2" "(Set_Vars: \"Var2$\")") (action_tile "Edit3" "(Set_Vars: \"Var3$\")") (action_tile "Edit4" "(Set_Vars: \"Var4$\")") (action_tile "Edit5" "(Set_Vars: \"Var5$\")") (action_tile "Edit6" "(Set_Vars: \"Var6$\")") (action_tile "Back" "(done_dialog 2)") (action_tile "Next" "(done_dialog 3)") (setq Return# (start_dialog)) (unload_dialog Dcl_Id%) (if (= Return# 0) (exit) );if (if (= Return# 1) (if (and (= Var2$ "") (= Var3$ "") (= Var4$ "") (= Var5$ "")(= Var6$ "")) (progn (alert "Enter information for Script Commands!") (setq Loop t) );progn (setq Loop nil) );if );if (setq *Script@ (change_nth 0 Var1$ *Script@)) (setq *Script@ (change_nth (+ Index# 1) Var2$ *Script@)) (setq *Script@ (change_nth (+ Index# 2) Var3$ *Script@)) (setq *Script@ (change_nth (+ Index# 3) Var4$ *Script@)) (setq *Script@ (change_nth (+ Index# 4) Var5$ *Script@)) (setq *Script@ (change_nth (+ Index# 5) Var6$ *Script@)) (if (and Loop (= Return# 2));Back (setq Index# (- Index# 5)) );if (if (and Loop (= Return# 3));Next (setq Index# (+ Index# 5)) );if );while (if (not (findfile "C:\\Temp\\Temp.scr")) (progn (vl-load-com)(vl-mkdir "C:\\Temp")) );if (if (or (= Var1$ "2")(= Var1$ "3")) (progn (if (>= (atoi (getvar "ACADVER")) 15) (if (/= (getvar "CTAB") "Model") (command "PSPACE") );if );if (if (not *Pathname$) (setq *Pathname$ (getvar "DWGPREFIX")) );if (if (= (getvar "DWGTITLED") 0) (progn (setq DwgName$ "C:\\Temp\\Temp.dwg");Optional name (if (findfile DwgName$) (command ".SAVEAS" "" DwgName$ "Y") (command ".SAVEAS" "" DwgName$) );if );progn (if (/= (getvar "DBMOD") 0) (command ".QSAVE") );if );if );progn );if (setq First t) (if (= Var1$ "1"); This Drawing only (progn (setq Filename% (open "C:\\Temp\\Temp.scr" "w")) (foreach Item *Script@ (if First (setq First nil) (if (/= Item "") (write-line Item Filename%) );if );if );foreach );progn );if (if (= Var1$ "2"); Drawings in Folder (if (setq PathFilename$ (getfiled " Select a drawing in a folder to run Script" *Pathname$ "dwg" 2)) (progn (setq *Pathname$ (getpath PathFilename$)) (setq FolderDwgs@ (vl-directory-files *Pathname$ "*.dwg" 1)) (setq Filename% (open "C:\\Temp\\Temp.scr" "w")) (foreach DwgName$ FolderDwgs@ (write-line "FileOpen" Filename%) (write-line (strcat "\"" *Pathname$ DwgName$ "\"") Filename%) (setq First t) (foreach Item *Script@ (if First (setq First nil) (if (/= Item "") (write-line Item Filename%) );if );if );foreach (write-line "(if(/=(getvar\"DBMOD\")0)(command\"QSAVE\"))" Filename%) );foreach (if (findfile (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))) (progn (write-line "FileOpen" Filename%) (write-line (strcat "\"" (getvar "DWGPREFIX") (getvar "DWGNAME") "\"") Filename%) );progn );if );progn (exit) );if );if (if (= Var1$ "3"); DXF files in Folder (if (setq PathFilename$ (getfiled " Select a DXF file in a folder to run Script" *Pathname$ "dxf" 2)) (progn (setq *Pathname$ (getpath PathFilename$)) (setq FolderDxfs@ (vl-directory-files *Pathname$ "*.dxf" 1)) (setq Filename% (open "C:\\Temp\\Temp.scr" "w")) (foreach DxfName$ FolderDxfs@ (write-line "FileOpen" Filename%) (write-line (strcat "\"" *Pathname$ DxfName$ "\"") Filename%) (setq First t) (foreach Item *Script@ (if First (setq First nil) (if (/= Item "") (write-line Item Filename%) );if );if );foreach (write-line "SaveAs dxf 16" Filename%) (write-line (strcat "\"" *Pathname$ DxfName$ "\"") Filename%) (write-line "Y" Filename%) );foreach (if (findfile (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))) (progn (write-line "FileOpen" Filename%) (write-line (strcat "\"" (getvar "DWGPREFIX") (getvar "DWGNAME") "\"") Filename%) );progn );if );progn (exit) );if );if (write-line "(princ \"\\n \\n \")(princ)" Filename%) (close Filename%) (command "SCRIPT" "C:\\Temp\\Temp.scr") (princ) );defun c:Scrs ;------------------------------------------------------------------------------- ; Start of Scrs Support Utility Functions ;------------------------------------------------------------------------------- ; Change_nth - Changes the nth item in a list with a new item value. ; Arguments: 3 ; Num# = Nth number in list to change ; Value = New item value to change to ; OldList@ = List to change item value ; Returns: A list with the nth item value changed. ;------------------------------------------------------------------------------- (defun Change_nth (Num# Value OldList@) (if (<= 0 Num# (1- (length OldList@))) (if (> Num# 0) (cons (car OldList@) (Change_nth (1- Num#) Value (cdr OldList@))) (cons Value (cdr OldList@)) );if OldList@ );if );defun Change_nth ;------------------------------------------------------------------------------- ; GetDwgsList - Returns a list of open drawings ; Use (length (GetDwgsList)) for the number of open drawings. ;------------------------------------------------------------------------------- (defun GetDwgsList (/ AcadOBJ DocsOBJ DwgsList@) (if (>= (atoi (getvar "ACADVER")) 15) (progn (setq AcadOBJ (vlax-get-acad-object) DocsOBJ (vlax-get-property AcadOBJ "Documents") DwgsList@ nil );setq (vlax-for ForItem DocsOBJ (setq DwgsList@ (cons (strcat (vlax-get-property ForItem "Path") "\\" (vlax-get-property ForItem "Name")) DwgsList@)) );vlax-for (setq DwgsList@ (reverse DwgsList@)) );progn (setq DwgsList@ (list (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")))) );if DwgsList@ );defun GetDwgsList ;------------------------------------------------------------------------------- ; GetPath - Used to get the path from the path and filename. ; Arguments: 1 ; PathFilename$ = Path and filename string ; Returns: Pathname string. ;------------------------------------------------------------------------------- (defun GetPath (PathFilename$) (strcat (vl-filename-directory PathFilename$) "\\") );defun GetPath ;------------------------------------------------------------------------------- ; GetLayoutList - Returns a list of layouts in the drawing in tab order ;------------------------------------------------------------------------------- (defun GetLayoutList (/ Layouts@) (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) '(lambda (x) (setq Layouts@ (cons x Layouts@))) );vlax-map-collection (setq Layouts@ (vl-sort Layouts@ '(lambda (x y) (< (vla-get-taborder x) (vla-get-taborder y))))) (vl-remove "Model" (mapcar '(lambda (x) (vla-get-name x)) Layouts@)) );defun GetLayoutList ;------------------------------------------------------------------------------- ; c:ZoomE - Zoom extents in all layouts ;------------------------------------------------------------------------------- (defun c:ZoomE (/ Layout$) (command "LAYOUT" "S" "Model") (command "ZOOM" "E") (foreach Layout$ (GetLayoutList) (command "PSPACE") (command "ZOOM" "E") );foreach (command "LAYOUT" "S" (nth 0 (GetLayoutList))) (princ) );defun c:ZoomE ;------------------------------------------------------------------------------- ; c:Purged - Purges All including null strings ;------------------------------------------------------------------------------- (defun c:Purged (/ SS&) (command ".LAYER" "T" "0" "U" "0" "ON" "0" "S" "0" "") (setq SS& (ssget "X" '( (-4 . "<OR") ;(0 . "POINT");Optional (-4 . "<AND") (0 . "TEXT") (-4 . "<OR") (1 . "") (1 . " ") (-4 . "OR>") (-4 . "AND>") (-4 . "<AND") (0 . "MTEXT") (-4 . "<OR") (1 . "") (1 . " ") (1 . " ") (1 . "\\A1;") (1 . "\\A1; ") (1 . "\\A1; ") (-4 . "OR>") (-4 . "AND>") (-4 . "OR>") ) );ssget );setq (if SS& (command "ERASE" SS& "")) (repeat 4 (command "PURGE" "A" "*" "N")) (princ "\n \n \n \n \n \n \nPurged including null strings") (princ) );defun c:Purged ;------------------------------------------------------------------------------- (princ);End of Scrs.lsp scrs.dcl dcl_settings : default_dcl_settings { audit_level = 3; } //------------------------------------------------------------------------------ // Scrs - Script Creator [Scrs R3] //------------------------------------------------------------------------------ Scrs : dialog { key = "Title"; initial_focus = "Edit2"; : spacer { height = 0.1; } : boxed_column { label = "Script Options"; : radio_column { key = "Radio1"; width = 21; : radio_button { key = "1"; label = "This Drawing only"; } : radio_button { key = "2"; label = "Drawings in Folder"; } : radio_button { key = "3"; label = "DXF files in Folder"; } } : toggle { key = "Toggle0"; label = "Clear Script"; } : spacer { height = 0.1; } } : text { key = "Text1"; label = ""; alignment = centered; } : boxed_column { label = "Script Commands"; : edit_box { key = "Edit2"; edit_width = 21; fixed_width = true; } : edit_box { key = "Edit3"; edit_width = 21; fixed_width = true; } : edit_box { key = "Edit4"; edit_width = 21; fixed_width = true; } : edit_box { key = "Edit5"; edit_width = 21; fixed_width = true; } : edit_box { key = "Edit6"; edit_width = 21; fixed_width = true; } : spacer { height = 0.1; } } : spacer { height = 0.1; } : row { : column { : button { key = "Back"; label = "< &Back"; alignment = right; width = 11; fixed_width = true; } } : column { : button { key = "Next"; label = "&Next >"; alignment = left; width = 11; fixed_width = true; } } } : row { : column { : ok_button { alignment = right; width = 11; } } : column { : cancel_button { alignment = left; width = 11; } } } }//Scrs //------------------------------------------------------------------------------ 1 Quote
AbdRF Posted July 12, 2019 Author Posted July 12, 2019 @Billy Ray Thank you very much for your help. Its working fine on single drawing but I am not able to run lisps command on multiple drawing. May be, I am doing something wrong. Really appreciate your efforts. Thanks Quote
Billy Ray Posted July 12, 2019 Posted July 12, 2019 You have to have only "One" drawing open in order to run it on all DWG's. It should prompt you prior to opening the window. If it works on 1 DWG it will work on all dwg's. Type the command then select "Drawings in folder". Quote
Manila Wolf Posted July 15, 2019 Posted July 15, 2019 (edited) On 7/12/2019 at 10:09 PM, Billy Ray said: You have to have only "One" drawing open in order to run it on all DWG's. It should prompt you prior to opening the window. If it works on 1 DWG it will work on all dwg's. Type the command then select "Drawings in folder". Billy Ray, I also have this lisp in my collection and it works well. It would be polite to credit the author, Terry Miller. Original lisp can be found here: - http://web2.airmail.net/terrycad/AutoLISP-Code.htm For info, the lisp saves the script file. It is saved as: - C:\Temp\Temp.scr You can open the script file with notepad if you are curious to see how it works. Edited July 15, 2019 by Manila Wolf Corrected bad English Quote
AbdRF Posted July 15, 2019 Author Posted July 15, 2019 @Billy Ray I understood what you are trying to convey.I have selected the option "Drawings in folder". But then it is allowing to select only one drawing Why it is not allowing to select multiple dwgs even when I have selected the option "Drawings in Folder". Thanks Quote
Manila Wolf Posted July 15, 2019 Posted July 15, 2019 (edited) 13 minutes ago, AbdRF said: Why it is not allowing to select multiple dwgs even when I have selected the option "Drawings in Folder". Thanks AbdRF, Just select the first drawing in the folder only. The lisp will select all the other drawings itself as it is running. Edited July 15, 2019 by Manila Wolf Quote
Alan_KD Posted July 15, 2019 Posted July 15, 2019 I used excel and VBA to modify, load and run a lisp on multiple drawings on a loop. Also you can pass variable values. Quote
Billy Ray Posted July 15, 2019 Posted July 15, 2019 7 hours ago, Manila Wolf said: Billy Ray, I also have this lisp in my collection and it works well. It would be polite to credit the author, Terry Miller. Original lisp can be found here: - http://web2.airmail.net/terrycad/AutoLISP-Code.htm For info, the lisp saves the script file. It is saved as: - C:\Temp\Temp.scr You can open the script file with notepad if you are curious to see how it works. Typically do . Just did a quick copy and paste and did not change the name of his lisp. Nor did I claim credit for it. Have a nice day Quote
Recommended Posts
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.