Author Topic: update drawings in a folder  (Read 1577 times)

0 Members and 1 Guest are viewing this topic.

Big G

  • Bull Frog
  • Posts: 415
update drawings in a folder
« on: December 10, 2007, 11:27:57 PM »
lo all!

Old block library (R12) where thumbnails display as an icon rather than the drawing.....I found this lisp file which mostly does what i want it to, but i want to add in a script file to...
1)Delete all centrelines    2)change all layers to 0 (and make current layer)    3) change all colours to bylayer   4)purge  (scripting itself is easy enough but just dont know at what part to add it in......)

any advise would be pukka!

Hi -- for the first time,
We have a lisp routine that updates all the drawings in a directory to the current version of ACAD.  We now run the routine, which worked in the past, and it crashes with a DOS window appearing that says:
"The system can not find the specified  path"

Could someone take a look at this for us and correct whatever is going wrong.
We know zip about lisp ... been meaning to learn but the work load here is such that finding the time to do the studying is next to impossible.

Using ACAD 2006
Thanks,
Larry
Code: [Select]

;;
;; BCONVERT.LSP
;;
;; Performs a Drawing Open, ZOOM Extents and Save on an entire Directory
;;
;; Note: This utility leaves behind 3 scratch files in the target Directory:
;;
;;  Convertst.scr
;;  Temp.dwg
;;  Temp.txt
;;
;; These 3 scratch files may be deleted after processing is complete
;;
;; TO USE:
;; Setup target Directory on local HDD containing ONLY drawings to convert
;; Launch AutoCAD
;; Set SDI sysvar to 1
;; Type (load "bconvert.lsp")
;; Type BCD
;;  Respond to prompts, navigate to target Directory and select first listed drawing
;;  Processing will be automatic
;; Set SDI sysvar to 0
;; Close AutoCAD
;;
 
(setq *process "")
 
;;
;; MAIN ROUTINE
;;
(defun C:BCD (/ afile)
  (alert "This routine does a zoom extents on an entire directory. Click OK to continue.")
  (setq afile (getfiled (strcat "Select the first file of the directory "
             "to be processed") "" "DWG" 0))
  (if afile
    (bprocess (strp_path afile))
      (alert "You must select the first file of the directory to be processed. Conversion halted.")
  )
)
 
;;
;; Core processing
;;
  (defun bprocess(listpath / tempfile filelist scrfile fp file)
    (setq tempfile (strcat listpath "temp.dwg"))
    (if (findfile tempfile)
      (command "_SAVE" tempfile "y")
      (command "_SAVE" tempfile)
    )
    (setq filelist (get_file_list listpath "DWG"))  ; Build list of drawings to process
    (setq scrfile (strcat listpath "convertst.scr"))  ; Begin building processing script
    (setq fp (open scrfile "w"))
    (foreach file filelist     ; Add each drawing to script
      (write-line (strcat "OPEN " "\"" listpath file "\"") fp) ; OPEN
      (write-line (strcat "Zoom") fp)   ; ZOOM...
      (write-line (strcat "E") fp)    ; ...EXTENTS
      (write-line (strcat *process "_QSAVE") fp)  ; SAVE
    )
    (close fp)
    (command "_SCRIPT" scrfile)   ; Run the script
    (princ)
  )
 
;;
;; Return file list in listpath directory with extention ext
;;
  (defun get_file_list (listpath ext / listfile fp fileline linelen
                     startnum filelist scr file extention filename c)
    (setq listfile "temp.txt")
    (setq listfile (strcat listpath listfile))
    (setq fp (open listfile "w"))
    (write-line "File list for this directory:" fp)
    (close fp)
    (setq filelist '())
    (setq scr (strcat "dir " listpath " > " listfile))
    (command "_shell" scr)
    (command "_delay" 2000)
    (setq fp (open listfile "r"))
    (while (setq fileline (read-line fp))
      (setq linelen (strlen fileline))
      (setq startnum 40) 
      (if (= (substr fileline startnum 1) ":")
        (setq startnum 45) 
      )
      (if (> linelen (+ startnum 3))
        (progn
          (setq file (substr fileline startnum (1+ (- linelen startnum))))
          (setq extention (substr file (- (strlen file) 2) 3))
          (if (= (strcase extention) (strcase ext))
            (setq filelist (append filelist (list file)))
          )
        )
      )
    )
    (close fp)
    (setq filelist filelist)
  )
 
;;
;; Process the drawing file name
;;
  (defun strp_name (full_str / count full_count not_found)
    (if full_str
      (progn
        (setq count (strlen full_str))
        (setq full_count count)
        (setq not_found T)
        (while not_found
          (if
            (or
              (= (substr full_str count 1) "\\")
              (= (substr full_str count 1) "/")
            )
              (setq not_found nil)
              (setq count (- count 1))
          )
        )
        (substr full_str (1+ count)  (- full_count 1) )
      )
      (eval "")
    )
  )
 
;;
;; Strip the path information from the file name
;;
  (defun strp_path(fullname / path name)
    (setq name (strp_name fullname))
    (setq path (substr fullname 1 (- (strlen fullname) (strlen name))))
  )
 
(princ)


I thought i seen the light at the end of the tunnel. But it was just someone with a torch bringing me more work.
"You have to accept that somedays youre the pigeon and  somedays youre the statue"

lispman21

  • Guest
Re: update drawings in a folder
« Reply #1 on: December 14, 2007, 12:47:57 PM »
Give this a try i think its what your looking for if i understood you right.

Code: [Select]
;;
;; BCONVERT.LSP
;;
;; Performs a Drawing Open, ZOOM Extents and Save on an entire Directory
;;
;; Note: This utility leaves behind 3 scratch files in the target Directory:
;;
;;  Convertst.scr
;;  Temp.dwg
;;  Temp.txt
;;
;; These 3 scratch files may be deleted after processing is complete
;;
;; TO USE:
;; Setup target Directory on local HDD containing ONLY drawings to convert
;; Launch AutoCAD
;; Set SDI sysvar to 1
;; Type (load "bconvert.lsp")
;; Type BCD
;;  Respond to prompts, navigate to target Directory and select first listed drawing
;;  Processing will be automatic
;; Set SDI sysvar to 0
;; Close AutoCAD
;;
 
(setq *process "")
 
;;
;; MAIN ROUTINE
;;
(defun C:BCD (/ afile)
  (alert "This routine does a zoom extents on an entire directory. Click OK to continue.")
  (setq afile (getfiled (strcat "Select the first file of the directory "
             "to be processed") "" "DWG" 0))
  (if afile
    (bprocess (strp_path afile))
      (alert "You must select the first file of the directory to be processed. Conversion halted.")
  )
)
 
;;
;; Core processing
;;
  (defun bprocess(listpath / tempfile filelist scrfile fp file)
    (setq tempfile (strcat listpath "temp.dwg"))
    (if (findfile tempfile)
      (command "_SAVE" tempfile "y")
      (command "_SAVE" tempfile)
    )
    (setq filelist (get_file_list listpath "DWG"))  ; Build list of drawings to process
    (setq scrfile (strcat listpath "convertst.scr"))  ; Begin building processing script
    (setq fp (open scrfile "w"))
    (foreach file filelist     ; Add each drawing to script
      (write-line (strcat "OPEN " "\"" listpath file "\"") fp) ; OPEN
      (write-line (strcat "Zoom") fp)   ; ZOOM...
      (write-line (strcat "chprop") fp)    ; ...Change Properties
      (write-line (strcat "all") fp)    ; ...all entities
      (write-line (strcat "") fp)    ; ...ENTER
      (write-line (strcat "la") fp)    ; ...Layer
      (write-line (strcat "0") fp)    ; ...0
      (write-line (strcat "c") fp)    ; ...Color
      (write-line (strcat "BYLAYER") fp)    ; ...BYALYER
      (write-line (strcat "layer") fp)    ; ...Layer
      (write-line (strcat "s") fp)    ; ...Set
      (write-line (strcat "0") fp)    ; ...0
      (write-line (strcat "") fp)    ; ...ENTER
      (write-line (strcat "purge") fp)    ; ...Purge
      (write-line (strcat "a") fp)    ; ...ALL
      (write-line (strcat "") fp)    ; ...ENTER
      (write-line (strcat "n") fp)    ; ...No
      (write-line (strcat *process "_QSAVE") fp)  ; SAVE
    )
    (close fp)
    (command "_SCRIPT" scrfile)   ; Run the script
    (princ)
  )
 
;;
;; Return file list in listpath directory with extention ext
;;
  (defun get_file_list (listpath ext / listfile fp fileline linelen
                     startnum filelist scr file extention filename c)
    (setq listfile "temp.txt")
    (setq listfile (strcat listpath listfile))
    (setq fp (open listfile "w"))
    (write-line "File list for this directory:" fp)
    (close fp)
    (setq filelist '())
    (setq scr (strcat "dir " listpath " > " listfile))
    (command "_shell" scr)
    (command "_delay" 2000)
    (setq fp (open listfile "r"))
    (while (setq fileline (read-line fp))
      (setq linelen (strlen fileline))
      (setq startnum 40) 
      (if (= (substr fileline startnum 1) ":")
        (setq startnum 45) 
      )
      (if (> linelen (+ startnum 3))
        (progn
          (setq file (substr fileline startnum (1+ (- linelen startnum))))
          (setq extention (substr file (- (strlen file) 2) 3))
          (if (= (strcase extention) (strcase ext))
            (setq filelist (append filelist (list file)))
          )
        )
      )
    )
    (close fp)
    (setq filelist filelist)
  )
 
;;
;; Process the drawing file name
;;
  (defun strp_name (full_str / count full_count not_found)
    (if full_str
      (progn
        (setq count (strlen full_str))
        (setq full_count count)
        (setq not_found T)
        (while not_found
          (if
            (or
              (= (substr full_str count 1) "\\")
              (= (substr full_str count 1) "/")
            )
              (setq not_found nil)
              (setq count (- count 1))
          )
        )
        (substr full_str (1+ count)  (- full_count 1) )
      )
      (eval "")
    )
  )
 
;;
;; Strip the path information from the file name
;;
  (defun strp_path(fullname / path name)
    (setq name (strp_name fullname))
    (setq path (substr fullname 1 (- (strlen fullname) (strlen name))))
  )
 
(princ)