CAD按块属性统计
本帖最后由 359321852 于 2024-5-12 18:24 编辑请问各位老大,如何实现通过块属性里的编号统计数量
比如想统计按块属性里编号统计数量
获取不到编号的属性值,情高手们帮忙修改一下,
(defun c:tjk1(/ en mpl ss n nn m xx pt0 mpl_new i);统计块数量的源码
(if *table-zg (princ)(setq *table-zg (* 3 (getvar "DIMSCALE"))));设置模式全局变量,初始默认值=1
(setq ss (ssget '((0 . "INSERT"))))
(or ss (setq ss (ssadd)))
(setq n 0 nn (sslength ss) mpl '())
(while (< n nn)
(setq en (ssname ss n) data (entget en))
(setq n (1+ n))
(setq name (cdr (assoc 2 data)))
(setq number (cdr (assoc 41 data))) ; 获取块的属性编号
(setq xx (assoc number mpl)) ; 检查属性编号是否已存在于 mpl 列表中
(if xx
(setq m (cadr xx) m (1+ m) mpl (subst (list number name m) xx mpl)) ; 属性编号存在,则更新数量
(setq mpl (append (list (list number name 1)) mpl)) ; 属性编号不存在,则添加新项
)
)
(if mpl
(progn
(setq i 0)
(setq mpl_new '())
(foreach x mpl
(setq mpl_new (append (list(cons (setq i (1+ i)) x)) mpl_new))
)
(setq mpl_new (append (list (list "序号" "属性编号" "图块名称" "数量")) (reverse mpl_new)))
(initget 0 "S")
(if (/= (setq pt0 (getpoint (strcat "\n当前文字高度:" (rtos *table-zg)))) nil)
(progn
(while (= pt0 "S")
(setq str (strcat "\n(建议高度:"(rtos (* 3 (getvar "DIMSCALE"))) ")" "请输表格文字高度:""<" (rtos *table-zg) ">"))
(if (setq temp (getint str))(setq *table-zg temp));采用新输入值
(initget 0 "S")
(setq pt0 (getpoint (strcat "\n当前文字高度:" (rtos *table-zg))))
(if (null pt0)(exit))
)
(if (and pt0 *table-zg)
(TableLst2Table mpl_new pt0 *table-zg)
)
)
)
(princ "/nNothing!")
)
(princ)
)
)
(defun c:TTT ()
(setq ss (ssget '((0 . "INSERT")))) ; 选择所有的块
(if ss
(progn
(setq count-alist nil); 初始化编号计数的关联列表
(setq sslen (sslength ss))
(setq i 0)
(while (< i sslen)
(setq ent (ssname ss i))
(setq entdata (entget ent))
(setq attribs (entnext ent))
;(princ "\nBlock Reference Data:\n")
;(princ (cdr (assoc 2 entdata))) ;; 显示块名
(while (= (cdr (assoc 0 (entget attribs))) "ATTRIB")
(setq attribdata (entget attribs))
(if (= (cdr (assoc 2 attribdata)) "编号")
(progn
(setq num (cdr (assoc 1 attribdata)))
(setq existing-pair (assoc num count-alist))
(if existing-pair
(setq count-alist (subst (cons num (+ 1 (cdr existing-pair)))
existing-pair
count-alist))
(setq count-alist (cons (cons num 1) count-alist))
)
)
)
(setq attribs (entnext attribs))
)
(setq i (+ i 1))
)
(princ "\nCount of '编号' Values:\n")
(foreach item count-alist
(princ (strcat (car item) ": " (itoa (cdr item)) "\n"))) ; 输出所有编号及其出现次数
)
(princ "\nNo attribute blocks selected.")
)
(princ)
)
tranque 发表于 2024-5-13 09:42
数据提取命令吗,这个命令的交互步骤和过程太繁琐
第一次做完可以保存DXE文件,后面再执行,选DXE,就是无脑下一步直接出结果 dataextraction命令就行,不需要写程序 http://s1.atlisp.cn/static/videos/at-math/统计-块属性.mp4
kozmosovia 发表于 2024-5-12 18:33
dataextraction命令就行,不需要写程序
数据提取命令吗,这个命令的交互步骤和过程太繁琐 kozmosovia 发表于 2024-5-13 15:51
第一次做完可以保存DXE文件,后面再执行,选DXE,就是无脑下一步直接出结果
学习了:handshake 如果你知道hashmap这个数据结构,就知道这个多简单了.
因为lisp没有map,因此可以lisp调用html的js,js里面有map,然后调用它 数据提取使用好了,非常方便,不过限值也很大就是,全公司只有你一个人会;P 发个dwg我看看
attach://134503.dwg
页:
[1]
2