zoom extend and save - PLEASE HELP!

zoom extend and save - PLEASE HELP!

Anonymous
Not applicable
3,122 Views
11 Replies
Message 1 of 12

zoom extend and save - PLEASE HELP!

Anonymous
Not applicable

Hello everyone,

 

This lisp might be very usefull:

 

I need help with lisp that asking for Folder \ Current drawing \ All tabs 

 

the default should be current drawing.

 

when pressing Enter (for current drawing) the drawing will do Zoom Extend - save the drawing - and close the drawing.

when pressing A (for all tabs) all the drawings in the tabs will be Zoom Extend - save the drawing - and close the drawing.

when pressing F (for folder) the drawing explorer will open and let the user choose a folder , and when folder is being choosed -all the drawing in it will Zoom Extend - save the drawing - and close the drawing.

 

The purpose of this lisp is to save time by saving and closing the drawing but only after zoom extend it for better preview.

 

Thank you very much in advance.

 

Eyal

 

0 Likes
3,123 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant

I don't think that will be possible.  An AutoLisp routine cannot start in one drawing and continue in another, which it would need to do if it's to Zoom and Save in any drawing other than the one you start it in.  There may be something that will do it by way of a SCRIPT and software to apply such a thing to multiple drawings, such as ScriptPro -- do some Searching.

Kent Cooper, AIA
0 Likes
Message 3 of 12

Anonymous
Not applicable

OK , and except the folder ,

Can you do it only for the current drawing , and all the drawings tabs that opens?

 

 

0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

OK , and except the folder ,

Can you do it only for the current drawing , and all the drawings tabs that opens?


Try this.  I'm sure there are others like it out there [probably also here on these Forums] -- again, a little Searching should find several.

Kent Cooper, AIA
0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi Kent1Cooper,

Thank you but it is not what I wanted.

 

I need lisp that asks for Current drawing \ All tabs 

 

the default should be current drawing.

 

when pressing Enter (for current drawing) the drawing will do Zoom Extend - save the drawing - and close the drawing.

when pressing A (for all tabs) all the drawings in the tabs will be Zoom Extend - save the drawing - and close the drawing.

 

I want to have the option to decide if I want to do the (zoom extend and close ) for the current drawing so the other tabs will not close ,

 

and the option to zoom extend and close all the tabs ,

 

It's veru important for my work. 

 

I saw a lot of lisps in the net , but they are not what I need.

 

Thank you.

 

0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

In the link in my previous Reply, I was thinking of the layout tabs within a single drawing [typically at the bottom of the screen].  If you mean the different-drawing tabs [typically across the top], read the beginning of my first Reply again.

Kent Cooper, AIA
0 Likes
Message 7 of 12

SeeMSixty7
Advisor
Advisor

Let's address these as separate processes.

 

FOLDER OPTION - Pretty Easy

Have user select a drawing from the folder to be processed. (use getfiled) to accomplish this part.

 

Then shell out to DOS(or use other AutoLISP means) do a directory listing of all files in that folder using something like

DIR *.DWG /b /s >myfolderscript.txt

 

Then open the file using autolisp and then use lisp to generate a script file to open each dwg and run ZOOM E QSAVE on them all. Then launch the script.

Note: Exclude files you have open, Exclude files others have open.

 

CURRENT DRAWING - Really Easy

(command "ZOOM" "E" "QSAVE" "CLOSE")

 

OTHER DRAWINGS OPENED - Not Sure yet

As Kent1Cooper stated, I am not sure this one is possible with AutoLISP, but will look into it.

 

Good luck

0 Likes
Message 8 of 12

Anonymous
Not applicable

I think it can be possible with "vla-zoomextents" method.

 

 

0 Likes
Message 9 of 12

roland.r71
Collaborator
Collaborator

Hi there,

 

I might be able to help on the folder & open drawings part. IF you don't mind using DOSLIB.

 

Wrote me a 'script generator' (*.scr) just to do that, years ago. (in AutoLISP ! )

 

It allows for selecting a folder, add all dwg's (and/or dxf's) and process them 1 by 1. loading & executing *.lsp and/or execute commands.

 

It does not yet add ALL open drawings, as there was no need for that back then (we worked with SDI mode)

nor will it process layouts (again, there was no need)

 

It works with my own fileopen command which checks the files real-time to see if its open already, opened by another user or read only

(allowing you to retry or skip the file )

 

...and a bunch more features.

 

I'll dig it up when I get home, to see if I can make it fit your needs.

0 Likes
Message 10 of 12

roland.r71
Collaborator
Collaborator

Found my earlier tool, but that needs a lot work to make it 'stand-alone'. Been planning to do that, but never got to it. That will take time.

 

Meanwhile I managed to create a 'bare-bones' version for the zoom extent part on a folder. (with or without subdirectories)

 

Nothing fancy, no checks for read-only files etc. I did my best to keep it small. As it is big enough as it is. (to post as code)

 

It will make a difference between being run form an existing drawing or a new one.

As the script needs SDI mode to run, it will not work if you have multiple drawings open.

 

Note: you need the DOSlib.arx for some of the functions to work. (these are written in CAPS & all start with DOS_)

 

  (defun c:zed ( / ) ; Zoom Extent Directory
; requires DOSlib arx
(if (not DOS_VERSION) (progn (prompt "\nThis function requires DOSlib!\n")(exit)))

 (defun get_files ( dr rc / dt tl fp i l filelist)
      (setq filelist nil)
      (if (= rc 1)
         (progn
            (setq dt (DOS_DIRTREE dr))
            (setq i 0)
            (while (< i (length dt))
               (setq tl (DOS_DIR (strcat (nth i dt) "*.dwg")))
               (setq l 0)
               (while (< l (length tl))
                  (setq fp (strcat (parse_path (nth i dt)) (nth l tl)))
                  (setq filelist (append filelist (list fp)))
                  (setq l (1+ l))
               )
               (setq i (1+ i))
            )
         )
         (progn
            (setq tl (DOS_DIR (strcat dr "*.dwg")))                      
            (setq i 0)
            (while (< i (length tl))
               (setq fp (strcat (parse_path dr)(nth i tl)))
               (setq filelist (append filelist (list fp)))
               (setq i (1+ i))
            )
         )
      )
      filelist
   )
   
   (defun parse_path (path2Filename / temp i)
      (setq i 1 temp "")
      (repeat (strlen path2Filename)
         (if (= (substr path2Filename i 1) "\\")
            (setq temp (strcat temp "/"))
            (setq temp (strcat temp (substr path2Filename i 1)))
         )
         (setq i (1+ i))
      )
      temp
   )
   
   (defun scrGen ( scrdir f_list / scr_file file_w)
      (setq scr_file (strcat scrdir "/zed.scr"))
      (setq file_w (open scr_file "w"))
      (setq currentmode (getvar "SDI"))
      (setq currentfdia (getvar "FILEDIA"))
      (setq currentdwg (parse_path (strcat (getvar "DWGPREFIX") (getvar "DWGNAME"))))
      (write-line "(setvar \"SDI\" 1)" file_w)
      (write-line "(setvar \"FILEDIA\" 0)" file_w)
      (if (= (DOS_FILEP currentdwg) T)
         (progn
            (write-line "(command \"_.zoom\" \"e\")" file_w)
            (write-line "(command \"_.qsave\")" file_w)
         )
      )
      (setq i 0)
      (while (< i (length f_list))
         (setq f_name (nth i f_list))
         (setq cmd (strcat "(command \"_.fileopen\" \"" f_name "\""))
         (if (= (DOS_FILEP currentdwg) T)
            (setq cmd (strcat cmd ")"))
            (setq cmd (strcat cmd " \"y\")"))
         )
         (write-line cmd file_w)
         (write-line "(command \"_.zoom\" \"e\")" file_w)
         (write-line "(command \"_.qsave\")" file_w)
         (setq i (1+ i))
      )
      (if (= (DOS_FILEP currentdwg) T)
         (write-line (strcat "(command \"_.fileopen\" \"" currentdwg "\")") file_w)
         (write-line "(command \"_.new\" \"\")" file_w)
      )
      (if (= currentmode 0)
         (write-line "(setvar \"SDI\" 0)" file_w)
      )
      (if (= currentfdia 1)
         (write-line "(setvar \"FILEDIA\" 1)" file_w)
      )
      (close file_w)
   )

   ; *** Main ***   
   (setq files_list nil)                     ; list of filenames (incl. full path)
   (setq recursive 1)                        ; include subdirectories (1 = yes)
   (setq dir_path "C:/")                     ; starting path for file selection
   (setq scr_path "c:/temp")                 ; path for writing script
   
   ; select directory
   (setq path (DOS_GETDIR "Select directory:" dir_path))                        
   (if path
      ; get the files
      (setq files_list (get_files path recursive))
   )

   ; Ask confirmation before generation & execution of script
   (setq abort T)
   (if files_list
      (progn
         (setq lc (length files_list))
         (setq cd_TXT (strcat "Ok to start processing " (itoa lc) " file(s) ?"))
         (setq confirm (DOS_MSGBOX cd_TXT "ZED" 2 4))
         (if (/= confirm 1)
            (progn
               (scrGen scr_path files_list)
               (setq abort nil)
            )
            (prompt "\n*Cancel*")
         )
      )
   )

   (if (= abort nil)
      (command "_.script" (strcat scr_path "/zed"))
   )
   (princ)
)
0 Likes
Message 11 of 12

john.uhden
Mentor
Mentor

It's possible.  I wrote a couple of AutoLisp routines for Philadelphia Gas Works to open every drawing in a directory tree (13,000+), perform 23 tasks, and save and close each with zero errors.  You just need MDI turned on and everything can be done from one PC running one session of AutoCAD.  It needed a specific acaddoc.lsp to load and perform the tasks.

 

With some work, I could redact it for others to modify to their needs.

John F. Uhden

0 Likes
Message 12 of 12

roland.r71
Collaborator
Collaborator

@john.uhden wrote:

It's possible.  I wrote a couple of AutoLisp routines for Philadelphia Gas Works to open every drawing in a directory tree (13,000+), perform 23 tasks, and save and close each with zero errors.  You just need MDI turned on and everything can be done from one PC running one session of AutoCAD.  It needed a specific acaddoc.lsp to load and perform the tasks.

 

With some work, I could redact it for others to modify to their needs.


Of course it is. I just posted a piece of code to do just that 😛

 

The need for acaddoc probably lies in the variables and/or lisp routines. You lose them each time. You need to reload them with each dwg opened.

For easy transfer of variables I usually use .ini files. They have many advantages, although one could argue its slower.

 

Wrote me a much bigger version of the above code. With a script generator & file selection tool allowing for anything to be done with any amount of DWG's/DXF's. It doesn't directly call the fileopen function, but uses a separate script to check each file for read-only, being open, in use on a network etc. it will allow the user to either skip such files (prompted or automatically) or even a retry. All skipped files can be logged, so you know what drawings to check again.

 

One of the mayor uses I once had for it is plotting. Back when the batch plot was still just to cry about & setting revisions & manage standards (setting all defaults, overwriting any manual changes) and/or to mame drawings. (bursting all blocks and stuff, to prevent our Chinese clients from reading the drawings back into an automated system (like Elcad and/or Electrical Designer) - as extra 'protection'.

 

Anything you can do with 1 drawing, can be done to a selection of drawings.

 

Back in 2004-2007 (when I first wrote & used the lisp routines) the only way to do it, was with DOSlib.

I noticed at least some functions are now available with ACET (like reading & writing .ini files, list directories etc.)

 

Need to check on that, to see if I can rewrite it to use ACET instead of DOSlib, but if I still need DOSlib for at least 1 function, it's kinda useless to force the need for ACET as well. (currently you don't need them installed for my scripts to work, but its probably more widespread nowadays)

 

Last weekend I already finished rewriting my script generator, to be more "general purpose" & completely stand-alone.

In addition I made a few changes to my MOpen script, to work with the new generator (& new ini file)

All I need to work on is my File selection tool. Which goes way beyond just selecting a directory and add all files in it.

 

Maybe I will add my plotscript as an example, although its pretty much obsolete these days (and only works with modelspace, as it was all we used back then.)

 

Allthough it's capable of adding "the current drawing", I know of no way to add ALL open drawings. (& to switch between them and process them in a similar way as single DWG's, without opening/closing them is a different story. An impossible one, afaik (as lisp is loaded & running on the current drawing only, instead of being independant))

 

If there's a way to retrieve a list of all opened DWG's, there's a possibility. Otherwise ...

0 Likes