【K:SSplit4Lay 】根据图层名称拆分选择集SS
本帖最后由 kucha007 于 2023-4-23 09:52 编辑;根据图层名称拆分选择集SS
(defun K:SSplit4Lay (SS / EntLst en Tmp LayLst Lay LayEnts)
(defun LM:ss->ent (SS / i Lst)
(if SS
(repeat (setq i (sslength SS))
(setq Lst (cons (ssname SS (setq i (1- i))) Lst))
)
)
);将选择集转换为实体列表 by Lee Mac
(setq EntLst (LM:ss->ent SS))
(foreach en EntLst
(setq Tmp (cdr (assoc 8 (entget en))))
(if (not (member Tmp LayLst))
(setq LayLst (cons Tmp LayLst))
)
);获取选择集包含的图层名称
(foreach Lay LayLst
(setq Tmp '())
(foreach en EntLst
(if (eq (strcase Lay) (strcase (cdr (assoc 8 (entget en)))))
(setq Tmp (cons en Tmp))
)
)
(setq LayEnts (cons (cons Lay Tmp) LayEnts))
)
(reverse LayEnts)
)
大概是这种感觉:
(K:SSplit4Lay SS) => (("Lay1" en1 en2 ... en_i) ("Lay2" en4 en5 en6 ...en_j)....)
(defun group-by-layer (ss)
;; 选择集转列表
(setq ents (pickset:to-list ss))
;; 按 图层名排序
(setq ents (vl-sort ents '(lambda (x y) (< (entity:getdxf x 8)
(entity:getdxf y 8)))))
;; 按图层名分组
(list:group-by ents
'(lambda (x y) (= (entity:getdxf x 8)
(entity:getdxf y 8))))
) 感谢楼主分享
页:
[1]