marmo 发表于 2022-7-5 16:19:46

解锁所有层

你好
我想知道是否有人知道一个lisp来解锁所有层。
谢谢
马可

ReMark 发表于 2022-7-5 16:24:09

寻找,你就会发现。因此,在右上角的高级搜索框的原因。
 
http://www.cadtutor.net/forum/showthread.php?47611-解锁所有层

Tharwat 发表于 2022-7-5 16:26:38

你好
 
不需要lisp,Autocad已经支持它。
 
命令:layulk
 
当做
 
塔瓦特

Se7en 发表于 2022-7-5 16:29:27

为什么不需要通过lisp解锁层?如果您的程序必须绘制一些东西,并且层被锁定,该怎么办?
 
这是一个快速编写的程序,可以解锁图形中的所有层(这只是一个快速演示)。
( (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)))) )

alanjt 发表于 2022-7-5 16:34:14

在代码中,使用Se7en的方式,只需知道您也可以从命令行执行此操作。
 
如。
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]:

Se7en 发表于 2022-7-5 16:38:35

这是另一种Visual Lisp方法。
( (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))))) )
 
这里有一些更酷的东西只使用自动Lisp。我使用大量变量创建了它,这样你可以更好地遵循这个过程。
 
( (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.
)

Se7en 发表于 2022-7-5 16:40:32

好的,我现在就停下来,你明白了。

Se7en 发表于 2022-7-5 16:43:01

*我刚想起来为什么我不在这里发代码。。。愚蠢的GPL执照;我不希望我的代码在GPL下。
 
我将修复/添加我的标题到我上面发布的代码。

gile 发表于 2022-7-5 16:46:42

你好
 
这里有一种使用defun-q在函数中存储未锁定层列表的方法,这样就可以通过调用相同的函数来重新锁定层。
 
使用
(gc:LayerUnLockAll T)解锁所有锁定的层,并将其存储在函数内的列表中
(gc:LayerUnLockAll nil)重新锁定先前存储在函数中的未锁定层。
 
;;; 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
)

Lee Mac 发表于 2022-7-5 16:50:18

吉尔,
 
这不应该:
 

(setq    layerunlockall
    (cons (car layerunlockall)
          (cons (list 'setq 'lst (list 'quote lst))
            (cddr layerunlockall)
          )
    )
)

 
be:
 

(setq    gc:layerunlockall
    (cons (car gc:layerunlockall)
          (cons (list 'setq 'lst (list 'quote lst))
            (cddr gc:layerunlockall)
          )
    )
)
页: [1] 2
查看完整版本: 解锁所有层