Bill Tillman Posted September 22, 2014 Posted September 22, 2014 I'm about 99.9% sure this is the exact code I found back in 2012 and used to perform a batch operation on a bunch of drawing files. All this did was allow you to point to a folder and then run a batch operation on every file in the folder. This one I customized to set some units properties. It worked great back then. I recall watching it take off on a huge folder of files. It worked tirelessly for about an hour and finished everything up just fine. So today I pull this thing back out and want to run some other batch operations with it. But no such luck. So like any studious programmer, I put the original code back in place and tried to run it on a folder of drawing files. It ran okay, but it's not saving the files, that is overwriting the existing files like it did before. ;------------------------------------------------------------------------; ; Program Name: batchLISP.lsp ; ; Date: 2012-10-02 ; ;------------------------------------------------------------------------; ; Carries out batch process on entire folder full of files ; ;------------------------------------------------------------------------; (vl-load-com) (defun browse-folder (msg path / sh fld folderobject result) (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application" ) ) (setq fld (vlax-invoke-method sh 'BrowseForFolder vlax-vbDefaultButton1 msg ; dialogue box message vlax-vbDefaultButton3 ; BIF_NONEWFOLDERBUTTON Bruno Toniutti path ; path start ) ) (vlax-release-object sh) (if fld (progn (setq folderobject (vlax-get-property fld 'Self)) (setq result (vlax-get-property folderObject 'Path)) (vlax-release-object fld) (vlax-release-object folderobject) result ) ) ) ; ; (defun list-dwg (path / file_list full_list) (setq file_list (vl-directory-files path "*.dwg" 1) ) (setq file_list (mapcar (function (lambda (x) (strcat path "\\" x))) file_list ) full_list (append full_list file_list) ) full_list ) ; ; (prompt "\n********************************************") (prompt "\n Enter BATCHMM to run batch file operation\n") (prompt "\n********************************************") ; ; (defun C:BATCHMM (/ *good-files* acapp adoc file_obj full-names-list osd) (setq acapp (vlax-get-acad-object) adoc (vla-get-activedocument acapp) ) (vla-startundomark adoc) (setq osd (vla-getvariable adoc "SDI")) (vla-setvariable adoc "SDI" 0) (setq olsp (vla-getvariable adoc "LISPINIT")) (vla-setvariable adoc "LISPINIT" 0) (if (setq full-names-list (list-dwg (browse-folder "SELECT FOLDER" "S:/")) ) ; change on your start path folder (progn (mapcar (function (lambda (i) (progn (setq file_obj (vla-open (vla-get-documents acapp) i)) (setq *good-files* (cons file_obj *good-files*)) ;;here will your batch function: (vla-setvariable file_obj "insunits" 1) (vla-setvariable file_obj "lunits" 5) (vla-setvariable file_obj "luprec" 5) (vla-setvariable file_obj "aunits" 0) (vla-setvariable file_obj "auprec" 4) ;(command "._ZOOM" "E") ; (vla-setvariable file_obj "INSUNITSDEFSOURCE" 0) ; (vla-setvariable file_obj "INSUNITSDEFTARGET" 0) ; (vla-setvariable file_obj "annotativedwg" 0) (vla-close file_obj :vlax-true) (vlax-release-object file_obj) (setq file_obj nil) ) ) ) full-names-list ) (cond ((zerop (length *good-files*)) (princ "\nThere isn't opened files\n") ) ((not (eq (length full-names-list) (length *good-files*))) (princ "\nSome files is not opened\n") ) (T nil) ) ) (princ "\nThere isn't .DWG files in selected directory\n") ) (vla-setvariable adoc "SDI" osd) (vla-setvariable adoc "LISPINIT" olsp) (vla-endundomark adoc) (princ) ) This thing really did work great, that's why I'd like to get it back online and use it some more. Quote
Bill Tillman Posted September 23, 2014 Author Posted September 23, 2014 Trying again today to follow up on this one. I am very certain that somewhere back in history I ran that batch process above and it worked on a huge folder of files. So I did some more checking today into a batch process. I seem to be hitting the wall because while the programs will run, they don't actually perform the work on the batch of drawings. For example, I tried this one today and it looked good on the start but all it did was print the same Layout tab in the same drawing over and over again. (vl-load-com) (setq ins 0) (setq plist (vl-directory-files (getvar "C:/MyFolder/") "*.dwg" 1)) (defun lmake () (setq yy (get_tile "l1")) ) (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)) ) (princ) ) (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) ) In the "do your lisp..." section I put some simple plot instructions to plot the one and only layout tab in each drawing file to a PDF. I run this from a blank drawing and all it does it print the blank layout tab in the initially opened drawing over and over and over. One for each file in the selection made with this code. Quote
BIGAL Posted September 24, 2014 Posted September 24, 2014 Not 100% sure what your doing but once you "command open" does it not take the control away from the current lisp, would it maybe be better to get dwg list and write a script less problems with opening and closing and keeping program turned on correct dwg. open dwg1 (load "the correct lisp") (defun with variables) close Y Quote
Bill Tillman Posted September 24, 2014 Author Posted September 24, 2014 Thanks for your reply BIGAL. I'm still a little in the dark on this topic. First, I did get the code in OP here to run again. It lets you select a folder and then it opens each drawing in that folder separately, changes the settings as the code directs for units, then it saves and closes the drawing file. Now, it's using VL side of LISP to do this so I guess that's the huge difference. What I'm after is a way to point to a folder, and then open and plot each Layout1 tab in each file to a PDF. I need this to work independently so we can start it and then walk away from it while it works. So last night my friend showed me how he would use SheetSets to do it using Publish. The trouble we found was that no matter which way we set the environment, the window to confirm where to save the file kept opening up waiting for user input. Perhaps I need to study this more, because he kept telling me that it should not be doing this, but it did. And unless I can get the thing to batch print 456 drawing files all on it's own.... so I'm thinking now I will whip out Visual Studio and build a C# app to do this. I was really hoping that LISP could take care of it because then it's all self contained within AutoCAD...which they seem to like around here. Quote
BIGAL Posted September 25, 2014 Posted September 25, 2014 If you where to script it open dwg1 etc then you can load a lisp that plots only layout1. You can do it a couple of ways using layout name or just "layout1" you need to be carefull though layout1 is the first layout created and may not be the first layout you see in the list, basicly you can retrieve the layout list as created or as viewed. Lee-mac helped me with that problem. Any way go here as a start http://www.cadtutor.net/forum/showthread.php?69132-Printing-LISP-Help...&highlight=Printing-LISP If you want more say the 1st 2 or open lots and print ranges I can give you a good start on that also. script open dwg1 (load "plotlays1") close N This example uses taborder so tabnum need to check should be 1 for 1st layout tab note 0 is Model. Just remove the lines not required like repeat and hard code layout to 1 ;Plots layouts by range ; By Alan H Feb 2014 (defun AH:pltlays1 ( / lay numlay numend) (setq numlay (getint "\nEnter Start tab number"))(setq numend (getint "\nEnter last tab number")) (setq len (+ (- numend numlay) 1)) (repeat len (vlax-for lay (vla-get-Layouts (vla-get-activedocument (vlax-get-acad-object))) (if (= numlay (vla-get-taborder lay)) ; change this to = 1 (setvar "ctab" (vla-get-name lay)) ) ; if ) ; for (setq lay nil) (princ name) (COMMAND "-PLOT" "Y" "" "\\\\PROD\\CLR-PRN03" "A3 (297 x 420 mm)" "m" "LANDSCAPE" "N" "W" "-6,-6" "807,560" "1=2" "C" "Y" "DesignLaserCOLOUR.ctb" "Y" "N" "N" "N" "N" "N" "y") (setq numlay (+ numlay 1)) ) ; end repeat ); defun (AH:pltlays1) Quote
BIGAL Posted September 25, 2014 Posted September 25, 2014 A bit more (setq pdfname (strcat (getvar "dwgprefix") dwgname "-" name)) (COMMAND "-PLOT" "Y" "" "dwg to Pdf" "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE" "N" "W" "-6,-6" "807,560" "1=2" "C" "y" "Designlasercolour.ctb" "Y" "n" "n" "n" pdfName "N" "y" ) ) Quote
Bill Tillman Posted September 29, 2014 Author Posted September 29, 2014 Thanks again BIGAL. I ended up attacking this with a .NET app with Visual Studio. It works perfectly. Prints out all 488 files to PDF in about 9 minutes and without any user input. That's the key to so many of the tasks I do these days. No user input allowed. Automation only. Quote
BIGAL Posted September 30, 2014 Posted September 30, 2014 Thats why we crucify the guys if they move a title block we have one who likes to copy when making a new one next to old one and removes it then does not move the title block to where it should be. Its suprising how fast you can manipulate a dwg with no user input even opening and closing. 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.