Author Topic: Zoom Extents to all dwg files in subfolders  (Read 3602 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Zoom Extents to all dwg files in subfolders
« on: August 22, 2014, 01:32:23 PM »
I wonder has anyone solved this trivial problem... Suppose we have hundreds of DWGs not zoomed properly after last saved session... I know ObjectDBX can't help, but I am seeking for the fastest solution like ODBX... Have anyone from ADESK thought ab this... This problem dates from 2005...

All I have is not working ODBX code

Code: [Select]
(defun c:odbx-zoom-extents ( / *error* getfiles fullfilenames odbx )

  (vl-load-com)
 
  (defun *error* ( msg )
    (if (and odbx (not (vlax-object-released-p odbx)))
      (vlax-release-object odbx)
    )
    (if msg (prompt msg))
    (princ)
  )
 
  (defun getfiles ( path / dirs files )
    (setq path (strcat path "\\"))
    (setq dirs (vl-directory-files path nil -1))
    (setq dirs (vl-remove "." dirs))
    (setq dirs (vl-remove ".." dirs))
    (setq files (vl-directory-files path "*.dwg" 1))
    (setq fullfilenames (append fullfilenames (mapcar '(lambda ( x ) (strcat path x)) files)))
    (mapcar '(lambda ( x ) (getfiles (strcat path x))) dirs)
    fullfilenames
  )

  (setq fullfilenames (getfiles (vl-filename-directory (getfiled "Select main directory" "" "" 4))))
  (setq odbx (vla-getinterfaceobject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." (itoa (atoi (getvar 'acadver))))))
  (foreach file fullfilenames
    (vla-open odbx file)
    (vla-zoomextents (vla-get-application odbx))
    (vla-saveas odbx file)
  )
  (*error* nil)
  (princ)
)

Kind regards, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Zoom Extents to all dwg files in subfolders
« Reply #1 on: August 22, 2014, 04:10:05 PM »
Only methods applicable to the Document object may be applied to the ObjectDBX Document - as far as I am aware, the ZoomExtents method will only operate on the active drawing.

I would recommend using a simple Script to open/process/save/close your drawings.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Zoom Extents to all dwg files in subfolders
« Reply #2 on: August 22, 2014, 04:13:00 PM »
thats what I would do as well.
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

danallen

  • Guest
Re: Zoom Extents to all dwg files in subfolders
« Reply #3 on: August 22, 2014, 04:36:23 PM »
why not add zoom extents to your lisps at drawing open instead? then no need to process and change time stamps

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Re: Zoom Extents to all dwg files in subfolders
« Reply #4 on: August 23, 2014, 07:36:40 AM »
All I could think till now is this code - it works, but I don't know how much data can script support... And you'll have to delete manually or through (mr) function file "c:\mr.scr"... I've noticed that when (vl-filename-mktemp) creates temporary unnamed .scr in temp folder, then when executing _.script command, it comes to bug - first character of first line of scr file is duplicated and therefore command isn't recognized correctly, which causes that whole script fails... So I intentionally put filename "c:\mr.scr" and it worked... Make sure c:\ is read-write enabled - allow this in windows settings...

Code - Auto/Visual Lisp: [Select]
  1. (defun mr nil
  2.   (if (findfile "c:\\mr.scr") (vl-file-delete "c:\\mr.scr"))
  3.   (setq mr nil)
  4.   (princ)
  5. )
  6.  
  7. (defun c:zoomextents ( / *error* getfiles scroperation fd fullfilenames )
  8.  
  9.   (defun *error* ( msg )
  10.     (if fd (setvar 'filedia fd))
  11.     (if msg (prompt msg))
  12.     (princ)
  13.   )
  14.  
  15.   (defun getfiles ( path / dirs files )
  16.     (setq path (strcat path "\\"))
  17.     (setq dirs (vl-directory-files path nil -1))
  18.     (setq dirs (vl-remove "." dirs))
  19.     (setq dirs (vl-remove ".." dirs))
  20.     (setq files (vl-directory-files path "*.dwg" 1))
  21.     (setq fullfilenames (append fullfilenames (mapcar '(lambda ( x ) (strcat path x)) files)))
  22.     (mapcar '(lambda ( x ) (getfiles (strcat path x))) dirs)
  23.     fullfilenames
  24.   )
  25.  
  26.   (defun scroperation ( fullfilename / fn )
  27.     (if (not (findfile "c:\\mr.scr"))
  28.       (progn
  29.         (vl-filename-mktemp "c:\\mr.scr")
  30.         (setq fn (open "c:\\mr.scr" "w"))
  31.       )
  32.       (setq fn (open "c:\\mr.scr" "a"))
  33.     )
  34.     (write-line "open" fn)
  35.     (write-line (strcat "\"" fullfilename "\"") fn)
  36.     (write-line "zoom" fn)
  37.     (write-line "e" fn)
  38.     (write-line "qsave" fn)
  39.     (write-line "close" fn)
  40.     (close fn)
  41.     (princ)
  42.   )
  43.  
  44.   (setq fd (getvar 'filedia))
  45.   (setvar 'filedia 0)
  46.   (alert "After execution of routine, type (mr) to finish routine task properly")
  47.   (setq fullfilenames (getfiles (vl-filename-directory (getfiled "Select main directory" "" "" 4))))
  48.   (foreach file fullfilenames
  49.     (scroperation file)
  50.   )
  51.   (command "_.script" "c:\\mr.scr")
  52.   (*error* nil)
  53. )
  54.  

M.R.
« Last Edit: August 24, 2014, 06:07:01 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube