Jump to content
AbdRF

Running Lisp routines on multiple dwgs

Recommended Posts

AbdRF

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

Share this post


Link to post
Share on other sites
maratovich

Use this:

runlisp.png

Share this post


Link to post
Share on other sites
Nardino

what kind of program is this?

Share this post


Link to post
Share on other sites
Nardino

thanks. I will look into it.

looks interesting😀

Share this post


Link to post
Share on other sites
Manila Wolf

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.

 

 

Share this post


Link to post
Share on other sites
AbdRF

@Nardino add objects to block and block counter programs

Share this post


Link to post
Share on other sites
Billy Ray

     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 [email protected] [email protected]
  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 *[email protected] (list Var1$ Var2$ Var3$ Var4$ Var5$ Var6$))
        (set_tile "Text1" (strcat "Page " (itoa (/ (+ Index# 5) 5)) " of " (itoa (/ (length *[email protected]) 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 *[email protected])
    (setq *[email protected] (list Option "" "" "" "" ""))
  );if
  (setq Var0$ "0"
        Var1$ (nth 0 *[email protected])
        Var2$ (nth 1 *[email protected])
        Var3$ (nth 2 *[email protected])
        Var4$ (nth 3 *[email protected])
        Var5$ (nth 4 *[email protected])
        Var6$ (nth 5 *[email protected])
        Loop t
        Index# 0
  );setq
  ;-----------------------------------------------------------------------------
  ; Load Dialog
  ;-----------------------------------------------------------------------------
  (while Loop
    (if (= (length *[email protected])(1+ Index#))
      (setq *[email protected] (append *[email protected] (list "" "" "" "" "")))
    );if
    (setq Var1$ (nth 0 *[email protected])
          Var2$ (nth (+ Index# 1) *[email protected])
          Var3$ (nth (+ Index# 2) *[email protected])
          Var4$ (nth (+ Index# 3) *[email protected])
          Var5$ (nth (+ Index# 4) *[email protected])
          Var6$ (nth (+ Index# 5) *[email protected])
    );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 *[email protected]) 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 *[email protected] (change_nth 0 Var1$ *[email protected]))
    (setq *[email protected] (change_nth (+ Index# 1) Var2$ *[email protected]))
    (setq *[email protected] (change_nth (+ Index# 2) Var3$ *[email protected]))
    (setq *[email protected] (change_nth (+ Index# 3) Var4$ *[email protected]))
    (setq *[email protected] (change_nth (+ Index# 4) Var5$ *[email protected]))
    (setq *[email protected] (change_nth (+ Index# 5) Var6$ *[email protected]))
    (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 *[email protected]
        (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 [email protected] (vl-directory-files *Pathname$ "*.dwg" 1))
        (setq Filename% (open "C:\\Temp\\Temp.scr" "w"))
        (foreach DwgName$ [email protected]
          (write-line "FileOpen" Filename%)
          (write-line (strcat "\"" *Pathname$ DwgName$ "\"") Filename%)
          (setq First t)
          (foreach Item *[email protected]
            (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 [email protected] (vl-directory-files *Pathname$ "*.dxf" 1))
        (setq Filename% (open "C:\\Temp\\Temp.scr" "w"))
        (foreach DxfName$ [email protected]
          (write-line "FileOpen" Filename%)
          (write-line (strcat "\"" *Pathname$ DxfName$ "\"") Filename%)
          (setq First t)
          (foreach Item *[email protected]
            (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
;   [email protected] = List to change item value
; Returns: A list with the nth item value changed.
;-------------------------------------------------------------------------------
(defun Change_nth (Num# Value [email protected])
  (if (<= 0 Num# (1- (length [email protected])))
    (if (> Num# 0)
      (cons (car [email protected]) (Change_nth (1- Num#) Value (cdr [email protected])))
      (cons Value (cdr [email protected]))
    );if
    [email protected]
  );if
);defun Change_nth
;-------------------------------------------------------------------------------
; GetDwgsList - Returns a list of open drawings
; Use (length (GetDwgsList)) for the number of open drawings.
;-------------------------------------------------------------------------------
(defun GetDwgsList (/ AcadOBJ DocsOBJ [email protected])
  (if (>= (atoi (getvar "ACADVER")) 15)
    (progn
      (setq AcadOBJ (vlax-get-acad-object)
            DocsOBJ (vlax-get-property AcadOBJ "Documents")
            [email protected] nil
      );setq
      (vlax-for ForItem DocsOBJ
        (setq [email protected] (cons (strcat (vlax-get-property ForItem "Path") "\\"
        (vlax-get-property ForItem "Name")) [email protected]))
      );vlax-for
      (setq [email protected] (reverse [email protected]))
    );progn
    (setq [email protected] (list (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))))
  );if
  [email protected]
);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 (/ [email protected])
  (vlax-map-collection (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    '(lambda (x) (setq [email protected] (cons x [email protected])))
  );vlax-map-collection
  (setq [email protected] (vl-sort [email protected] '(lambda (x y) (< (vla-get-taborder x) (vla-get-taborder y)))))
  (vl-remove "Model" (mapcar '(lambda (x) (vla-get-name x)) [email protected]))
);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
//------------------------------------------------------------------------------

 

  • Like 1

Share this post


Link to post
Share on other sites
Nardino

many thanks. I will try it out

  • Like 1

Share this post


Link to post
Share on other sites
AbdRF

@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

Share this post


Link to post
Share on other sites
Billy Ray

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". 

Share this post


Link to post
Share on other sites
Manila Wolf
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 by Manila Wolf
Corrected bad English

Share this post


Link to post
Share on other sites
AbdRF

@Billy Ray I understood what you are trying to convey.I have selected the option "Drawings in folder". 

image.png.1c01183a076ce6bf49ce04200c8acc36.png

But then it is allowing to select only one drawing
image.png.d5c88fb481f9d5942fc0722aabc7a304.png


Why it is not allowing to select multiple dwgs even when I have selected the option "Drawings in Folder".

Thanks 

 

Share this post


Link to post
Share on other sites
Manila Wolf
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 by Manila Wolf

Share this post


Link to post
Share on other sites
Alan_KD

I used excel and VBA to modify, load and run a lisp on multiple drawings on a loop. Also you can pass variable values.

Share this post


Link to post
Share on other sites
Billy Ray
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

Share this post


Link to post
Share on other sites
Manila Wolf

All good Billy Ray. 👍

Have a nice day too. 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...