本帖最后由 vitalgg 于 2021-7-13 19:29 编辑
下载: @lisp.fas
命令行方式可以实现任意 dxf 组码的统计。
通用函数 (@:stat-entity stat-item ssfilter)
stat-item: 统计项目(dxf 组码比如图层 为8 );
ssfilter: 选择集过滤
 - ;; 要统计单行文本在不同图层的个数
- (@:stat-entity 8 '((0 . "TEXT"))) ;;要统计单行文本在不同图层的个数
- (@:stat-entity 7 '((0 . "TEXT"))) ;;要统计单行文本的不同文字样式的个数
- (@:stat-entity 8 '((0 . "LINE"))) ;;统计所选中的直线在每个图层下的个数
- (@:stat-entity 8 '((0 . "insert"))) ;;统计所选中的图块在每个图层下的个数
- (@:stat-entity 62 '((0 . "line"))) ;;统计所选中的直线的不同颜色的个数,随层的为 nil,因为随层图元的没有这个组码。

 - (@:add-menu "统计" "图块名" "(@:stat-block-by-name)")
- (@:add-menu "统计" "属性" "(@:menu-stat-block-by-attribute)")
- (@:add-menu "统计" "单行文本" "(@:menu-stat-text)")
- (@:add-menu "统计" "--" "--")
- (@:add-menu "统计" "输出结果" "(stat:print)")
- (@:add-menu "统计" "绘制结果" "(stat:draw)")
- ;;(@:add-menu "统计" "块属性" "(@:stat-block-by-attribute)")
- (defun @:stat-block-by-name ()
- "统计选中块的块名及数量。"
- (setq @:tmp-stat-result
- (stat:stat
- (mapcar (function
- (lambda (x)
- (block:get-effectivename x)))
- (ss:ss-to-entlist (ssget '((0 . "insert"))))))))
- (defun @:stat-block-by-attribute (attribute-name block-name)
- "统计选中的指定块名中的某一属性的值及数量。"
- (setq @:tmp-stat-result
- (stat:stat
- (mapcar (function
- (lambda (x)
- (if (= block-name (block:get-effectivename x))
- (cdr (assoc attribute-name (block:get-attributes x)))
- )))
- (ss:ss-to-entlist (ssget '((0 . "insert"))))))))
- (defun @:menu-stat-block-by-attribute (/ blk-name attribute-name)
- (setq blk-name (getstring "请输入要统计的块名称:"))
- (setq attribute-name (getstring "请输入要分类统计的块属性的名称:"))
- (@:stat-block-by-attribute attribute-name blk-name))
-
- (defun @:stat-entity (stat-item ssfilter)
- "stat-item: 统计项目(dxf 组码比如图层 为8 ); ssfilter 选择集过滤"
- (setq @:tmp-stat-result
- (stat:stat
- (mapcar (function
- (lambda (x)
- (cdr (assoc stat-item (entget x)))))
- (ss:ss-to-entlist (ssget ssfilter))))))
- (defun @:menu-stat-text (/ ssfilter)
- (setq strfilter (getstring "请输入文本通配符(示例 GBZ* ?BZ* LL*): "))
- (if (/= "" strfilter)
- (setq ssfilter (list '(0 . "TEXT") (cons 1 strfilter)))
- (setq ssfilter (list '(0 . "TEXT"))))
- (setq @:tmp-stat-result
- (stat:stat
- (mapcar (function
- (lambda (x)
- (cdr (assoc 1 (entget x)))))
- (ss:ss-to-entlist (ssget ssfilter))))))
视频演示:
http://atlisp.cn/package-info?name=vitalmath&edition=stable
|