批量选择最外矩形框
本帖最后由 qazxswk 于 2023-9-22 09:05 编辑看到这么一个帖子,http://bbs.mjtd.com/thread-113219-2-1.html
删除方框内的对象,但这个方框是在独立的一个图层里,比较容易选择。
我今天突然有个想法,如果这个外方框,跟方框内的对象,在同一个图层,而且框里也有矩形框,那该如何选择中这些最外围的方框呢?如下面图片,如何框选选中箭头所指的外框?
qazxswk 发表于 2023-9-22 22:37
你们把我的要求看反了
一个原理 把删图行改成删选择集(defun c:tt(/ ptlst ss ss2)
(setq ss(ssget '((0 . "LWPOLYLINE")(90 . 4))))
(foreach ty (vl-remove-if-not '(lambda (x) (= (type x) 'ENAME)) (mapcar 'cadr (ssnamex ss)))
(if (entget ty)
(progn
(setq ptlst nil)
(foreach x (entget ty) (if (= (car x) 10) (setq ptlst (cons (cdr x) ptlst))))
(setq ss2 (ssget "CP" ptlst))
(if(ssmemb ty ss2)(ssdel ty ss2))
(foreach ty (ss-enlst ss2)
(if(ssmemb ty ss)(ssdel ty ss))
)
)
)
)
(sssetfirst nil ss)
(princ)
) 先分堆,可以在论坛上搜索分堆,有现成函数。再判断删除 (defun c:tt (/ pp s x xx)
;;本例是特例,矩形不相交
(if (and (setq s (ssget '((0 . "*PO*"))))
(setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
(setq s (mapcar '(lambda(x)(list x (vla-get-Area (vlax-ename->vla-object x))))s))
(setq s (vl-sort s '(lambda(a b)(>= (cadr a) (cadr b)))))
(setq s (mapcar 'car s))
)
(foreach x s
(if (and (setq pp (mapcar 'cdr (vl-remove-if-not '(lambda(a)(= 10 (car a)))(entget x))))
(< 2 (length pp))
(setq xx (ssget "CP" pp))
(setq xx (ssdel x xx))
)
(command "ERASE" xx "")
)
)
)
)
简单的方法就是挨个循环 每个矩形创建选择集后排除自身 删除 (defun c:tt (/ pp s x xx)
;;本例是特例,矩形不相交
(if (and (setq s (ssget '((0 . "*PO*"))))
(setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
(setq s (mapcar '(lambda(x)(list x (vla-get-Area (vlax-ename->vla-object x))))s))
(setq s (vl-sort s '(lambda(a b)(>= (cadr a) (cadr b)))))
(setq s (mapcar 'car s))
)
(foreach x s
(if (and (setq pp (mapcar 'cdr (vl-remove-if-not '(lambda(a)(= 10 (car a)))(entget x))))
(< 2 (length pp))
(setq xx (ssget "CP" pp))
(setq xx (ssdel x xx))
)
(command "ERASE" xx "")
)
)
)
)
(defun c:tt (/ e pp s x x1 xx)
;;本例是特例,矩形不相交
(if (and (setq s (ssget '((0 . "*PO*"))))
(setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))))
(setq s (mapcar '(lambda(x)(list x (vla-get-Area (vlax-ename->vla-object x))))s))
(setq s (vl-sort s '(lambda(a b)(>= (cadr a) (cadr b)))))
(setq s (mapcar 'car s))
)
(while (setq e (car s))
(if (setq pp (mapcar 'cdr (vl-remove-if-not '(lambda(a)(= 10 (car a)))(entget e))))
(cond
(if (and (< 2 (length pp))
(setq xx (ssget "CP" pp))
(setq x1 (ssdel e xx))
)
(progn
(command "ERASE" x1 "")
(setq xx (vl-remove-if 'listp (mapcar 'cadr (ssnamex xx))))
(setq s (vl-remove-if '(lambda(x)(member x xx))s))
)
(setq s (vl-remove e s))
)
)
)
)
)
) 飞雪神光 发表于 2023-9-22 12:21
简单的方法就是挨个循环 每个矩形创建选择集后排除自身 删除
老大,你的注册时间=2016-11-20最后登录时间=1970-1-1穿越回去了 我也发个(defun c:tt(/ ptlst ss ss2)
(setq ss(ssget '((0 . "LWPOLYLINE")(90 . 4))))
(foreach ty (vl-remove-if-not '(lambda (x) (= (type x) 'ENAME)) (mapcar 'cadr (ssnamex ss)))
(if (entget ty)
(progn
(setq ptlst nil)
(foreach x (entget ty) (if (= (car x) 10) (setq ptlst (cons (cdr x) ptlst))))
(setq ss2 (ssget "CP" ptlst))
(if(ssmemb ty ss2)(ssdel ty ss2))
(vl-cmdf "erase" ss2 "")
)
)
)
(princ)
) 飞雪神光 发表于 2023-9-22 12:37
我也发个
需要从大到小先排序下,否则.... bonny 发表于 2023-9-22 12:35
老大,你的注册时间=2016-11-20最后登录时间=1970-1-1穿越回去了
也许是浏览器的问题 不少人都这样吧