Jump to content

Recommended Posts

Posted (edited)

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

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
Posted

Hi @dlanorh

Have a look at the following:

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

And this:

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

 

  • Like 1
Posted (edited)
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
Posted
1 minute ago, dlanorh said:

 

I know, they are the same. :P

Are you sure? ;)

Posted
Just now, Tharwat said:

Are you sure? ;)

 

See amended post above. I spotted it just after i posted

Posted

This stuck out to me:

(setq l_lst '(1 2 3))
(cond ((> (length l_lst) 0)))
;; Could just check if the list exists
(if l_list
  (progn)
)

 

Posted
35 minutes ago, ronjonp said:

This stuck out to me:

 

It could be even -

(cond 
   ( (setq l_lst (vl-sort l_lst '<))
     ...
   )
); cond

 

  • Like 1
Posted
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!

Posted

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

  • 5 months later...
Posted

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"

  • 2 months later...
Posted

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

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

Thanks for your response but not like this...

I want to drop down menu like this👇 

 

image.png.94d7989f56afc2a607b1398075d6a63e.png

Posted (edited)

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
Posted

Maybe @sakthi should explain what he/she means by 'like this'. Maybe adding the control to a floating toolbar is the solution?

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