Jump to content

Layerlist


dnll

Recommended Posts

Hello!
I found this awesome lisp at JTBworld website and it works great. I do however need some help with tweakinging it to suit my needs.

 

The lisp is as follows:

 

;;; Layer list
;;;
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2006 JTB World, All Rights Reserved
;;; Website: www.jtbworld.com
;;; E-mail: info@jtbworld.com
;;; 2000-03-15
;;;
;;; c:llfp <LayerListFilePrint>
;;; Save the layer list to a file, (can be imported to Excel)
;;;
;;; Example: (ax:layer-list)
;;; Return values: list of layers and all layerstates
;;;    (<Layer Name> <On/Off> <Frozen/Thawed> <Locked/Not locked> <Color> <Linetype>
;;;        <Lineweight> <Plotstylename> <Plottable/Not plottable> <Viewportdefault=Frozen/Not frozen>)
(vl-load-com)
(defun ax:layer-list (/ lst layer colors color lw)
  (setq colors '("Red" "Yellow" "Green" "Cyan" "Blue" "Magenta" "White"))
  (vlax-for layer (vla-get-Layers
                    (vla-get-ActiveDocument
                      (vlax-get-acad-object)
                    )
                  )
    (setq color (vla-get-color layer))
    (if (< color 8) (setq color (nth (1- color) colors)) (setq color (itoa color)))
    (setq lw (vla-get-lineweight layer))
    (if (= lw -3) (setq lw "Default") (setq lw (rtos (/ lw 100.0) 2 2)))
    (setq lst (cons
                (list
                  (vla-get-name layer)
                  (if (= (vla-get-layeron layer) :vlax-true) "On" "Off")
                  (if (= (vla-get-freeze layer) :vlax-true) "Frozen" "Thawed")
                  (if (= (vla-get-lock layer) :vlax-true) "Locked" "Not locked")
                  color
                  (vla-get-linetype layer)
                  lw
                  (vla-get-plotstylename layer)
                  (if (= (vla-get-plottable layer) :vlax-true) "Plottable" "Not plottable")
                  (if (= (vla-get-viewportdefault layer) :vlax-true) "Frozen" "Not frozen")
                ) lst))
  )
  (vl-sort lst
           (function (lambda (e1 e2)
                       (< (strcase (car e1)) (strcase (car e2)))
                     )
           )
  ) 
)

;;; Writes layer list to specified file
;;; (layer-list-fprint "test.txt")
;;; return: T if file was created, else nil
(defun layer-list-fprint (fn / f row col)
  (if (setq f (open fn "w"))
    (progn
      ; print header
      (princ "\"Layer Name\" \"On\" \"Frozen\" \"Locked\" " f)
      (princ "\"Color\" \"Linetype\" \"Lineweight\" \"Plotstylename\" " f)
      (princ "\"Plottable\" \"Viewportdefault\"\n" f)
      (foreach row (ax:layer-list)
        (foreach col row
          (prin1 col f)
          (princ " " f) ; for tabulated (princ "\t" f)
        )
        (princ "\n" f)
      )
      (close f)
      T
    )
    nil
  )
)

(defun c:llfp (/ fn)
  (if (setq fn
             (getfiled "Save layer list as"
                       (strcat (vl-filename-base (getvar "dwgname")) ".txt")
                       "txt"
                       1
             )
      )
    (if (layer-list-fprint fn)
      (princ "\nLayer list created.")
      (princ "\nError: Layer list not created!")
    )
  )
  (princ)
)

What I would like to be changed is for it to only export the layernames of layers that are frozen. Also if possible to set it to remove the save as function and always save it as "dwgname" at C:\Layerlist\dwgname.txt.

 

* Edit: Also wondering whether this can be converted or executed as a script?

 

Thanks in advance!

Edited by dnll
Link to comment
Share on other sites

Try this. The directory "C:/Layerlist/" must exist before running. It does what you want without having to butcher someone elses code.

(vl-load-com)

(defun c:fll ( / c_doc c_lyrs f_name l_lst fp)
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_lyrs (vla-get-layers c_doc)
        f_name (strcat "c:/Layerlist/" (vl-filename-base (getvar 'dwgname)) ".txt")
  );end_setq
  
  (vlax-for lyr c_lyrs
    (if (= :vlax-true (vlax-get-property lyr 'freeze))
      (setq l_lst (cons (vlax-get-property lyr 'name) l_lst))
    );end_if
  );end_for
  
  (cond ( (> (length l_lst) 0)
          (setq l_lst (vl-sort l_lst '<))
          (if (setq fp (open f_name "w"))
            (progn
              (princ "Frozen Layers :\n" fp)
              (princ "\n" fp)
              (foreach item l_lst
                (princ (strcat (strcase item) "\n") fp)
              );end_foreach
              (princ "\n" fp)
              (close fp)
            );end_progn
          );end_if
        )
  );end_cond        
);end_defun

 

Edited by dlanorh
amended code
Link to comment
Share on other sites

11 minutes ago, Tharwat said:

Hi @dlanorh

Have a look at the following:


(vl-string-right-trim ".dwg" "my drawing.dwg")

And this:


(vl-filename-base (getvar 'dwgname))

 

 

I know, they are the same. :P

 

It's old code and I was only paying attention to this bit

(vlax-get-property lyr 'freeze)

which was previously

 

(vlax-get-property lyr 'lock)

Ohh! wait, I see what you mean. "drawin"

Edited by dlanorh
Link to comment
Share on other sites

11 hours ago, Lee Mac said:

For the batch process aspect of your request, have you considered using my Layer Extractor application?

 

I'm very well aware of your work Lee Mac and I thank you for your input. I had previously been browsing through your website in search for answers to this conondrum but obviously not well enough. 

 

10 hours ago, dlanorh said:

Try this. The directory "C:/Layerlist/" must exist before running. It does what you want without having to butcher someone elses code.


(vl-load-com)

(defun c:fll ( / c_doc c_lyrs f_name l_lst fp)
  (setq c_doc (vla-get-activedocument (vlax-get-acad-object))
        c_lyrs (vla-get-layers c_doc)
        f_name (strcat "c:/Layerlist/" (vl-filename-base (getvar 'dwgname)) ".txt")
  );end_setq
  
  (vlax-for lyr c_lyrs
    (if (= :vlax-true (vlax-get-property lyr 'freeze))
      (setq l_lst (cons (vlax-get-property lyr 'name) l_lst))
    );end_if
  );end_for
  
  (cond ( (> (length l_lst) 0)
          (setq l_lst (vl-sort l_lst '<))
          (if (setq fp (open f_name "w"))
            (progn
              (princ "Frozen Layers :\n" fp)
              (princ "\n" fp)
              (foreach item l_lst
                (princ (strcat (strcase item) "\n") fp)
              );end_foreach
              (princ "\n" fp)
              (close fp)
            );end_progn
          );end_if
        )
  );end_cond        
);end_defun

 

 

This worked absolutely beautifully! Thank you all for your help!

Link to comment
Share on other sites

Attached is an updated lisp. Please note that the lisp has been renamed from FLL  to FFL 

 

This checks that the supplied path is valid and if so creates it. If there are NO frozen layers; the file is still created, but it reports no frozen layers found.

FFL.lsp

Link to comment
Share on other sites

  • 5 months later...

Would it be possible to add quotationmarks around the layer name?

Say I have these layers frozen:
Layer1
Layer2
Layer3

The txt file would make a list of those 3.

Would it be possible to add "" to make it export:
"Layer1"

"Layer2"

"Layer3"

Link to comment
Share on other sites

  • 2 months later...
11 hours ago, sakthi said:

Anybody help me ….I want a lisp that with drop down menu to change the selected object layer.

 

No need for LISP, simply use the Layer Manager in AutoCAD.

  • Like 1
Link to comment
Share on other sites

You can use Lee's list box.lsp to make a list of the layers so you can pick the layer from a list. Some one has probably done this did you goggle.

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

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...