russell84 Posted March 5, 2008 Posted March 5, 2008 (defun C:G-() (command "-layer" "OFF" "*" "YES" "ON" "G-*" "") (princ) );end of G- ;############################################################################################################## (defun C:G-ON() (command "-layer" "ON" "G-*" "") (princ) Hey we use layer codes starting with G- , R- ETC I wrote these easy two to isolate the layers starting with G- and to turn on the layers starting with G- But im having problems with writing the lisp for turning off the layers starting with G- - with allowing for the additional possibility that a G- layer is set to current any help? Cheers again:D Quote
ASMI Posted March 5, 2008 Posted March 5, 2008 (defun Pattern_On_Off(Pattern Mode / St) (vl-load-com) (vlax-for l(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if(wcmatch(vla-get-Name l)Pattern) (vla-put-LayerOn l (if Mode :vlax-true :vlax-false)) ); end if ); end vlax-for (princ) ); end Pattern_On_Off Arguments: Pattern - string with wildcard pattern (for more patterns look function WCMATCH help), Mode - T- turns layers ON, nil- turns OFF. For exampe: (Pattern_On_Off "G-*" nil) - turn of all layers starts with G- (Pattern_On_Off "G-*" T) turn on all layers starts with G- Quote
ChrisCMU Posted July 17, 2008 Posted July 17, 2008 Very cool. Do you have a version that prompts you for the pattern and uses that? Quote
ASMI Posted July 17, 2008 Posted July 17, 2008 > ChrisCMU I decide to add some lines: (defun c:lonff(/ cFlag Pat lLst Ans) (vl-load-com) (while(not cFlag) (setq Pat(getstring T "\nSpecify layer name pattern or [All/Help]: ")) (cond ((member Pat '("H" "h" "_H" "_h" "Help" "HELP" "help")) (princ "\n <<< PATTERNS AVAILABLE >>> \n") (princ "\n # - Matches any single numeric digit.") (princ "\n @ - Matches any single alphabetic character.") (princ "\n . - Matches any single nonalphanumeric character.") (princ "\n * - Matches any character sequence, including an ") (princ "\n empty one, and it can be used anywhere in the ") (princ "\n search pattern: at the beginning, middle, or end.") (princ "\n ? - Matches any single character \n") (princ "\n ~ - If it is the first character in the pattern,") (princ "\n it matches anything except the pattern.") (princ "\n [...] - Matches any one of the characters enclosed.") (princ "\n [~...] - Matches any single character not enclosed.") (princ "\n - - Used inside brackets to specify a range.") (princ "\n for a single character.") (princ "\n , - Separates two patterns.") (princ "\n ` - Escapes special characters (reads next") (princ "\n character literally).") (princ "\n\nPress F2 to close text scren...\n") (textscr) ); end condition #1 ((member Pat '("A" "a" "_A" "_a" "All" "ALL" "all")) (setq Pat "*" cFlag T) ); end condition #2 ((/= Pat "") (setq cFlag T) ); end condition #3 ((= "" Pat) (princ "\nEmpty input Quit. ") (setq Pat nil cFlag T) ); end condition #4 ); end cond ); end while (if Pat (progn (setq lLst '()) (vlax-for l(vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if(wcmatch(vla-get-Name l)Pat) (setq lLst(append lLst(list l))) ); end if ); end vlax-for (if lLst (progn (princ (strcat "\n" (itoa(length lLst)) " layers found ") ); end princ (setq Ans "List") (while(or(= Ans "List")(= Ans "Highlight")) (initget 1 "ON OFF List Highlight Quit") (setq Ans(getkword "\nSelect option [ON/OFF/List/Highlight/Quit] <Quit>: ")) (cond ((= "List" Ans) (princ "\nLAYERS LIST: ") (princ(strcat "\n"(vla-get-Name(car lLst)))) (foreach l(cdr lLst) (princ(strcat ", "(vla-get-Name l))) ); end foreach ); end condition #1 ((= "ON" Ans) (mapcar '(lambda(l)(vla-put-LayerON l :vlax-true))lLst) ); end condition #2 ((= "OFF" Ans) (mapcar '(lambda(l)(vla-put-LayerON l :vlax-false))lLst) ); end condition #3 ((= "Highlight" Ans) (sssetfirst nil(ssget "_X"(list(cons 8 pat)))) ); end condition #4 (T ); end condition #5 ); end cond ); end while ); end progn (princ "\nNothing found! ") ); end if ); end progn ); end if (princ) ); end of c:lonff Quote
russell84 Posted July 17, 2008 Author Posted July 17, 2008 Asmi - that works so great - i never said thanks - thanks heaps mate Works a charm. Quote
ASMI Posted July 18, 2008 Posted July 18, 2008 There is with additional options http://www.asmitools.com/Files/Lisps/Patlay.html . New program name PATLAY. Quote
alanjt Posted August 20, 2008 Posted August 20, 2008 There is with additional options http://www.asmitools.com/Files/Lisps/Patlay.html . New program name PATLAY. impeccable routine. i did notice one issue, it's case sensitive. if you type in "LAYER" and the name is "layer" is says it doesn't exist. i was going to make the change myself and post it, but my vla experience is limited to altering a vla list of layers as vla-objects. as far as suggestions go (if you don't mind), an isolate and an option to erase everything on a specified layer would be most useful, i know i couldn't live w/o my LX command that will either erase everything on the layer of a picked entity, or the typed in name. Quote
ASMI Posted August 20, 2008 Posted August 20, 2008 impeccable routine. i did notice one issue, it's case sensitive. if you type in "LAYER" and the name is "layer" is says it doesn't exist. i was going to make the change myself and post it, but my vla experience is limited to altering a vla list of layers as vla-objects. That because layer names is case sensitive. You can create for example three layers "Layer1", "lAYER1" and "layer1". All will works. Ok I will think about it. Maybe make option and store current value in Registry. It possible. as far as suggestions go (if you don't mind), an isolate and an option to erase everything on a specified layer would be most useful, i know i couldn't live w/o my LX command that will either erase everything on the layer of a picked entity, or the typed in name. Ok. I can to add Isolate option. But I think erase option isn't need because there is Highlight option. You can highlight layers and use _ERASE command. Thanks for your ideas, I appreciate your participation. I will try to make that be one of these days. Today my limit of time is exhausted, it is necessary to work. Quote
alanjt Posted August 21, 2008 Posted August 21, 2008 That because layer names is case sensitive. You can create for example three layers "Layer1", "lAYER1" and "layer1". All will works. Ok I will think about it. Maybe make option and store current value in Registry. It possible. are you sure about this? if i create a layer called "alan", then try and create a layer called "AlAn" or "aLAn" it will just overwrite the existing layer. i don't think it's case sensitive. also, if you type -layer off "storm* it will turn off all layers with storm in them, regardless of casing. I think erase option isn't need because there is Highlight option. You can highlight layers and use _ERASE command. good point, i completely forgot about the highlight option. on a side note, how can you manipulate a vla list of layer names? Quote
ASMI Posted August 21, 2008 Posted August 21, 2008 are you sure about this? if i create a layer called "alan", then try and create a layer called "AlAn" or "aLAn" it will just overwrite the existing layer. i don't think it's case sensitive.also, if you type -layer off "storm* it will turn off all layers with storm in them, regardless of casing. You are right. I at all do not know to that I so thought. Thanks for good idea. This non case sensetive version: ;; ============================================================ ;; ;; ;; ;; PATLAY.LSP - Allows to select group of layers with the help ;; ;; of wildcard pattern string and to do with them ;; ;; following actions: On/Off, Lock/Unlock, ;; ;; Freeze/Thaw, Highlight (select). ;; ;; ;; ;; ============================================================ ;; ;; ;; ;; Command(s) to call: PATLAY ;; ;; ;; ;; Specify wildcard string and do action with layers selected ;; ;; ;; ;; ============================================================ ;; ;; ;; ;; THIS PROGRAM AND PARTS OF IT MAY REPRODUCED BY ANY METHOD ;; ;; ON ANY MEDIUM FOR ANY REASON. YOU CAN USE OR MODIFY THIS ;; ;; PROGRAM OR PARTS OF IT ABSOLUTELY FREE. ;; ;; ;; ;; THIS PROGRAM PROVIDES THIS PROGRAM 'AS IS' WITH ALL FAULTS ;; ;; AND SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF ;; ;; MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. ;; ;; ;; ;; ============================================================ ;; ;; ;; ;; V1.1, 21st Aug 2008, Riga, Latvia ;; ;; © Aleksandr Smirnov (ASMI) ;; ;; For AutoCAD 2000 - 2009 (isn't tested in a next versions) ;; ;; ;; ;; http://www.asmitools.com ;; ;; ;; ;; ============================================================ ;; (defun c:patlay(/ oldPat cFlag lLst Ans actDoc aName) (vl-load-com) (if(not laypat:pat)(setq laypat:pat "")) (setq oldPat laypat:pat) (while(not cFlag) (setq laypat:pat(getstring T (strcat "\nLayer name pattern or [Help/Quit] <" laypat:pat ">: "))) (cond ((member laypat:pat '("H" "h" "_H" "_h" "Help" "HELP" "help")) (princ "\n <<< PATTERNS AVAILABLE >>> \n") (princ "\n # - Matches any single numeric digit.") (princ "\n @ - Matches any single alphabetic character.") (princ "\n . - Matches any single nonalphanumeric character.") (princ "\n * - Matches any character sequence, including an ") (princ "\n empty one, and it can be used anywhere in the ") (princ "\n search pattern at the beginning, middle, or end.") (princ "\n ? - Matches any single character \n") (princ "\n ~ - If it is the first character in the pattern,") (princ "\n it matches anything except the pattern.") (princ "\n [...] - Matches any one of the characters enclosed.") (princ "\n [~...] - Matches any single character not enclosed.") (princ "\n - - Used inside brackets to specify a range.") (princ "\n for a single character.") (princ "\n , - Separates two patterns.") (princ "\n ` - Escapes special characters (reads next") (princ "\n character literally).") (princ "\n\nPress F2 to close text scren...\n") (textscr) ); end condition #1 ((member laypat:pat '("Q" "q" "_Q" "_q" "Quit" "QUIT" "quit")) (setq cFlag T laypat:pat "") ); end condition #2 ((= laypat:pat "") (setq laypat:pat oldPat cFlag T) ); end condition #3 (t (setq cFlag T) ); end condition #4 ); end cond ); end while (if(/= laypat:pat "") (progn (setq lLst '() actDoc(vla-get-ActiveDocument (vlax-get-acad-object)) ); end setq (vlax-for l(vla-get-Layers actDoc) (if(wcmatch(strcase(vla-get-Name l))(strcase laypat:pat)) (setq lLst(append lLst(list l))) ); end if ); end vlax-for (if lLst (progn (princ(strcat "\n>>> Layers found ("(itoa(length lLst))"): ")) (princ(strcat (vla-get-Name(car lLst)))) (foreach l(cdr lLst) (princ(strcat ", "(vla-get-Name l))) ); end foreach (setq Ans "lIst") (while(or(= Ans "lIst")(= Ans "Highlight")) (initget "On ofF Lock Unlock fReeze Thaw Highlight Quit") (setq Ans (getkword "\nSelect option [On/ofF/Lock/Unlock/fReeze/Thaw/Highlight/Quit] <Quit>: ")) (cond ((= "On" Ans) (mapcar '(lambda(l)(vla-put-LayerON l :vlax-true))lLst) ); end condition #2 ((= "ofF" Ans) (mapcar '(lambda(l)(vla-put-LayerON l :vlax-false))lLst) ); end condition #3 ((= "Lock" Ans) (mapcar '(lambda(l)(vla-put-Lock l :vlax-true))lLst) ); end condition #4 ((= "Unlock" Ans) (mapcar '(lambda(l)(vla-put-Lock l :vlax-false))lLst) ); end condition #5 ((= "fReeze" Ans) (mapcar '(lambda(l)(if(not(member(vla-get-Name l) (list (vla-get-Name (vla-get-ActiveLayer actDoc)) "0"))) (vla-put-Freeze l :vlax-true))) lLst); end mapcar (if(member (setq aName(vla-get-Name(vla-get-Activelayer actDoc))) (mapcar 'vla-get-Name lLst)) (princ(strcat "\nCan't freeze active layer '" aName "'! ")) ); end if ); end condition #6 ((= "Thaw" Ans) (mapcar '(lambda(l)(if(not(member(vla-get-Name l) (list (vla-get-Name (vla-get-ActiveLayer actDoc)) "0"))) (vla-put-Freeze l :vlax-false))) lLst); end mapcar (setvar "CMDECHO" 0) (command "_.regenall") (setvar "CMDECHO" 1) ); end condition #6 ((= "Highlight" Ans) (sssetfirst nil(ssget "_X"(list(cons 8 laypat:pat)))) ); end condition #7 ((or(not Ans)(= "Quit" Ans)) (princ "\nQuit LAYPAT ") ); end condition #8 ); end cond ); end while ); end progn (princ "\nNo layers found! ") ); end if ); end progn (setq laypat:pat oldPat) ); end if (princ) ); end of c:patlay (princ "\n*** Type PATLAY for wildcard layer actions*** ") on a side note, how can you manipulate a vla list of layer names? For example (type in command line) get layers collection: Command: (setq lCol(vla-get-Layers(vla-get-ActiveDocument(vlax-get-acad-object)))) #<VLA-OBJECT IAcadLayers 0765a6bc> Turn OFF all layers: Command: (vlax-for l lCol(vla-put-LayerON l :vlax-false)) nil Turn ON all layers: Command: (vlax-for l lCol(vla-put-LayerON l :vlax-true)) nil Use VLAX-FOR or VLAX-MAP-COLLECION functions to loop all collection items and manipulate them. PATLAY creates list of layrs matched to pattern inside VLAX-FOR loop and apply function LAMBDA to change layer state. For example: (mapcar '(lambda(l)(vla-put-LayerON l :vlax-true))lLst) will turn ON all layers in 'Lst' list. Quote
CAB Posted August 21, 2008 Posted August 21, 2008 Nice work ASMI. Here is another play toy. ;; CAB 08.21.08 [ Limited Testing ] version 3 ;; User pick of layers to remain Thawed, freeze all others ;; Picked layers turn off as picked, when Enter is pressed ;; picked layers are thawed & turned on and all others are frozen ;; ;; modified to allow current layer to be frozen, makes the first ;; thawed layer current ;; ;; If a layer in an xref is selected the layer the xref is on can ;; not be frozen ;; ;; Layer 0 in an xref will not be frozen ;; ;; added uiso to restore the previous layer states ;; (defun c:liso (/ laylst thalst ent lname xrlays) (vl-load-com) ;; get current layer settings (defun getlayerdata (doc / lst) (vlax-for layObj (vla-get-layers doc) (setq lst (cons (list layObj (vla-get-freeze layObj) (vla-get-layeron layObj) ) lst))) lst ) (defun xrefp (ent / elist blist) (and (setq elist (entget ent)) (setq blist (entget (tblobjname "BLOCK" (cdr (assoc 2 elist))))) (= 4 (logand (cdr (assoc 70 blist)) 4)) ) ) (defun LayerOff (layname doc) ; added for version 3 (vla-put-LayerOn (vla-item (vla-get-layers doc) layname) :vlax-false) ) (command ".undo" "begin") (setq *laysts (getlayerdata (vla-get-activedocument (vlax-get-acad-object))) *clayer (getvar "clayer") ) (prompt "\nLayers picked will turn off during selection.") (while (setq ent (nentsel "\nPick layers to keep thawed. Enter when done")) (setq lname (cdr (assoc 8 (entget (car ent))))) (if (vl-position lname xrlays) (prompt "\nFlagged xref layer can not be frozen.") (if (and (= lname "0") (cadddr ent) (xrefp (last (nth 3 ent)))) (prompt "\nLayer 0 in xref can not be frozen.") (progn (setq thalst (cons lname thalst)) (LayerOff lname (vla-get-activedocument (vlax-get-acad-object))) (if (and (cadddr ent) (xrefp (car (nth 3 ent)))) (progn ; save the xref layer (setq xrlays (cons (cdr (assoc 8 (entget (last (nth 3 ent))))) xrlays) thalst (cons (car xrlays) thalst) ) ) ) ) ) ) ) (if thalst (progn (setq laylst (list (cdr (assoc 2 (tblnext "layer" t)))) clayer (getvar "clayer") ) (while (setq lay (cdr (assoc 2 (tblnext "layer")))) (if (and lay (not (member lay thalst)) (/= lay clayer) ) (setq laylst (cons lay laylst)) ) ) (if (vl-position *clayer laylst) (setvar "clayer" (car thalst)) ) (command "._Layer") (mapcar '(lambda (x) (command "_f" x)) laylst) (command "") (command "._Layer") (mapcar '(lambda (x) (command "_ON" x)) thalst) (command "") ) ) (command ".undo" "end") (princ) ) (prompt "\n*-* Layers Isolate loaded, Enter LayISO to run. *-*") (princ) ;; restore previous layer settings (defun c:uiso (/ doc) (setq doc (vla-get-activedocument (vlax-get-acad-object)) clayer (vla-get-activelayer doc) ) (if *laysts (progn (vlax-for layObj (vla-get-layers doc) (if (and (setq lyrdat (assoc layObj *laysts)) (not (equal clayer layObj)) ) (progn (vla-put-freeze layObj (cadr lyrdat)) (vla-put-layeron layObj (caddr lyrdat)) (if (= *clayer (vla-get-name layObj)) (vla-put-activelayer doc layObj) ) ) ) ) (setq lyrdat (assoc clayer *laysts)) (if (/= *clayer (vla-get-name (car lyrdat))) (vla-put-freeze (car lyrdat) (cadr lyrdat)) ) (vla-put-layeron (car lyrdat) (caddr lyrdat)) (vla-regen doc acactiveviewport) ) ) ) Quote
CAB Posted August 21, 2008 Posted August 21, 2008 Thanks, I just updated the routine for a BUG fix. So download it again. Quote
ASMI Posted August 22, 2008 Posted August 22, 2008 > alanjt There is non case sensitive version with Isolate and Previouos state restore options: http://www.asmitools.com/Files/Lisps/Patlay.html Quote
alanjt Posted August 22, 2008 Posted August 22, 2008 > alanjt There is non case sensitive version with Isolate and Previouos state restore options: http://www.asmitools.com/Files/Lisps/Patlay.html that is incredible! i hope you didn't see my comments as demands/requests; i was just making suggestions. however, i will most definitely be using this powerhouse of a routine. 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.