- 积分
- 1485
- 明经币
- 个
- 注册时间
- 2007-12-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
请高手增加一个合并输出结果 ,把第一层的 和嵌套层的输出结果 合并成一个新的输出,原有的保留。
;;该程序将生成一份详细说明个人的报告;
;; ;;中的主块和嵌套块,动态块和外部参照的数量
;;选择或整个工程图。 ;;
;;该程序将正确计算嵌套块的数量;
;;嵌套的动态块和嵌套的外部参照;嵌套到任何级别;和;;
;;在每个级别具有相同块的任意数量的实例。 ;;
;;当然,该程序可用作标准块计数器。
;;由于嵌套的块计数数据与;;分开显示
;;主要块计数数据,并且不会显示嵌套报告;
;;如果工程图中没有嵌套块。 ;;
;;该报告将打印到命令行,并分别显示详细信息;
;;分解为;;的主要块和嵌套块的数量;
;;每个块名称的数量,以及总数;
;;与报告相邻的主要块和嵌套块的数量;
;;标题。随后可以将打印的报告提取为;;
;;文本文件或CSV文件。 ;;
;; ------------------------------------------------ ---------------------- ;;
;;作者:Lee Mac,版权所有?2014-www.lee-mac.com ;;
;; ------------------------------------------------ ---------------------- ;;
;;版本1.5-2014-02-02 ;;
(defun c:BlockCount
(
/
_GetBlockCount
_OutputResults
_Main
)
(defun _GetBlockCount;获得块数量
(
selection
/
_Assoc++
_BlockHierarchy
_GetBlockHierarchy
_EffectiveName
_UpdateNestedBlockCount
_IterateSelection
)
(defun _Assoc++ ( key value lst / pair )
(if (setq pair (assoc key lst))
(subst (cons key (+ value (cdr pair))) pair lst)
(cons (cons key value) lst)
)
)
(defun _BlockHierarchy ( blk / alist enx );块层次结构
(while (setq blk (entnext blk))
(if
(and
(= "INSERT" (cdr (assoc 0 (setq enx (entget blk)))))
(/= 1 (cdr (assoc 60 enx)))
)
(setq alist (_Assoc++ (cdr (assoc 2 enx)) 1 alist))
)
)
alist
)
(defun _GetBlockHierarchy ( / block name tree );---获取块层次结构
(while (setq block (tblnext "block" (null block)))
(setq tree
(cons
(cons
(setq name (cdr (assoc 2 block)))
(_BlockHierarchy (tblobjname "block" name))
)
tree
)
)
)
tree
)
(defun _EffectiveName ( ent / blk rep );---有效名称
(if (wcmatch (setq blk (cdr (assoc 2 (entget ent)))) "`**")
(if
(and
(setq rep
(cdadr
(assoc -3
(entget
(cdr
(assoc 330
(entget
(tblobjname "block" blk)
)
)
)
'("AcDbBlockRepBTag")
)
)
)
)
(setq rep (handent (cdr (assoc 1005 rep))))
)
(setq blk (cdr (assoc 2 (entget rep))))
)
)
blk
)
(defun _UpdateNestedBlockCount ( name count tree alist / nests );更新嵌套块计数
(if (setq nests (cdr (assoc name tree)))
(foreach nest nests
(setq alist
(_UpdateNestedBlockCount (car nest) (* count (cdr nest)) tree
(_Assoc++
(_EffectiveName (tblobjname "block" (car nest)))
(* count (cdr nest))
alist
)
)
)
)
alist
)
)
(defun _IterateSelection ( selection blocktree / block idx nested primary );反复选择
(if selection
(repeat (setq idx (sslength selection))
(setq block (ssname selection (setq idx (1- idx)))
primary (_Assoc++ (_EffectiveName block) 1 primary)
nested (_UpdateNestedBlockCount (cdr (assoc 2 (entget block))) 1 blocktree nested)
)
)
)
(list primary nested)
)
(_IterateSelection selection (_GetBlockHierarchy))
)
(defun _OutputResults;---输出结果
(
data
/
_PrintReport
_PrintFile
_PrintOutput
)
(defun _PrintReport(data / _PadBetween _PrintIt);---打印报告
(defun _PadBetween ( s1 s2 ch ln );------------
(
(lambda ( a b c )
(repeat (- ln (length b) (length c)) (setq c (cons a c)))
(vl-list->string (append b c))
)
(ascii ch)
(vl-string->list s1)
(vl-string->list s2)
)
)
(defun _PrintIt ( lst wid );---------
(princ (_PadBetween "\n" "" "=" wid))
(princ "\n 块 计数:")
(princ (_PadBetween "\n" "" "=" wid))
(princ
(_PadBetween
(strcat
"\n 第一级: ("
(itoa (apply '+ (mapcar 'cdr (car lst))))
")"
)
"Count" " " wid
)
)
(princ (_PadBetween "\n" "" "-" wid))
(foreach item
(vl-sort
(car lst)
(function (lambda ( a b ) (< (car a) (car b))))
)
(princ (_PadBetween (strcat "\n " (car item)) (itoa (cdr item)) "." wid))
)
(if (cadr lst)
(progn
(princ (_PadBetween "\n" "" "=" wid))
(princ
(_PadBetween
(strcat
"\n 嵌套块 ("
(itoa (apply '+ (mapcar 'cdr (cadr lst))))
")"
)
"Count" " " wid
)
)
(princ (_PadBetween "\n" "" "-" wid))
(foreach item
(vl-sort
(cadr lst)
(function (lambda ( a b ) (< (car a) (car b))))
)
(princ (_PadBetween (strcat "\n " (car item)) (itoa (cdr item)) "." wid))
)
)
)
(princ (_PadBetween "\n" "" "=" wid))
)
(_PrintIt data 70)
)
(defun _PrintFile( data file / _PrintIt _WriteFile);打印到文件
(defun _PrintIt ( lst del des );----------------------
(princ "块数" des)
(princ
(strcat
"\n第一组块 ("
(itoa (apply '+ (mapcar 'cdr (car lst))))
")"
del
"数量"
)
des
)
(foreach item;---将表中的所有成员以指定变量的身份带入表达式求值
(vl-sort;---根据给定的比较函数来对表中的元素排序
(car lst)
(function (lambda ( a b ) (< (car a) (car b))))
)
(princ (strcat "\n" (car item) del (itoa (cdr item))) des)
)
(if (cadr lst)
(progn
(princ
(strcat
"\n\n嵌套块 ("
(itoa (apply '+ (mapcar 'cdr (cadr lst))))
")"
del
"数量"
)
des
)
(foreach item
(vl-sort
(cadr lst)
(function (lambda ( a b ) (< (car a) (car b))))
)
(princ (strcat "\n" (car item) del (itoa (cdr item))) des)
)
)
)
)
(defun _WriteFile ( data file / desc );---------写入文件
(if file
(if (setq desc (open file "w"))
(progn
(_PrintIt
data;---------------数据
(if (= ".txt" (strcase (vl-filename-extension file) t)) "\t" ",")
desc
)
(close desc)
(startapp "explorer" file)
)
(princ "\n无法写入所选文件.")
)
(princ "\n*Cancel*")
)
)
(_WriteFile data file)
)
(defun _PrintOutput ( data / out );----------------输出
(_PrintReport data)
(textpage)
(initget "TXT CSV")
(cond
( (setq out (getkword "\n输出结果为 [TXT/CSV] <Exit>: "))
(_PrintFile data (getfiled "创建输出文件" "" (strcase out t) 1))
(graphscr)
)
( (graphscr) )
)
)
(_PrintOutput data)
)
;----------------------------------------------------------------
(defun _Main
(
/
*error*
_CountBlocks
)
(defun *error* ( msg );---------------------- 出错处理
(if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
(princ (strcat "\nError: " msg))
)
(princ)
)
(defun _CountBlocks ( / allblocks sel );-------------------------标记88
(cond
( (null (setq allblocks (ssget "_X" '((0 . "INSERT")))))
(princ "\n当前图纸中未找到任何块.")
)
( (progn
(setvar 'nomutt 1)
(princ "\n选择要计数的块 <all>: ")
(setq sel
(cond
( (null (setq sel (vl-catch-all-apply 'ssget '(((0 . "INSERT"))))))
allblocks
)
( (null (vl-catch-all-error-p sel))
sel
)
)
)
(setvar 'nomutt 0)
sel
)
(_OutputResults (_GetBlockCount sel))
)
)
(princ)
)
(_CountBlocks)
)
(_Main)
)
;;----------------------------------------------------------------------;;
;;;(princ
;;; (strcat
;;; "\n:: BlockCount.lsp | Version 1.5 | \\U+00A9 Lee Mac "
;;; (menucmd "m=$(edtime,0,yyyy)")
;;; " www.lee-mac.com ::"
;;; "\n:: Type \"BlockCount\" to Invoke ::"
;;; )
;;;)
(princ)
;;----------------------------------------------------------------------;;
;; End of File ;;
;;----------------------------------------------------------------------;;
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|