marmo Posted July 28, 2010 Share Posted July 28, 2010 Hi, I wonder if anyone knows a lisp to unlock all the layers. Thanks, Marco Quote Link to comment Share on other sites More sharing options...
ReMark Posted July 28, 2010 Share Posted July 28, 2010 Seek and ye shall find. Thus the reason for the Advanced Search box in the upper right-hand corner. http://www.cadtutor.net/forum/showthread.php?47611-Unlock-ALL-layers Quote Link to comment Share on other sites More sharing options...
Tharwat Posted July 28, 2010 Share Posted July 28, 2010 Hi There is no need for a lisp, it is already support with Autocad. command: layulk Regards Tharwat Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 28, 2010 Share Posted July 28, 2010 (edited) Why isnt there a need for unlocking layers via lisp? What if your program has to draw something and the layer is locked? Here is a quickly penned progy to just unlock all layers in the drawing (this is just a quick demonstration). ( (lambda (/ layer) ;; ;; (ex) Unlock all layers in drawing using Visual Lisp. ;; ;; By: Se7en ;; 07.28.10 08:11:00 AM ;; ;; Licence: ;; ;; Copyright (c)2010-2011 John Kaul ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in ;; the documentation and/or other materials provided with the ;; distribution. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ;; COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ;; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS ;; OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ;; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF ;; THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH ;; DAMAGE. ;; (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (if (vlax-get-property layer 'Lock) (vlax-put-property layer 'Lock :vlax-false)))) ) Edited July 28, 2010 by Se7en The forum's obtuse GPL licence rule. Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 28, 2010 Share Posted July 28, 2010 In code, use Se7en's way, just know you can also do this from the command line. eg. Command: LA -LAYER Current layer: "ALAN" Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: U Enter name list of layer(s) to unlock or <select objects>: * Enter an option [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/MATerial/Plot/Freeze/Thaw/LOck /Unlock/stAte/Description/rEconcile]: Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 28, 2010 Share Posted July 28, 2010 (edited) Here is another Visual Lisp method. ( (lambda ( / ) ;; ;; ;; (ex) Unlock all layers in drawing using Visual Lisp. ;; ;; By: Se7en ;; 07.28.10 08:30:00 AM ;; ;; Licence: ;; ;; Copyright (c)2010-2011 John Kaul ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in ;; the documentation and/or other materials provided with the ;; distribution. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ;; COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ;; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS ;; OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ;; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF ;; THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH ;; DAMAGE. ;; (vlax-map-collection (vla-get-layers (vla-Get-ActiveDocument (vlax-Get-Acad-Object))) '(lambda ( layer ) (if (vlax-get-property layer 'Lock) (vlax-put-property layer 'Lock :vlax-true))))) ) Here is something a bit cooler using only Auto Lisp. I created it using plenty of variables so you can follow the process better. ( (lambda ( layername / layer lsylst props off freeze lock ) ;; ;; (ex) Toggle layer's settings in drawing using Auto Lisp. ;; ;; By: Se7en ;; 07.28.10 08:30:00 AM ;; ;; NOTES: ;; 70 - Standard flags (bit-coded values): ;; 1 = Layer is frozen; otherwise layer is thawed ;; ... ;; 4 = Layer is locked ;; ... ;; 62 - Color number (if negative, layer is off) ;; ;; Or if your feeling adventrous you can combine frozen and locked ;; (1+4=5). something like... ;; ;; EXAMPLE: ;; (setq laylst (entget (tblobjname "LAYER" "<YOUR LAYER NAME HERE>"))) ;; (entmod ;; (subst ;; (cons 70 (boole 6 (cdr (assoc 70 laylst)) 5)) ;; (assoc 70 laylst) ;; laylst)) ;; ;; Licence: ;; ;; Copyright (c)2010-2011 John Kaul ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in ;; the documentation and/or other materials provided with the ;; distribution. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ;; COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, ;; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS ;; OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED ;; AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF ;; THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH ;; DAMAGE. ;; (setq layer (tblobjname "LAYER" layername)) (setq laylst (entget layer) props (cdr (assoc 70 laylst)) off (cdr (assoc 62 laylst)) freeze 1 lock 4 ) (setq props (boole 6 props freeze)) (setq off (1+ (~ off))) (setq props (boole 6 props lock)) (setq laylst (subst (cons 70 props) (assoc 70 laylst) laylst) laylst (subst (cons 62 off) (assoc 62 laylst) laylst)) (entmod laylst) ) "0" ;; just for example. make this a named procedure to use in your library. ) Edited July 28, 2010 by Se7en because someone didnt read the GPL and i dont want this code under the GPL Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 28, 2010 Share Posted July 28, 2010 Okay, i will stop now you get the idea. Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 28, 2010 Share Posted July 28, 2010 *GACK* I just remembered why i dont post code here?! ...that stupid GPL licence; I dont want my code under the GPL. I will fix/add my header to the code i posted above. Quote Link to comment Share on other sites More sharing options...
gile Posted July 28, 2010 Share Posted July 28, 2010 (edited) Hi, Here's a method using defun-q to store the unlocked layers list within the function so that they can be relocked by calling the same function. Using (gc:LayerUnLockAll T) unlock all locked layers and store them in a list within the function (gc:LayerUnLockAll nil) relock previously unlocked layers stored in the function. ;;; gc:LayerUnLockAll (gile) ;;; Unlock all layers or relock prevously locked layers ;;; ;;; Argument : T or nil ;;; ;;; Using : ;;; (gc:LayerUnLockAll T) unlock all locked layers ;;; (gc:LayerUnLockAll nil) relock previously unlocked layers (vl-load-com) (defun-q gc:layerunlockall (flag / lst lay) (setq lst nil) (if flag (vlax-for l (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (and (= (vla-get-Lock l) :vlax-true) (setq lst (cons l lst)) (vla-put-Lock l :vlax-false) ) ) (progn (foreach n lst (vl-catch-all-apply 'vla-put-Lock (list n :vlax-true)) ) (setq lst nil) ) ) (setq gc:layerunlockall (cons (car gc:layerunlockall) (cons (list 'setq 'lst (list 'quote lst)) (cddr gc:layerunlockall) ) ) ) lst ) Edited July 28, 2010 by gile corrected a bad translation (see Lee's reply above) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 28, 2010 Share Posted July 28, 2010 Gile, Shouldn't this: (setq layerunlockall (cons (car layerunlockall) (cons (list 'setq 'lst (list 'quote lst)) (cddr layerunlockall) ) ) ) be: (setq [color=Red][b]gc:[/b][/color]layerunlockall (cons (car [color=Red][b]gc:[/b][/color]layerunlockall) (cons (list 'setq 'lst (list 'quote lst)) (cddr [b][color=Red]gc:[/color][/b]layerunlockall) ) ) ) Quote Link to comment Share on other sites More sharing options...
gile Posted July 28, 2010 Share Posted July 28, 2010 Oops !... You're right Lee. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 28, 2010 Share Posted July 28, 2010 Oops !...You're right Lee. No worries mate - nice code by the way Quote Link to comment Share on other sites More sharing options...
marmo Posted July 29, 2010 Author Share Posted July 29, 2010 Thanks so much Gile and Lee! It 's what I want. Thanks again!:thumbsup: Quote Link to comment Share on other sites More sharing options...
Se7en Posted July 29, 2010 Share Posted July 29, 2010 Thanks so much Gile and Lee!It 's what I want. Thanks again!:thumbsup: *blink-blink* *facepalm* rofl! Quote Link to comment Share on other sites More sharing options...
gile Posted July 29, 2010 Share Posted July 29, 2010 *blink-blink* *facepalm* rofl! What's to say ???... Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 29, 2010 Share Posted July 29, 2010 *blink-blink* *facepalm* rofl! I kinda know how you feel - I saw you put a lot of effort into your explanation for it to seemingly be dismissed without comment. Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 29, 2010 Share Posted July 29, 2010 I kinda know how you feel - I saw you put a lot of effort into your explanation for it to seemingly be dismissed without comment. Many can relate. Quote Link to comment Share on other sites More sharing options...
marmo Posted July 29, 2010 Author Share Posted July 29, 2010 Hello, I read the post quickly:P, I took the code that works and I thank those who posted:D. Greetings all, Marco Quote Link to comment Share on other sites More sharing options...
alanjt Posted July 29, 2010 Share Posted July 29, 2010 Hello,I read the post quickly:P, I took the code that works and I thank those who posted:D. Greetings all, Marco Nice. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 29, 2010 Share Posted July 29, 2010 I read the post quickly:P, I took the code that works and I thank those who posted:D. So you have no intention to learn? John obviously put a lot of time into his answer to benefit your learning, surely the least you could do was study his code. Quote Link to comment Share on other sites More sharing options...
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.