一种获取图中及外部引用中指定块名的方法
本帖最后由 wharan 于 2022-6-23 10:26 编辑为了提取图中图标信息,借用了论坛中大侠的某些代码:自动选取图中及外部引用中的所有图标块,返回该块的图元名列表。;; [功能] 返回外部引用中名为Bname的图块实体列表
(defun HH:Xrefblk (Bname / bock-name
ss t-get-bock-all-name
t-get-lst-unique
)
;;说明:删除表里的重复元素
;;参数:l:表
;;返回:表
;;用法T-get-lst-Unique '(1 2 5 8 2 3 2 5 2 6))-->'(1 2 5 8 3 6)
(defun T-get-lst-Unique (lst / s-car new)
(while lst
(setq s-car (car lst))
(if (vl-position s-car new)
nil
(setq new (cons s-car new))
)
(setq lst (cdr lst))
)
(setq new (reverse new))
)
;;返回:图元名表
(defun T-get-bock-all-name (bock-name / dxf last-name name)
(setq name-lst nil)
(setq
last-name
(tblobjname "block" (cdr (assoc 2 (entget bock-name))))
)
(while (setq last-name (entnext last-name))
(setq dxf (entget last-name))
(setq name (cdr (assoc -1 dxf)))
(if (and (= (cdr (assoc 0 dxf)) "INSERT")
(wcmatch (cdr (assoc 2 dxf)) Bname)
)
(setq name-lst (cons name name-lst))
)
)
(setq name-lst (T-get-lst-Unique name-lst))
name-lst
)
(princ "自动选择目标")
(if
(setq ss (ssget "A"
(list (cons 0 "insert")
)
)
)
(progn
(while (setq bock-name (ssname ss 0))
(setq
name-lst (append name-lst (T-get-bock-all-name bock-name))
)
(setq ss (ssdel bock-name ss))
)
)
)
)
感谢大佬分享收藏备用啦
页:
[1]