Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Contributor
Maynard_Rowley
Posts: 21
Registered: ‎04-28-2008
Message 1 of 17 (1,778 Views)

Batch process all drawings in folder

1778 Views, 16 Replies
08-12-2009 11:15 AM
I have two large folders of drawings. I need to open all drawings in each folder, purge them, zoom extents, plot them to PDF, save them and close them. I can manage to purge them, zoom extents, save and close them without problem. I have even managed to plot them to PDF (I have to manually put in the filename though, that's a problem to solve later unless someone has a lisp that plots to PDF nicely). The problem I am having is that I have no idea how to process all of the drawings in the folder by running the lisp once (right now I am opening each file individually & running the lisp). Anyone have suggestions?

I am running XP 64 so Script Pro will not work (there is no version available for a 64-bit OS).
Distinguished Contributor
msclout72
Posts: 128
Registered: ‎10-10-2007
Message 2 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-12-2009 12:19 PM in reply to: Maynard_Rowley
look here

http://www.jefferypsanders.com/autolisp.html
i haven't used this one but he has some useful tools..

for a lisp batchlisp
*Some Buddy
Message 3 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-12-2009 12:19 PM in reply to: Maynard_Rowley
Hi,

These subjects were discussed recently here. The next one is about batch
processing with VisualLISP:

http://tinyurl.com/r5ryr6

As for printing to PDF, it seems that there is a DWG to PDF.pc3 available in
AutoCAD 2008, 2009 and 2010. You can read about it in this thread:

http://tinyurl.com/lk5ln3

HTH


--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


<67belvedere@sasktel.net> a écrit dans le message de news:
6236012@discussion.autodesk.com...
I have two large folders of drawings. I need to open all drawings in each
folder, purge them, zoom extents, plot them to PDF, save them and close
them. I can manage to purge them, zoom extents, save and close them without
problem. I have even managed to plot them to PDF (I have to manually put in
the filename though, that's a problem to solve later unless someone has a
lisp that plots to PDF nicely). The problem I am having is that I have no
idea how to process all of the drawings in the folder by running the lisp
once (right now I am opening each file individually & running the lisp).
Anyone have suggestions?

I am running XP 64 so Script Pro will not work (there is no version
available for a 64-bit OS).
Distinguished Contributor
msclout72
Posts: 128
Registered: ‎10-10-2007
Message 4 of 17 (1,778 Views)

pdf

08-12-2009 12:33 PM in reply to: Maynard_Rowley
;; DWG2PDF.LSP
;; Plot .DWG to .PDF
;; AutoCAD R2007 Only, with DWG To PDF.pc3 driver, Use AcroBat Reader 6.0 or 7.0
(defun C:smileytongue:DF-ROOT ( / paper orient filename dwgname dwgpre )
;; Setup section


(setq paper "ANSI B (11.00 x 17.00 Inches)") ;Drawing size Uncomment for printing
;(setq paper "ARCH D (36.00 x 24.00 Inches)") ;Drawing size Uncomment for printing
(setq orient "LANDSCAPE") ;Orientation
(setq tab "Layout1") ;Layout tab to print
(setq plottable "Monochrome.ctb") ;Plot table
(setq plotscale "fit")
;(setq plottername "DWG To PDF.pc3")
(setq plottername "primopdf")
(setq paper "11 x 17") ;Drawing size Uncomment for printing


(setq dwgname (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4) ))
(setq dwgpre (getvar "dwgprefix"))
(setq filename (strcat dwgpre dwgname ".ps"))
(if (> (getvar "cvport") 1)
(command "_plot" "Y" "MODEL" plottername paper "inches" orient "N" "E" plotscale "C" "Y" plottable "Y" "A" filename "N" "Y")
(command "_plot" "Y" tab plottername paper "inches" orient "N" "E" plotscale "C" "Y" plottable "Y" "Y" "N" "N" "y" filename "N" "Y")
)
(prompt "\n ")
(princ)
); end function
(princ)
(C:smileytongue:DF-ROOT)
Contributor
Maynard_Rowley
Posts: 21
Registered: ‎04-28-2008
Message 5 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-12-2009 01:06 PM in reply to: Maynard_Rowley
"These subjects were discussed recently here. The next one is about batch
processing with VisualLISP:

http://tinyurl.com/r5ryr6"


Yup. Read that post already. Trouble is it recommends using Script Pro, which (as I mentioned in my original post) does not work with XP64. The author does mention using LISP or Object DBX but does not provide any information on how one might do so. Thanks anyway.
Mentor
southie
Posts: 291
Registered: ‎03-15-2007
Message 6 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-12-2009 01:36 PM in reply to: Maynard_Rowley
Maynard,

Try this

This will give you a mult-pick dialog with all drawingings in the current acad folder.
It will then cycle thru the .dwgs you selected performing your lisp code. Sorry for sloppy code but it works.

(vl-load-com)
(setq ins 0)

(setq plist (vl-directory-files (getvar "dwgprefix") "*.dwg" 1))

(defun lmake ()
(setq yy (get_tile "l1"))
);defun

(defun mk_list (/ count item retlist)
(setq count 1)
(while (setq item (read yy))
(setq retlist (cons (nth item plist) retlist))
(while (and (/= " " (substr yy count 1))
(/= "" (substr yy count 1)))
(setq count (1+ count))
)
(setq yy (substr yy count))
)
(setq ww (reverse retlist))
(setq ins1 (nth ins ww))
(setq newdwg (get_tile "newdwg"))
)

(DEFUN WGCH ()
(SETVAR "CMDECHO" 0)
(SETVAR "EXPERT" 4)

(while (/= ins1 nil)
(setvar "lispinit" 0)
(command "open" ins1)


;;**************

;do your lisp inside here ....

;************



(setq ins (+ ins 1))
(setq ins1 (nth ins ww))
);while
(princ));defun

(defun gout ()
(setvar "expert" 0)
(setvar "cmddia" 1)
(setvar "filedia" 1))

(defun C:JB ( / dcl_id)
(setq dcl_id (load_dialog "mprg1.dcl"))
(if (not (new_dialog "mprg1" dcl_id) ) (exit))
(action_tile "accept" "(gout)(mk_list)(done_dialog)")
(action_tile "cancel" "(gout)(done_dialog)")
(start_list "l1")
(mapcar 'add_list plist)
(end_list)
(start_dialog)
(unload_dialog dcl_id)
(wgch)
(SETQ PLIST NIL)
(setvar "lispinit" 1)
(princ))


Below is the .DCL file

mprg1 : dialog {
label="BATCH FILES";
initial_focus="l1";

:boxed_column{
:row{
:column{


:boxed_row {
:list_box {
label="Select Drawings";
key="l1";
action= "(lmake)";
multiple_select=true;
edit_width=300;
}
}
}
}
}
ok_cancel;
}

Southie
*Some Buddy
Message 7 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-12-2009 01:38 PM in reply to: Maynard_Rowley
I thought that at least it gives you an ideea about what to search for. I
think there's a lot of ODBX threads on this forum and on the Internet in
general and I think that if you were able to write the code that does all
that you are saying in the OP, it seems that you have enough skills and
knowledge to understand the ODBX stuff. I'm sorry, but I don't really have
time these days to help and guide you through this. Maybe somebody else can
do it.

Regartds

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


a écrit dans le message de news:
6236131@discussion.autodesk.com...
"These subjects were discussed recently here. The next one is about batch
processing with VisualLISP:

http://tinyurl.com/r5ryr6"


Yup. Read that post already. Trouble is it recommends using Script Pro,
which (as I mentioned in my original post) does not work with XP64. The
author does mention using LISP or Object DBX but does not provide any
information on how one might do so. Thanks anyway.
Distinguished Contributor
EC-CAD
Posts: 5,930
Registered: ‎12-12-2003
Message 8 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-12-2009 03:22 PM in reply to: Maynard_Rowley
Sorry for late response, been busy.
Try this one:
http://www.bobscadshop.com
.. EC-Batch
will do the job.
Bob
Valued Contributor
gilsoto13
Posts: 79
Registered: ‎03-06-2009
Message 9 of 17 (1,778 Views)

Re: Batch process all drawings in folder

08-20-2009 11:47 AM in reply to: Maynard_Rowley
I've found this trying to accomplish exactly the same, I have found the batch purge, audit, save and close routine, (attached)

Also, you can try this batchplot routine.

PlotDwgs.lsp - PlotDwgs is a plot utility program with several unique options including plotting all open drawings, and plotting a folder of user selected drawings. Drawings may be plotted to a specified size, or by selecting the "Varies" option, the program determines the correct paper size to plot. Also included is the option of plotting all layouts in reverse order, and plotting a folder of user selected drawings in reverse order. The associated files are PlotDwgs.lsp, PlotDwgs.dcl and PlotDwgs.dvb.

You can find it here...

http://web2.airmail.net/terrycad/AutoLISP-Code.htm

And if you like DwgToPdf printer from autodesk (installed in 2008, 2009, and 2010) you may use it for modifying that "PlotDwgs.lsp" to make it print multiple pdfs...

this is an automatic pdf printer routine I started and someone helped me to use it for 2008, 2009 or 2010 with the same abbreviation. It´s just for the current drawing thought.

;
(defun c:smileytongue:df ()
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(cond
((= (atof (getvar 'AcadVer)) 17.2)(command "tilemode""0""-plot""y""""DWG To PDF.pc3""ANSI expand B (17.00 x 11.00 Inches)""I""L""N""W""25.4,3.81""908.685,603.885""F""0.75,0""Y""M3_11x17.ctb""Y""N""N""N" (strcat (GETVAR "dwgprefix") (getvar "dwgname")) "N""Y"))
((= (atof (getvar 'AcadVer)) 17.1)(command "tilemode""0""-plot""y""""DWG To PDF2008.pc3""ANSI expand B (11.00 x 17.00 Inches)""I""L""N""W""25.4,3.81""908.685,603.885""F""0.75,0""Y""M3_11x17.ctb""Y""N""N""N" (strcat (GETVAR "dwgprefix") (getvar "dwgname")) "N""Y"))
((= (atof (getvar 'AcadVer)) 18.0)(command "tilemode""0""-plot""y""""DWG To PDF2010.pc3""ANSI expand B (11.00 x 17.00 Inches)""I""L""N""W""25.4,3.81""908.685,603.885""F""0.75,0""Y""M3_11x17.ctb""Y""N""N""N" (strcat (GETVAR "dwgprefix") (getvar "dwgname")) "N""Y"))
)
(setvar "osmode" os)
)
;
;
(defun c:smileytongue:de ()
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(cond
((= (atof (getvar 'AcadVer)) 17.2)(command "tilemode""0""-plot""y""""DWG To PDF.pc3""ANSI expand B (17.00 x 11.00 Inches)""I""L""N""W""1,0.15""35.775,23.775""F""0.75,0""Y""M3_11x17.ctb""Y""N""N""N" (strcat (GETVAR "dwgprefix") (getvar "dwgname")) "N""Y"))
((= (atof (getvar 'AcadVer)) 17.1)(command "tilemode""0""-plot""y""""DWG To PDF2008.pc3""ANSI expand B (11.00 x 17.00 Inches)""I""L""N""W""1,0.15""35.775,23.775""F""0.75,0""Y""M3_11x17.ctb""Y""N""N""N" (strcat (GETVAR "dwgprefix") (getvar "dwgname")) "N""Y"))
((= (atof (getvar 'AcadVer)) 18.0)(command "tilemode""0""-plot""y""""DWG To PDF2010.pc3""ANSI expand B (11.00 x 17.00 Inches)""I""L""N""W""1,0.15""35.775,23.775""F""0.75,0""Y""M3_11x17.ctb""Y""N""N""N" (strcat (GETVAR "dwgprefix") (getvar "dwgname")) "N""Y"))
)
(setvar "osmode" os)
)
; Edited by: gilsoto13 on Aug 20, 2009 6:48 PM
Active Member
eugene_k
Posts: 6
Registered: ‎06-29-2008
Message 10 of 17 (1,778 Views)

Re: Batch process all drawings in folder

03-31-2010 07:03 PM in reply to: Maynard_Rowley
Southie, this is something I was looking for - a simple batch processing engine to run various lisp codes on multiple drawings, and without any intermediate script generation. I badly need your routine to work for me every day, but I could not even test it because of the dcl file... it does not allow for drawings selection! No "browsing" option, just an empty box with "select" and "cancel" buttons. Can you please help to make it work? I hope very much for your help, because I cannot find anything better to run my lisp codes on multiple drawings! My address is eugene_k@wahw.com.au and I would very appreciate your reply. best regards, Eugene
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.