Author Topic: Update drawings in a directory  (Read 8541 times)

0 Members and 1 Guest are viewing this topic.

aicm

  • Guest
Update drawings in a directory
« on: October 26, 2005, 01:19:27 PM »
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)


pmvliet

  • Guest
Re: Update drawings in a directory
« Reply #1 on: October 26, 2005, 03:01:09 PM »
Are you taking older versions and then brinigng them to the 2k4, 2k5 and 2k6 format?
If this is true, then Autodesk has a batch convertor. Not trying to ignore your lisp, just saying there are other methods readily available. There is always the fact that maybe you can download or install any other software...

Pieter

Arizona

  • Guest
Re: Update drawings in a directory
« Reply #2 on: October 26, 2005, 03:17:35 PM »
It has been a very long time since I have done any lisp, but where is listpath actually being defined?

aicm

  • Guest
Re: Update drawings in a directory
« Reply #3 on: October 26, 2005, 03:20:28 PM »
Are you taking older versions and then bringing them to the 2k4, 2k5 and 2k6 format?
If this is true, then Autodesk has a batch converter. Not trying to ignore your lisp, just saying there are other methods readily available. There is always the fact that maybe you can download or install any other software...

Pieter

Pieter,
I want to thank you for your response and will look into this alternative immediately.
Larry

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Update drawings in a directory
« Reply #4 on: October 26, 2005, 08:57:06 PM »
You can also take a look to BLP 1.0 (Batch Lisp Processor)

here
« Last Edit: October 26, 2005, 09:06:10 PM by Andrea »
Keep smile...

hudster

  • Gator
  • Posts: 2848
Re: Update drawings in a directory
« Reply #5 on: October 27, 2005, 04:25:05 AM »
From my very basic understanding of lisp, all I can see this routine does is writes a scrpt file for all files in a directory, zooms to extents and then saves the file.

Wouldn't it be just as easy to write a script like this,
Code: [Select]
;;;script file to zoom extents and save
zoom
extents
qsave
;;;end of script

Then run it on a directory using either AutoCADs own script program, or EZscript, oh annd EZscript can also run lisp routines on files as well.

This would have the added bonus of not leaving any files behind when it's finished.

Or have I missed something?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

deegeecees

  • Guest
Re: Update drawings in a directory
« Reply #6 on: October 27, 2005, 12:25:59 PM »
This may be a big bite to chew on but, have you looked into ObjectDBX? You can "poke" into AutoCAD drawings without opening them, or without AutoCAD if you use it in a VB app.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Update drawings in a directory
« Reply #7 on: October 27, 2005, 12:35:01 PM »
Sorry, I'm swamped this morning as much as I'd like to pour a bunch of info into this thread. What I'd say about object dbx is just be mendful that said technology screws up the alignment of modified text / attribute entites.

One way to fix said aberration (without resorting to an object arx solution) is to batch open them after you complete all your dbx processing (not via object dbx) and do a simple entupd on all the affected entities and then a save. Unfortunately this does away with your plans to do all this without actually opening them up.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

deegeecees

  • Guest
Re: Update drawings in a directory
« Reply #8 on: October 27, 2005, 12:39:01 PM »
OK, here's the easy way:

Make sure AutoCAD is set to save in the version you require, then run this...

Code: [Select]
;batch_anything.lsp
;Created by P.R. Donnelly
;Date: Sept of 2002
;Description: Batch Process
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;start prog

(DEFUN C:batch_anything ()

;;;;;;;;;;;;;;;;;;;;;;;;;Select directory to be processed

(setq dfil (getfiled "Select ONE FILE In The Directory You Want To Batch Process" "p:/" "dwg" 0))
(setq wutdir (vl-filename-directory dfil))
(setq wutfiles (vl-directory-files wutdir "*.dwg"))

(setq scrfile (open "c:\\scrfile.scr" "w"))
(close scrfile)
(setq scrfile (open "c:\\scrfile.scr" "a"))

(foreach n wutfiles
(setq n2 (strcat "\""wutdir "\\" n "\""))
(setq n2 (vl-string-translate "\\" "\\" n2))
(setq scrline (strcat "open" " " n2 " " " "qsave" " " "close"));;;;;;;COMMANDS FOR BATCH GO HERE
(write-line scrline scrfile)
(princ)
)

(close scrfile)
(command "script" "c:\\scrfile")

(princ "\n***Batch complete.***")
(princ)


);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DEFUN

This will create a file called scrfile.scr on your C:\ drive, delete after use if you want.

Arizona

  • Guest
Re: Update drawings in a directory
« Reply #9 on: October 27, 2005, 12:47:39 PM »
I have a vba program that does what you want. If you will pm me I will send it to you. You will need to change (I'll show you where) the version it is saving to. Also I have never tested this on newer releases of Acad although I see nothing in it that wouldn't run under 2004 - 2006.

Fatty

  • Guest
Re: Update drawings in a directory
« Reply #10 on: October 27, 2005, 01:22:21 PM »
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.

Hi Larry

If you need rewrite this lisp try this one

(tested in A2005)

Thank you

f.

[code
;; BASED ON BCONVERT.LSP

;; MAIN ROUTINE
(prompt "\n\t***\tType BCD to run batch file operation.\t***\n")

(defun C:BCD (/ afile file_list strp_path)
  (alert "This routine does a zoom extents on an entire directory. Click OK to continue.")
  (setq afile (getfiled (strcat "Select the first DWG file in folder "
             "to be processed") "" "DWG" 0))
  (setvar "filedia" 0)
  (setvar "cmdecho" 0)
  (if afile
    (bprocess afile )
      (alert "You must select any dwg file of the directory \n
      to be processed. Conversion halted.")
  )
      (setvar "filedia" 1)
    (setvar "cmdecho" 1)
  (princ)
)

;; Core processing
  (defun bprocess (afile / file_list scrfile fp file)

      (setq strp_path (strcat (vl-filename-directory afile) "\\"))
;;;    (setq tempfile (strcat strp_path "temp.dwg"))
;;;    (if (findfile tempfile)
;;;      (command "_SAVE" tempfile "y")
;;;      (command "_SAVE" tempfile)
;;;    );=>Why?
  (setq file_list (vl-directory-files strp_path "*.dwg"))
  (setq file_list (mapcar (function (lambda (x) (strcat strp_path x))) file_list))
    (setq scrfile (strcat strp_path "convertst.scr"))  ; Begin building processing script
    (setq fp (open scrfile "w"))
    (princ (strcat "CMDECHO" " " "0" "\n") fp)
    (princ (strcat "ATTDIA" " " "0" "\n") fp)
    (foreach file file_list     ; Add each drawing to script
      (write-line (strcat "_OPEN " "\"" file "\"") fp) ; OPEN
      (write-line (strcat "_ZOOM" " " "_E") fp)   ; ZOOM...E
      (write-line (strcat "_QSAVE\n" " " "_CLOSE") fp)  ; SAVE&CLOSE

)
 
(princ (strcat "CMDECHO" " " "1" "\n") fp)
(princ (strcat "ATTDIA" " " "1" "\n") fp)

    (close fp)
    (alert "Be patience...now is load script")
    (command "_DELAY" 1500)
    (command "_SCRIPT" scrfile)   ; Run the script

    (princ)
  )
Code: [Select]

deegeecees

  • Guest
Re: Update drawings in a directory
« Reply #11 on: October 27, 2005, 01:30:33 PM »
AICM,

Let us know how things turn out.

Deeg

aicm

  • Guest
Re: Update drawings in a directory
« Reply #12 on: October 27, 2005, 01:56:05 PM »
Quote

Hi Larry
If you need rewrite this lisp try this one
(tested in A2005)
Thank you

f.

[code
;; BASED ON BCONVERT.LSP
.........
Quote



Fatty,
This one is a winner.......... fantastic ......... now I just heed to study how you did this.
Looks like I'm going to have to stay up at nights with Stig's LISP course and Kenny's Afra LISP downloads and get my ar$e in gear and lean this stuff.

We can't thank you enough for taking the time to help.
Larry

PS.
I tried this one first and will take the other suggestions for a spin later today or tonight.

Thank you all again
Larry

pmvliet

  • Guest
Re: Update drawings in a directory
« Reply #13 on: October 27, 2005, 01:56:53 PM »
This just proves the fact that there are a gazzilion ways to accomplish the same thing...
Some very simple, some very complex but I guess that all depends on your knowledge....

Pieter

deegeecees

  • Guest
Re: Update drawings in a directory
« Reply #14 on: October 27, 2005, 02:01:59 PM »
Make sure you change this:

Code: [Select]
    ...(close fp)
    (alert "Be patience...now is load script")
    (command "_DELAY" 1500)
    (command "_SCRIPT" scrfile)   ; Run the script

    (princ)

To this:

Code: [Select]
    ...(close fp)
    (alert "ALL YOUR BASE ARE BELONG TO US")
    (command "_DELAY" 1500)
    (command "_SCRIPT" scrfile)   ; Run the script

    (princ)

It'll make all the difference.  :lmao: