Author Topic: Batch Layer Export to Excel from multiple dwgs  (Read 2459 times)

0 Members and 1 Guest are viewing this topic.

One Shot

  • Guest
Batch Layer Export to Excel from multiple dwgs
« on: April 25, 2005, 10:14:44 AM »
Can someone please if did this correct.  I took the Lisp that Mark Thomas wrote and added behind a batch run lisp.  I got it to run, but it is not exporting layers.  Here is the Lisp:



Code: [Select]

(defun c:BatchRun (/ UserFile UserDir FileList File#1 DwgName FileName )
  (vl-load-com)
  (setq UserFile (getfiled "Select a drawing within the directory to process" "" "dwg" 16 ) )
  (setq UserDir  (vl-filename-directory UserFile ) )
  (setq FileList (vl-directory-files UserDir "*.dwg" 1 ) )
  (setq File#1   (open "c:/BatchRun.scr" "w" ) )
  (foreach DwgName FileList
    (setq FileName (strcat "\"" UserDir "\\" DwgName "\"" ) )
    (princ "open\n" File#1 )
    (princ (strcat FileName "\n" ) File#1 )
    (princ "(command \42._zoom\42 \42Extents\42 )\n" File#1 )
  (princ)
)

(defun c:layers2csv (/ get->layobj open->file lay lylst fo)
  (vl-load-com)

  (defun get->layrobj ()
    (vla-get-Layers
      (vla-get-ActiveDocument
        (vlax-get-acad-object)
        )
      )
    )
 
    (vlax-for lay (get->layrobj)
      (setq lylst
             (cons
               (list
                 (vlax-get-property lay 'Name)
                 (itoa (vlax-get-property lay 'Color))
                 (vlax-get-property lay 'Linetype)
                 )
               lylst
               )
            )
      )

  (if lylst
    (progn
       ; remove layer '0' and reverse the list
      (setq lylst (reverse (vl-remove (last lylst) lylst))
            ; sort the list
            lylst (vl-sort lylst '(lambda (x y) (< (car x)(car y))))
            fo (open (strcat "C:/Program Files/Brad's LISP/Layer Merging/"(getvar 'dwgname)".csv") "w"); suitable for Excel
            )
      (foreach l lylst
        (write-line (strcat (car l) "," (cadr l) "," (last l)) fo)
        )
      (close fo)
      )
    )
    (princ "_.close\n" File#1 )
    (princ "N\n" File#1 ) ; do save
  )
  (close File#1 )
  (command "._delay" "3000" ) ; wait ~3 sec to let file close
  (command "._script" "C:/BatchRun.scr" )
  (princ)
)


Thank you for all of your help,

Brad

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Batch Layer Export to Excel from multiple dwgs
« Reply #1 on: April 25, 2005, 11:01:09 AM »
Code: [Select]

; place this some where in your search path
(defun layers2csv (/ get->layobj open->file lay lylst fo)
  (vl-load-com)

  (defun get->layrobj ()
    (vla-get-Layers
      (vla-get-ActiveDocument
        (vlax-get-acad-object)
        )
      )
    )
 
    (vlax-for lay (get->layrobj)
      (setq lylst
             (cons
               (list
                 (vlax-get-property lay 'Name)
                 (itoa (vlax-get-property lay 'Color))
                 (vlax-get-property lay 'Linetype)
                 )
               lylst
               )
            )
      )

  (if lylst
    (progn
       ; remove layer '0' and reverse the list
      (setq lylst (reverse (vl-remove (last lylst) lylst))
            ; sort the list
            lylst (vl-sort lylst '(lambda (x y) (< (car x)(car y))))
            fo (open (strcat "C:/"(getvar 'dwgname)".csv") "w"); suitable for Excel
            )
      (foreach l lylst
        (write-line (strcat (car l) "," (cadr l) "," (last l)) fo)
        )
      (close fo)
      )
    )
  )
 

(defun c:BatchRun
  (/ UserFile UserDir FileList File#1 DwgName FileName)
  (vl-load-com)
  (setq
UserFile (getfiled
  "Select a drawing within the directory to process"
  ""
  "dwg"
  16
  )
)
  (setq UserDir (vl-filename-directory UserFile))
  (setq FileList (vl-directory-files UserDir "*.dwg" 1))
  (setq File#1 (open "c:/BatchRun.scr" "w"))

  (foreach DwgName FileList
(setq FileName (strcat "\"" UserDir "\\" DwgName "\""))
(write-line "open" File#1)
(write-line FileName File#1)
(write-line "(command \42._zoom\42 \42Extents\42 )" File#1)
(write-line "(load \"layers2csv\")" File#1)
(write-line "(layers2csv)" File#1)
;(princ)
)

  (close File#1)
 
  (command "._delay" "3000") ; wait ~3 sec to let file close
  (command "._script" "C:/BatchRun.scr")
  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

One Shot

  • Guest
Batch Layer Export to Excel from multiple dwgs
« Reply #2 on: April 25, 2005, 01:14:30 PM »
I have done this but I am not getting any .csv file created.  What could be going on?

M-dub

  • Guest
Batch Layer Export to Excel from multiple dwgs
« Reply #3 on: April 25, 2005, 01:15:26 PM »
You looked in the root of C:, right?

One Shot

  • Guest
Batch Layer Export to Excel from multiple dwgs
« Reply #4 on: April 25, 2005, 02:06:58 PM »
Quote from: M-dub
You looked in the root of C:, right?


This is where I am having them to go:
Code: [Select]

fo (open (strcat "C:/Program Files/Brad's LISP/Layer Merging/"(getvar 'dwgname)".csv") "w"); suitable for Excel