Jump to content

Recommended Posts

Posted

Do you know any routine to list all layer's names in a text file or Excel sheet?

Please help. Tkx.

Posted

Phiphi:

 

It is generally not a good idea to append a new question to an existing thread even if the subject seems to be similar. In the future, start a new thread. Thanks.

 

But don't be too disappointed. I found exactly what you need at the link below. When you get to the web page, scroll down to the section called Layer Management and look for a routine called laylst.lsp. This lisp routine will, according to its author, "generate a sorted list of layer names in a drawing".

 

http://paracadd.com/lisp.htm

 

By the way, the tip jar is on the counter. ;)

Posted
Do you know any routine to list all layer's names in a text file or Excel sheet?

Please help. Tkx.

 

Open the Layer Manager>Select all (Ctrl+A)>Copy (Ctrl+C)>Open Excel or Notepad and paste the contents.

Posted
Do you know any routine to list all layer's names in a text file or Excel sheet?

Please help. Tkx.

 

I've used this routine in the past. Don't know who wrote it or where I got it. I've had it for ages.

 

;;Change this line

;;fo (open (strcat "c:/"(getvar 'dwgname)".csv") "w"); suitable for Excel

;;

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

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

;;----------------------------------------------------------------------------------------

 

(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) (

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)

)

 

Edit: This request has been moved to it's own thread and placed in the Customization section.

Posted

I wrote this a while back, will process all drawings in a directory (and subdirectories):

 

(defun c:CheckLayers ( / *error* DBX DOCLST FILES FLAG LAYER_LIST ODOC OFILE OUTFILE SHELL )
 (vl-load-com)
 ;; Lee Mac  ~  15.01.10

 (defun *error* (msg)
   (ObjRelease (list Shell dbx))
   (and ofile (= (type ofile) 'FILE) (close ofile))
   
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
 )

 (setq *acad (cond (*acad) ((vlax-get-acad-object)))
       *doc  (cond (*doc ) ((vla-get-ActiveDocument *acad))))

 (if (and (setq Files   (GetAllFiles nil t "*.dwg"))
          (setq outfile (getfiled "Output File" "" "txt" 1)))
   (progn
     
     (vlax-for doc (vla-get-Documents *acad)
       (setq DocLst
         (cons
           (cons (strcase (vla-get-FullName doc)) doc) DocLst
         )
       )
     )      

     (setq dbx (ObjectDBXDocument))
     
     (foreach dwg Files

       (cond
         (  (setq flag
              (and
                (setq oDoc
                  (cdr (assoc (strcase dwg) DocLst))
                )
              )
            )
          )
         (t
           (setq flag
             (not
               (vl-catch-all-error-p
                 (vl-catch-all-apply
                   (function vla-open) (list dbx dwg)
                 )
               )
             )
           )
           (setq oDoc dbx)
         )
       )

       (setq Layer_List
         (if flag
           (cons (cons dwg (GetLayerProperties oDoc)) Layer_List)
           (cons (cons dwg '(("**Error Opening this Drawing **"))) Layer_List)
         )
       )
     )

     (princ (strcat "\n<< " (itoa (length Files)) " Drawings Processed >>"))
   )    
   (princ "*Cancel*")
 )

 (vlax-release-object dbx) (gc) (gc)

 (if (and Layer_List (setq ofile (open outfile "w")))
   (progn      
     (mapcar
       (function
         (lambda (x)
           (write-line (car x) ofile)
           (write-line (MakeString '("Name" "Colour" "LineType" "LineWeight") (chr 32)) ofile)
           (mapcar
             (function
               (lambda (y)
                 (write-line
                   (MakeString y (chr 32)) ofile
                 )
               )
             )
             (cdr x)
           )            
           (write-line "\n" ofile)
         )
       )
       Layer_List
     )
     (close ofile)
   )
   (princ "\n*Cancel*")
 )
 (princ)
)

(defun ObjectDBXDocument ( / acVer )

 (setq *acad (cond (*acad) ((vlax-get-acad-object))))
 
 (vla-GetInterfaceObject *acad
   (if (< (setq acVer (atoi (getvar "ACADVER"))) 16) "ObjectDBX.AxDbDocument"
     (strcat "ObjectDBX.AxDbDocument." (itoa acVer))
   )
 )
)

(defun GetAllFiles ( Dir Subs Filetype / GetSubFolders Shell Fold Dir )
 (vl-load-com)
 ;; Lee Mac  ~  17.01.10
 
 (defun GetSubFolders ( folder / _f )
   (mapcar
     (function
       (lambda ( f ) (setq _f (strcat folder "\\" f))
         (cons _f (apply (function append)
                         (GetSubFolders _f)))
       )
     )
     (cddr (vl-directory-files folder nil -1))
   )
 )

 (cond
   ( (not
       (or
         (and Dir (vl-file-directory-p Dir))
         (progn
           (setq Shell (vla-getInterfaceObject
                         (setq acad (vlax-get-acad-object)) "Shell.Application")
                 Fold  (vlax-invoke-method Shell 'BrowseForFolder
                         (vla-get-HWND acad) "Select Directory" 512))
           (vlax-release-object Shell)
           
           (if Fold
             (progn
               (setq Dir (vlax-get-property
                           (vlax-get-property Fold 'Self) 'Path))
               (vlax-release-object Fold)
               
               (and (= "\\" (substr Dir (strlen Dir)))
                    (setq Dir (substr Dir 1 (1- (strlen Dir)))))
               
               Dir
             )
           )
         )
       )
     )
   )
   ( (apply (function append)
       (vl-remove (quote nil)
         (mapcar
           (function
             (lambda (Filepath)
               (mapcar
                 (function
                   (lambda (Filename)
                     (strcat Filepath "\\" Filename)
                   )
                 )
                 (vl-directory-files Filepath Filetype 1)
               )
             )
           )
           (append (list Dir)
             (apply (function append)
               (if subs (GetSubFolders Dir))
             )
           )
         )
       )
     )
   )
 )
)

(defun GetLayerProperties ( doc / lst )
 (vlax-for lay (vla-get-Layers doc)
   (setq lst
     (cons
       (mapcar
         (function
           (lambda ( property )
             (vl-princ-to-string
               (vlax-get-property lay property)
             )
           )
         )
         '(Name Color Linetype LineWeight)
       )
       lst
     )
   )
 )  
 (vl-sort lst
   (function
     (lambda (a b) (< (car a) (car b)))
   )
 )
)

(defun MakeString  ( lst del / Pad str x i )
 (setq i 10)
 
 (defun Pad ( Str Del Len )
   (while (>= (strlen Str) Len) (setq Len (+ Len 5)))
   (while (< (strlen Str) Len)
     (setq Str (strcat Str Del))
   )
   Str
 )
 
 (apply (function strcat)
   (reverse
     (cons (last lst)
       (mapcar
         (function
           (lambda ( $str )
             (Pad $str del (setq i (abs (- 40 i))))
           )
         )          
         (cdr (reverse lst))
       )
     )
   )
 )
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...