dnll Posted November 1, 2018 Posted November 1, 2018 (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 November 1, 2018 by dnll Quote
Lee Mac Posted November 1, 2018 Posted November 1, 2018 For the batch process aspect of your request, have you considered using my Layer Extractor application? 1 Quote
dlanorh Posted November 1, 2018 Posted November 1, 2018 (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 November 1, 2018 by dlanorh amended code Quote
Tharwat Posted November 1, 2018 Posted November 1, 2018 Hi @dlanorh Have a look at the following: (vl-string-right-trim ".dwg" "my drawing.dwg") And this: (vl-filename-base (getvar 'dwgname)) 1 Quote
dlanorh Posted November 1, 2018 Posted November 1, 2018 (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. 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 November 1, 2018 by dlanorh Quote
Tharwat Posted November 1, 2018 Posted November 1, 2018 1 minute ago, dlanorh said: I know, they are the same. Are you sure? Quote
dlanorh Posted November 1, 2018 Posted November 1, 2018 Just now, Tharwat said: Are you sure? See amended post above. I spotted it just after i posted Quote
ronjonp Posted November 1, 2018 Posted November 1, 2018 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) ) Quote
Grrr Posted November 1, 2018 Posted November 1, 2018 35 minutes ago, ronjonp said: This stuck out to me: It could be even - (cond ( (setq l_lst (vl-sort l_lst '<)) ... ) ); cond 1 Quote
dnll Posted November 2, 2018 Author Posted November 2, 2018 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! Quote
dlanorh Posted November 2, 2018 Posted November 2, 2018 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 Quote
dnll Posted April 9, 2019 Author Posted April 9, 2019 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" Quote
sakthi Posted June 15, 2019 Posted June 15, 2019 Anybody help me ….I want a lisp that with drop down menu to change the selected object layer. Quote
Lee Mac Posted June 15, 2019 Posted June 15, 2019 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. 1 Quote
Lee Mac Posted June 17, 2019 Posted June 17, 2019 11 hours ago, BIGAL said: Like this ? Exactly 1 Quote
sakthi Posted June 18, 2019 Posted June 18, 2019 Thanks for your response but not like this... I want to drop down menu like this Quote
BIGAL Posted June 19, 2019 Posted June 19, 2019 (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 June 19, 2019 by BIGAL 1 Quote
Roy_043 Posted June 19, 2019 Posted June 19, 2019 Maybe @sakthi should explain what he/she means by 'like this'. Maybe adding the control to a floating toolbar is the solution? Quote
Recommended Posts
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.