本帖最后由 kucha007 于 2023-12-19 12:13 编辑
最近接触到的几种删除对象的方法,这里以删除层内对象为例,分享给大家,也欢迎大佬补充完善。
01-首先,我们得有一个选择集:
- (setq ss (ssget "_x" (list '(8 . "0"))));选中0图层的所有对象
02-解锁图层,避免对象锁定无法删除
- (setq LayObj (vlax-ename->vla-object (tblobjname "LAYER" "0")))
- ;(vla-put-layeron LayObj :vlax-true);打开
- (vla-put-lock LayObj :vlax-false);解锁
- ;(vla-put-freeze LayObj :vlax-false);解冻
※注意:注释掉的部分可以相互替换
方法一:command / vl-cmdf
- (command "_ERASE" ss "")
- ;(vl-cmdf "_ERASE" ss "")
方法二:entdel / Vla- (repeat (setq i (sslength ss))
- (entdel (ssname ss (setq i (1- i))))
- ;(vla-erase (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
- ;(vla-delete (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
- )
方法二扩展:repeat也可以用while代替
- (setq i (sslength ss))
- (while (setq en (ssname ss (setq i (1- i))))
- (entdel en )
- ;(vla-erase (vlax-ename->vla-object en))
- ;(vla-delete (vlax-ename->vla-object en))
- )
|