本帖最后由 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)
- )
- )
|