分解所有动态块exc
我制作了一个lisp例程来分解除“DOORMODEL1,DOORMODEL2”之外的所有动态块。但它不起作用,问题是什么?选择?有人能帮我吗?(defun c:test ()
(sssetfirst
nil
(ssget
'(
( 0 . "INSERT")
(-4 . "<AND")
(-4 . "<NOT")
(2 . "`*U* , DOORMODEL1,DOORMODEL2")
(-4 . "NOT>")
(-4 . "AND>")
)
)
)
(command "qaflags" "1")
(COMMAND "EXPLODE" "P" "")
(command "qaflags" "0")
)
提前感谢 动态块可能会获得与“`U*”匹配的匿名名称,因此不能仅依赖ssget过滤器。
但是,这不适用于块参照的vla对象的“EffectiveName”特性。
因此,答案是迭代选择集,将每个ename转换为vla对象,检查其有效名称
并相应地决定何时使用“Explode and”Delete方法或保持原样。 gc 2 wcmatch字符串包含其他空格。它正在寻找名为“*U123”(尾随空格)和“DOORMODEL1”(前导空格)的块,它们不存在。当然,代码也相当危险。如果用户没有选择任何内容,会发生什么? 感谢Grrr和Roy_43的回复。所以这并不像我想的那么简单。然而,我对lisp的了解并没有超出我的lisp。甚至我也从其他lisp例程编译。事实上,我的例行程序要求进行选择,但我希望例行程序能够做到这一点。
我应该做什么改变才能让它工作?
PmxCAD 举个例子:
(defun C:test ( / L SS e o nm ) ;; Define a function and localise the used variables
(setq L (mapcar 'strcase '("DoorModel" "DoorModel"))) ;; Initially set a list of block names, capitalise all items using (strcase)
(if (setq SS (ssget '((0 . "INSERT")))) ;; Prompt the user for a selection set of blocks and check if user selected any
(repeat (sslength SS) ;; iterate through the selection set
(setq e (ssname SS 0)) ;; first entity inside the selection set
(setq o (vlax-ename->vla-object e)) ;; convert that entity into a vla-object
(setq nm (strcase (vla-get-EffectiveName o))) ;; extract the EffectiveName property from the vla-object (the "True Block Name" if you prefer)
(if (not (member nm L)) ;; check if the EffectiveName is not "DOORMODEL1" or "DOORMODEL2"
(progn ;; if the EffectiveName is not member of that list
(vla-Explode o) ;; call the Explode method (literaly explode the block)
(vla-Delete o) ;; call the Delete method (erase the original block)
); progn
); if
(ssdel e SS) ;; erase the first entity inside the selection set, so the next entity could be processed
); repeat
); if SS
(princ) ;; Exit cleanly
); defun
(vl-load-com)(princ) ;; Load the visual lisp extensions, cleanly
Grrr它适用于动态块,但也可以分解正常的非动态块,我真的不想这样做。
要检查块是否为动态块,请执行以下操作:
(eq (vla-get-IsDynamicBlock block_vla-object) :vlax-true) 好的,但这部分在Lisp程序中放在哪里?
页:
[1]