Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Open, Purge All, Zoom Extents, then Save, Lisp routine.

61 REPLIES 61
Reply
Message 1 of 62
Ak_homegrown
15700 Views, 61 Replies

Open, Purge All, Zoom Extents, then Save, Lisp routine.

I have thousands of archive drawings that I would like to run a lisp routine on that would Open, Purge All, Zoom Extents, Save, and Close the file, moving onto the next one. I am not very lisp savvy, so I was hoping someone out there could provide me with a lisp that does just that.

(I know there are lots of people out there with lisps for this very purpose, so hopefully one of you can help me out!)

Thanks in advance!
61 REPLIES 61
Message 2 of 62
anim8er_gie
in reply to: Ak_homegrown

This is generally done with a script and a patch processing program. You should be able to find a batch program for free off the net. You should be able to write the script, it's just the type in commands in a text file.
Message 3 of 62
Ak_homegrown
in reply to: Ak_homegrown

Thanks for the response, wouold you be able to reccommend a "batch processing program" that I could download for free as you suggest?
Message 4 of 62
anim8er_gie
in reply to: Ak_homegrown

You could try this one:

http://www.brothersoft.com/ezscript-pro-26362.html
Message 5 of 62
DanielCoe
in reply to: Ak_homegrown

EZScripts-Pro: http://www.brothersoft.com/ezscript-pro-download-26362.html
Message 6 of 62
DanielCoe
in reply to: Ak_homegrown

Only quirky thing I hate about this EZScript program is that it doesn't like the AutoCAD ribbon, and your palettes. After you use it, you have to load everything back. And you have to make sure your Layer and Properties palettes are off before using it.
Message 7 of 62
scottbolton
in reply to: Ak_homegrown

AK,

There's more than one way to skin a nut - here's just one:

Save this code in RV.lsp somewhere on your PC, type APPLOAD and browse to the file, then type RV to start it.

(defun C:RV ( / COUNT DIR FILENAME FILES SCRIPTNAME)
(if (setq dir (getfiled "Select the drawing directory:" "" "dwg" 0))
(setq dir (vl-filename-directory dir))
)
(if dir
(setq files (vl-directory-files dir "*.dwg" 1))
)
(if files
(progn
(setq scriptname (open "C:\\batch.scr" "w")
count 0
)
(while (setq filename (nth count files))
(setq filename (strcat dir "\\" filename))
(write-line (strcat "_open \"" filename "\"") scriptname)
(write-line "_purge all * no" scriptname)
(write-line "_purge all * no" scriptname)
(write-line "_purge all * no" scriptname)
(write-line "_zoom extents" scriptname)
(write-line "_qsave" scriptname)
(write-line "_close" scriptname)
(setq count (1+ count))
)
(close scriptname)
)
)
(princ)
)

It will prompt you to select a file in the directory that you want to work with - choose any one drawing.

It will then create a script file, batch.scr, in the root of C: - change these in the code if you want (note that directories are separated with "\\" or "/" in lisp, not "\"). It loops through all the files and adds an OPEN, PURGE, ZOOM, SAVE and CLOSE to the script file. When it's finished you can check the batch.scr file to ensure it looks ok (it did for my small test directory):

_open "C:\Users\scott\Documents\DIWI Projects\HTP MVA0.dwg"
_purge all * no
_purge all * no
_purge all * no
_zoom extents
_qsave
_close
_open "C:\Users\scott\Documents\DIWI Projects\Jct L1-02 Swept Paths (2009-09-07).dwg"
_purge all * no
_purge all * no
_purge all * no
_zoom extents
_qsave
_close

Now load the script file - type SCR at the command line and browse to C:\batch.scr. Go for a tea.

Hope this helps.

S
Message 8 of 62
DanielCoe
in reply to: Ak_homegrown

Slick! That's Awesome! However, I see it does all the files within the folder. Edited by: DanielCoe on Oct 14, 2009 8:33 AM
Message 9 of 62
thatcadguy
in reply to: Ak_homegrown

And you want it do to what? Only the files you select?

If you're wanting it to open all nested files, check this blog post of mine: http://thatcadguy.blogspot.com/2009/10/batch-processing-autocad-drawings.html

The function is called listAllFiles, it's nested inside the c:batch function shown there,
Message 10 of 62
DanielCoe
in reply to: Ak_homegrown

Yes, the EZScript-Pro. I am using version 3.1 with AutoCAD 2010.

If you have your Properties, Layer, DesignCenter Palettes on before running any script; EZScript-Pro will turn then off as well as your ribbon. The next time you open a drawing in AutoCAD, you will have to reload all of the palettes and the ribbon.

Now when I was running EZScript-Pro with AutoCAD 2009, it would crash if the Layer pallette was on.
Message 11 of 62
crashcup99
in reply to: Ak_homegrown

Could I trouble you to provide the script that EZScript-Pro creates (Ezscript.scr) and a sample drawing (.DWF is fine) so I can try to recreate what you have seen? This is a first.

Ezscriptpro@yahoo.com
Message 12 of 62
Ak_homegrown
in reply to: Ak_homegrown

Scott,

Thank you very much for your post, it worked great and is exactly what I needed! (And not above my comprehension!)
Message 13 of 62
crashcup99
in reply to: Ak_homegrown



If you use EZScript-PRO on AutoCAD 2010, simply put the command RIBBON at the beginning of your scripts.

You can also put this ion the ACAD.lsp file.

 

This will always make sure that the ribbon does not 'dissapear' when a script is run from the command line.

Message 14 of 62
e2luc
in reply to: Ak_homegrown

Read this Lisp Routine Topic and thought if we could add Bind Xrefs and Explode to the mix that this could be powerful.  But do we even have to open the drawing?

 

Have it run the lisp Routine; Bind Insert Xrefs, Explode, Purge All, Zoom Extents, then Save

 

Any Help on this topic

Message 15 of 62
mn08jhh
in reply to: scottbolton

Hi,

This is a sever thread revival, but this script is superb, thank you very much.

I am not very experienced with LSP and am wondering whether it's possible to modify the routine slightly to add a function that not only zooms to extents, but changes the view to SE, zooms extents, and sets home. Further to that, it would be great if it could do select all and set to Layer 0.

The reason why I ask is that all our models, which are blocks, tend to be saved on the outlines layer, which is causing problems. I need to move them en mass to Layer 0, and they are all blocks already so the save all function won't cause a problem.

Thanks in advance,

Jonathon
Message 16 of 62
mn08jhh
in reply to: mn08jhh

Also, perhaps, setting the display to shaded...

Message 17 of 62
aqdam1978
in reply to: Ak_homegrown

;; purge, zoom and saves all drawings in a folder
;; By Abbas Aqdam
(defun C:PZT ( / path files dwg sf )
(if (or (= (getvar "SDI") 0) (> (getvar "DBMOD") 0))
   (alert "Please: \n\n1-SAVE and close all open drawing!\n\n2-Set SDI to 0")
   (progn
      (setq path "C:\\TEST\\")
      (setq files (vl-directory-files path "*.dwg" 1))
      (if (> (length files) 0)
         (progn
            (setq sf (open (strcat path "T.SCR") "w"))
            (write-line "Filedia" sf)
            (write-line "0" sf)
            (foreach dwg files
               (write-line "open" sf)
               (write-line (strcat "\"" path dwg "\"") sf)
               (write-line "(command \"purge\" \"a\" \"*\" \"N\")" sf)
               (write-line "(command \"zoom\" \"e\" \"zoom\" \"s\" \"0.95x\")" sf)
               (write-line "qsave" sf)
            );foreach
            (write-line "Filedia" sf)
            (write-line "1" sf)
            (close sf)
            (command "script" (strcat path "t.scr"))
         );progn
         (Alert (strcat "There is no dwg files in " path "!"))
      );if
   );progn
);if
);defun

 

Message 18 of 62
j.shell
in reply to: scottbolton

Refering to scottboltonThis is a great tool. However I think if we could add 1 more function it would make it a super tool. Currently running this only opens and zooms to extents either the model or layout space the dwg was last saved in. I have dwgs that have multiple layouts that are saved wherever the last person who saved it was working at. If this could go to all of a dwgs layouts and model space to zoom extents it would be amazing!!!! Here is an individual dwg lsp I found for what I am describing. If there is a way we could combine the two it would be golden.

 

 

(defun C:ZEA (/ acad acdoc aclay)
(setq acad (vlax-get-acad-object)
acdoc (vla-get-ActiveDocument acad)
aclay (vla-get-ActiveLayout acdoc)
); setq
;; Modified by Bob Shaw 10-Nov-2011 for John Wagner at Davis Bews Design Group
(vlax-for layout (vla-get-Layouts acdoc)
(vla-put-ActiveLayout acdoc layout)
(if (/= "Model" (getvar "ctab"))
(progn
(command "_pspace")
(princ)
(vla-ZoomExtents acad)
); progn
); if
); vlax-for
(vla-put-ActiveLayout acdoc aclay)
(princ)
); function

Tags (1)
Message 19 of 62
pendean
in reply to: j.shell

If anyone has a current AutoCAD version (2012 or higher), grab two freeware apps from the Autodesk Exchange: REDICAL PURGE (excellent general purpose purger that's better than PURGE command alone) and DRAWING PURGE (gets rid of DGN items, a big problem for many these days).

There are other for-purchase apps that combine the functionality of both: http://apps.exchange.autodesk.com/ACD/en/Home/Index
I believe both can be run inside Lisps.
Message 20 of 62
mracad
in reply to: pendean

I had a similar problem a few days ago and ended up spending a long, cold Saturday trying to figure out the AcCoreConsole. Here is a simple batch file and script file (THAT I DID NOT TEST). Be sure to change the drawing file and script file locations in Fix_Drawing.bat file. NOTE - I would copy a few files into a new folder for testing. It is amazing how fast it processes drawing, a few seconds for each drawing (depending on size).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost