Author Topic: Print Layers (or export to Word / Excel)  (Read 4307 times)

0 Members and 1 Guest are viewing this topic.

M-dub

  • Guest
Print Layers (or export to Word / Excel)
« on: May 04, 2004, 12:56:16 PM »
As the subject states, I'm looking for something that will either print out the layers in a drawing (Acad2000) or export them to an Excel spreadsheet or Word document.  Anyone have any ideas?  (Besides -layer and copying all that stuff to Word and all that garbage...I've got Freakin' TONS of layers in this one drawing in particular.)

Thanks a million!

Mike

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Print Layers (or export to Word / Excel)
« Reply #1 on: May 04, 2004, 01:22:48 PM »
why don't we write one real quick? I'll get it started.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Print Layers (or export to Word / Excel)
« Reply #2 on: May 04, 2004, 01:25:22 PM »
that was quick Mark!!

creates a .csv file on the root of C named the same as the dwg.
example: Drawing1.csv

Code: [Select]

(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:/"(getvar 'dwgname)".csv") "w"); suitable for Excel
            )
      (foreach l lylst
        (write-line (strcat (car l) "," (cadr l) "," (last l)) fo)
        )
      (close fo)
      )
    )

  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)

M-dub

  • Guest
Print Layers (or export to Word / Excel)
« Reply #3 on: May 04, 2004, 01:34:02 PM »
I am not worthy of your talents, Mark!

When are you gonna put that paypal thing up again?  ;)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Print Layers (or export to Word / Excel)
« Reply #4 on: May 04, 2004, 01:45:53 PM »
glad you like it :D
TheSwamp.org  (serving the CAD community since 2003)

Dent Cermak

  • Guest
Print Layers (or export to Word / Excel)
« Reply #5 on: May 04, 2004, 03:58:52 PM »
Go to your Sheet Manager tab, down to "Sheet Tools", then down to "Create Layer Report". Gives you a nice file that you can edit in WORD, and probably Excel.

M-dub

  • Guest
Print Layers (or export to Word / Excel)
« Reply #6 on: May 04, 2004, 08:54:12 PM »


I'll have to try that one tomorrow Dent.  Hopefully it works!
Thanks a lot!
Mike

Dent Cermak

  • Guest
Print Layers (or export to Word / Excel)
« Reply #7 on: May 05, 2004, 01:41:22 PM »
Well, did it work ?

M-dub

  • Guest
Print Layers (or export to Word / Excel)
« Reply #8 on: May 05, 2004, 02:09:37 PM »
Call me an idiot, but I can't find 'Sheet Manager' so, No, I guess it didn't work.  :(

I just have Acad 2000...pretty plain jane.

Dent Cermak

  • Guest
Print Layers (or export to Word / Excel)
« Reply #9 on: May 05, 2004, 03:00:44 PM »
Dang!! Send me the drawing and I will send you a text file. A blank drawing with all of your layers loaded will do the trick.

M-dub

  • Guest
Print Layers (or export to Word / Excel)
« Reply #10 on: May 05, 2004, 03:16:59 PM »
Acutally Dent, I completely appreciate the offer, but the routine Mark provided me with worked like a charm.
Thanks a lot!

One Shot

  • Guest
Print Layers (or export to Word / Excel)
« Reply #11 on: April 19, 2005, 08:15:40 PM »
Quote from: Mark Thomas
that was quick Mark!!

creates a .csv file on the root of C named the same as the dwg.
example: Drawing1.csv

Code: [Select]

(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:/"(getvar 'dwgname)".csv") "w"); suitable for Excel
            )
      (foreach l lylst
        (write-line (strcat (car l) "," (cadr l) "," (last l)) fo)
        )
      (close fo)
      )
    )

  (princ)
  )

Mark,

This cool, but where do the file go after your run the lisp?

One Shot

  • Guest
Print Layers (or export to Word / Excel)
« Reply #12 on: April 19, 2005, 08:34:55 PM »
I found it.  Is there a way that the file can be sent to a folder that you want?

thank you,

Brad

nivuahc

  • Guest
Print Layers (or export to Word / Excel)
« Reply #13 on: April 19, 2005, 09:08:47 PM »
Change this line
Code: [Select]
fo (open (strcat "c:/"(getvar 'dwgname)".csv") "w"); suitable for Excel

to the directory of your choosing (using forward slashes, of course). Like this:

Code: [Select]
fo (open (strcat "c:/this/is/my/favorite/folder/"(getvar 'dwgname)".csv") "w"); suitable for Excel

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Print Layers (or export to Word / Excel)
« Reply #14 on: April 20, 2005, 09:16:42 AM »
Quote from: Dent Cermak
Go to your Sheet Manager tab, down to "Sheet Tools", then down to "Create Layer Report". Gives you a nice file that you can edit in WORD, and probably Excel.

I have 2005, i opened Sheet Set Manager, but I cant find what you are referring to.
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)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Print Layers (or export to Word / Excel)
« Reply #15 on: April 20, 2005, 09:48:10 AM »
Hi David,
I think Dent needs to update the 'version used note' his profile
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pmvliet

  • Guest
Print Layers (or export to Word / Excel)
« Reply #16 on: April 20, 2005, 11:44:54 AM »
Mark...
I would like to build upon this to have all the layer properties extracted to excel. I think it would be a great way to set-up layer scheme's, whats on, what's off, what color's, weights etc.

you have the list with vlax-

so where can I read more about this so I can understand what the missing items would be?

thanks,
Pieter

One Shot

  • Guest
Print Layers (or export to Word / Excel)
« Reply #17 on: April 20, 2005, 11:48:47 AM »
Thank you for all you help!

PitchBlack98

  • Guest
Re: Print Layers (or export to Word / Excel)
« Reply #18 on: November 18, 2005, 06:17:36 PM »
I hate to bring this back from the dead, but I have 2005 and this is not working for me. I can see all my layers layed out in the AutoCAD Text Window, but Im getting an error... Error: bad argument type: streamp nil... Can someone tell me how to fix this so it works or what Im doing wrong. Appreciate it!

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Print Layers (or export to Word / Excel)
« Reply #19 on: November 20, 2005, 10:15:04 PM »
there is one of mine...

Code: [Select]
;| ;;
LoFi Layer Output For Info ;;
;;
By: Andrea Andreetti |;

(defun c:LoFi ()
(setq lst2 nil)
      iselected (ssget) 
      sscount (sslength iselected)
      val1 (- sscount 1)
)
(repeat sscount
(setq a1 (entget (ssname iselected val1)))
(getinfo)   
(setq lst1 (list (strcat layer "," itemcolor "," layercolor "," layerlock"," layerplot )))
(if (not (vl-position (car lst1) lst2))
(setq lst2 (append lst2 lst1))
)   
(setq val1 (- val1 1))
);;end repeat
(printresult)
);;defun


;| ;;
GET INFO ;;
|;
(defun getinfo () 
(setq layer (cdr (assoc 8 a1));;layer
      color (cdr (assoc 62 a1));;color
)

(if (not color)(setq itemcolor "ByLayer")(setq itemcolor (rtos color)))
(setq layercolor (rtos (cdr (assoc 62 (entget (tblobjname "layer" (cdr (assoc 8 (entget (cdar a1))))))))))
 
;;locked or not
(if (= 4 (logand 4 (cdr (assoc 70
                           (tblsearch "layer" (cdr (assoc 8 (entget (cdar a1)))))
))))
(setq layerlock "Yes")
(setq layerlock "No") 
)

;;printable or not
(setq layerplot (rtos
      (cdr (assoc 290 (entget (tblobjname "layer" (cdr (assoc 8 (entget (cdar a1))))))))
       2)
)
(if (= layerplot "0") (setq layerplot "No")(setq layerplot "Yes"))

);;defun


;| ;;
PRINT RESULT ;;
|;
(defun printresult ()

(initget "Yes No")
(setq yon (getkword "Print in a File ?"))
(if (= (strcase yon) "YES")
(printfile)
(textprint)
)
)

;;;;;;;;;;;;;;;;;;;
(defun Printfile ()
(setq filew (open "c:\\LoSi_result.txt" "w"))
 
(princ
"
                   LAYER of SELECTED ITEM
                   ______________________

")
                   
(princ (strcat "\n\nFile:    " (getvar "dwgname")) filew)
(princ (strcat "\n\nDate:    " (menucmd "M=$(edtime,$(getvar,date),YYYY MON D H:MMam/pm)")) filew)
(princ "


__________________________________________________ 
Layer          Color            LOCK         PRINT
Nname        Item/Layer:        Mode         mode \n\n" filew)


(foreach n lst2
(getlst1)
(princ (strcat "\n" item1 spr1 item2 "/" item3 spr3 item4 spr4 item5 ) filew)


(close filew)
(startapp  "notepad" "c:\\LoSi_result.txt")
(resetvar)
)


;;;;;;;;;;;;;;;;;;;
(defun textprint () 
 
(princ
"
                   LAYER of SELECTED ITEM
                   ______________________

")
                   
(princ (strcat "\n\nFile:    " (getvar "dwgname")))
(princ (strcat "\n\nDate:    " (menucmd "M=$(edtime,$(getvar,date),YYYY MON D H:MMam/pm)")))
(princ "


__________________________________________________ 
Layer          Color            LOCK         PRINT
Nname        Item/Layer:        Mode         mode \n\n" )


 
 (foreach n lst2
   (getlst1)

(princ (strcat "\n" item1 spr1 item2 "/" item3 spr3 item4 spr4 item5 ))

(textscr)

)
(resetvar))

;;;;;;;;;;;;;;;;;;
(defun getlst1 ()

   (setq fLiL (car lst2))

    (setq #s1 (vl-string-position (ascii ",") fLiL))
    (setq item1 (substr fLiL 1 #s1))
    (setq fLiL (substr fLiL (+ #s1 2)))
    (setq spr# (- 20 #s1))
    (setq spr1 (substr space (- 20 spr#)))
     
    (setq #s2 (vl-string-position (ascii ",") fLiL))
    (setq item2 (substr fLiL 1 #s2))
    (setq fLiL (substr fLiL (+ #s2 2)))
    (setq spr# (- 15 #s2))
    (setq spr2 (substr space (- 15 spr#)))
   
    (setq #s3 (vl-string-position (ascii ",") fLiL))
    (setq item3 (substr fLiL 1 #s3))
    (setq fLiL (substr fLiL (+ #s3 2)))
    (setq spr# (- 15 #s3))
    (setq spr3 (substr space (- 15 spr#)))   

    (setq #s4 (vl-string-position (ascii ",") fLiL))
    (setq item4 (substr fLiL 1 #s4))
    (setq fLiL (substr fLiL (+ #s4 2)))
    (setq spr# (- 18 #s4))
    (setq spr4 (substr space (- 18 spr#)))
   
    (setq #s5 (vl-string-position (ascii "¯") fLiL))
    (setq item5 (substr fLiL 1 #s5))
    (setq lst2 (cdr lst2))
 );;defun



;;;;;;;;;;;;;;;;;;
(defun resetvar ()
(setq VarLst '(#s1 #s2 #s3 #s4 #s5 lst1 lst2 item1 item2 item3 item4 item5 itemcolor
       flil filew yon layerlock layerplot layer color sscount
       iselected a1 val1))
(mapcar '(lambda (l) (set l nil)) VarLst)
  (princ)
)
 

Maybe not good looking.....but it work. :kewl:
Keep smile...

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Print Layers (or export to Word / Excel)
« Reply #20 on: November 21, 2005, 01:23:51 PM »
Mark...
I would like to build upon this to have all the layer properties extracted to excel. I think it would be a great way to set-up layer scheme's, whats on, what's off, what color's, weights etc.

you have the list with vlax-

so where can I read more about this so I can understand what the missing items would be?

thanks,
Pieter
Code: [Select]
(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)
        )
      )
    )

  (defun TrueFalse2Str (sym)
    (if (= sym :vlax-true)
      "True" "False")
    )

  (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)
                      (strcat "ON="(TrueFalse2Str (vlax-get-property lay 'LayerOn)))
                      (strcat "FROZEN="(TrueFalse2Str (vlax-get-property lay 'Freeze)))
                      (strcat "LOCKED="(TrueFalse2Str (vlax-get-property lay 'Lock)))
                      )
                    lylst
                    )
                  )
            )

;; ("XREFS" "7" "Continuous" "ON=True" "FROZEN=True" "LOCKED=False")

  (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 (nth 0 l) "," ; name
                         (nth 1 l) "," ; color
                         (nth 2 l) "," ; linetype
                         (nth 3 l) "," ; On/Off
                         (nth 4 l) "," ; Frozen
                         (nth 5 l)     ; Locked
                         )
                 fo)
               )
      (close fo)
      )
    )

  (princ)
  )
TheSwamp.org  (serving the CAD community since 2003)