用于删除特定
你好哪些代码可以删除我可能包含在例程中的特定层名称?
非常感谢。
迈克尔 最简单的方法可能是使用VL,但为了避免错误,您必须首先确保该层没有以任何方式被引用。
此外,档案中还有:
http://www.cadtutor.net/forum/showthread.php?2022-删除层%28s%29 我不久前也写过这样的话:
(defun c:test nil
(LM:DeleteLayersIf "*")
(princ)
)
;;-----------------=={ Delete Layers If }==-------------------;;
;; ;;
;;Deletes layers in a drawing if the layer name matches a ;;
;;wildcard string ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;;Arguments: ;;
;;wcstr - wildcard string to identify layers to delete ;;
;;------------------------------------------------------------;;
(defun LM:DeleteLayersIf ( wcstr / layers locked ss )
;; © Lee Mac 2010
(setq layers
(vla-get-layers
(vla-get-ActiveDocument
(vlax-get-acad-object)
)
)
)
(foreach x (setq locked (LM:GetLocked layers))
(vla-put-lock x :vlax-false)
)
(setvar 'CLAYER "0")
(if (setq ss (ssget "_X" (list (cons 8 wcstr))))
(
(lambda ( i / e )
(while (setq e (ssname ss (setq i (1+ i))))
(entdel e)
)
)
-1
)
)
(vlax-for l layers
(if (wcmatch (vla-get-name l) wcstr)
(LM:CatchApply vla-delete (list l))
)
)
(foreach x locked
(LM:CatchApply vla-put-lock (list x :vlax-true))
)
(princ)
)
;;-----------------=={ Get Locked Layers }==------------------;;
;; ;;
;;Returns a list of VLA Layer Objects locked within the ;;
;;current drawing ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;;Arguments: ;;
;;layers - the layers collection for the current drawing ;;
;;------------------------------------------------------------;;
;;Returns:List of VLA Layer Objects, else nil ;;
;;------------------------------------------------------------;;
(defun LM:GetLocked ( layers )
;; © Lee Mac 2010
(vlax-for l layers
(if (eq :vlax-true (vla-get-lock l))
(setq locked (cons l locked))
)
)
locked
)
;;---------------------=={ Catch Apply }==--------------------;;
;; ;;
;;Applies a function to a list of arguments and catches ;;
;;an exception. ;;
;;------------------------------------------------------------;;
;;Author: Lee Mac, Copyright © 2010 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;;Arguments: ;;
;;foo- function to be applied ;;
;;args - list of arguments to be supplied to foo ;;
;;------------------------------------------------------------;;
;;Returns:Result of applying foo, else nil if exception ;;
;;------------------------------------------------------------;;
(defun LM:CatchApply ( foo args / result )
;; © Lee Mac 2010
(if
(not
(vl-catch-all-error-p
(setq result
(vl-catch-all-apply (function foo) args)
)
)
)
result
)
) 李的精彩套路。
非常感谢。
迈克尔 不客气,迈克尔 只是一个问题。。。如果这些层中的一个或多个层上的块中存在实体,会发生什么?
然后,为了使lisp尽可能简单,为什么不简单地使用LayDel命令呢?
关于区块内实体的问题很好,这就是我今天想要检查的,但我没有检查,因为我太忙了。
我没有使用命令调用,因为我不想在我的例程中的代码中添加命令调用,所以要用可能
单独使用Lisp代码会更强大、更好,对于我这个初学者来说,我希望熟悉Lisp而不是依赖它
的命令调用。
非常感谢irneb先生
迈克尔 没问题。。。我只是建议您在处理DWG中的所有块定义时要小心一点。修改动态块引用时生成的未命名块之类的内容可以(通常也会)与原始动态块定义解除链接。因此,诀窍是试着找出哪些块是不可触摸的。
尽管如此,获取块定义的常规ALisp方法(即使用tblsearch、tblobjname、tblnext等)仅给出DWG内的一些块定义。获取所有控件的另一种方法是单步执行ActiveX块集合。要了解VLisp的一些内容,请参阅Lee的有用帖子:http://www.cadtutor.net/forum/showthread.php?53374-xref clip boundry&p=361940&viewfull=1#post361940
基本上,当前图形(或者更确切地说是ActiveDocument)有一个称为块的特性。这是块定义的集合,它们还包括模型空间和所有图纸空间块。然后,每个块定义也是该定义内对象的集合。您可以使用vlax for函数快速轻松地逐步完成集合。
页:
[1]