Jump to content

unlock all layers


marmo

Recommended Posts

  • Replies 32
  • Created
  • Last Reply

Top Posters In This Topic

  • Se7en

    7

  • alanjt

    5

  • marmo

    5

  • gile

    4

Top Posters In This Topic

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 by Se7en
The forum's obtuse GPL licence rule.
Link to comment
Share on other sites

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]:

Link to comment
Share on other sites

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 by Se7en
because someone didnt read the GPL and i dont want this code under the GPL
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by gile
corrected a bad translation (see Lee's reply above)
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Hello,:shock:

I read the post quickly:P, I took the code that works and I thank those who posted:D.

Greetings all,

Marco

Link to comment
Share on other sites

Hello,:shock:

I read the post quickly:P, I took the code that works and I thank those who posted:D.

Greetings all,

Marco

Nice.:glare:
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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