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

0 Members and 1 Guest are viewing this topic.

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)