Lee Mac Posted October 27, 2008 Posted October 27, 2008 Hi All, I am currently working on a LISP used to change the layer of certain entities in a drawing. The LISP searches each layer in turn for TEXT entities, displays the results to the user, who then decides whether to proceed or move onto the next layer. My question is related to an improvement for this LISP - is there any way to retrieve a list of all the Layers contained in a drawing? We work to a template, and it is the layers in this template that I am currently using in my LISP - however, sometimes drawings will use other layers created by users editing the drawing. I obviously don't want to have to edit my LISP for every drawing opened, and so any help would be greatly appreciated as always. Here is the LISP that I am working on - if anyone finds it of any use, feel free to use it and modify it to suit your needs. ; Txtlay, created by Lee McDonnell October 2008 (defun c:txtlay (/ laylist ss ans) (setvar "cmdecho" 0) (setq laylist '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "BORDER" "Defpoints" "DIM" "SIGNATURE") ) ; end setq ; for each Layer in laylist (foreach n laylist (if (setq ss (ssget "X" (list (cons 0 "TEXT") (cons 410 (getvar "ctab")) (cons 8 n) ) ; end list ) ; end ssget ) ; end setq (progn (sssetfirst nil ss) (initget "Yes No") (setq ans (getkword "Change Selected Entities to Text Layer? [Yes/No] <Yes> :" )) (if (/= ans "No") (progn (command "_.chprop" ss "" "LA" "TEXT" "C" "bylayer" "" ) ; end property change ) ; end progn ) ; end if ) ; end progn ) ; end if ) ; end foreach (setvar "cmdecho" 1) (prompt "\nFunction Complete.") (princ) ) ; end program Quote
wizman Posted October 28, 2008 Posted October 28, 2008 hi lee mac, here's for looping layers: (setq layer (tblnext "LAYER" T)) (while layer (princ (strcat "\nLayer name: " (cdr (assoc 2 layer)))) (setq layer (tblnext "LAYER")) ) Quote
ASMI Posted October 28, 2008 Posted October 28, 2008 Hi Lee Mac. This is ActiveX example (do not foget (vl-load-com) once per AutoCAD session): (defun GetLayerList(/ oLst) (vlax-for l (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (setq oLst(cons(vla-get-Name l)oLst)) ); end vlax-for (reverse oLst) ); end of GetLayerList Quote
Lee Mac Posted October 29, 2008 Author Posted October 29, 2008 Thanks guys, The Active X method works well ASMI - I really need to learn Active X methods - they seem to be able to do a lot more than the standard LISP functions. I am working from an AutoLISP reference from R.11, and so this manual doesn't have Active X functions included - I will have to do a bit of research and learn about them. 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.