yansu 发表于 2009-12-19 17:30:00

[求助]如何统计块中子块的数量

请求帮忙如何统计块中子块的数量,输出到图纸中,不要分解图块,谢谢

xianaihua 发表于 2009-12-19 18:01:00

给几个别人写的程序,你稍作修改,便可以满足你的要求
运行程序会返回图形或选择集中所有的块树列表
例如:("1" ("2" "3"("4"("5" ("6" ("7"))))))
表示:块“7”在块“6”中,块“6”在块“5”中,块“5”在块“4”中,块“4”,块“3”,块“2”,在块“1”中
;;;作者:highflybird
;;;Main Function
(defun c:BT (/ AllLst bkTree)
(setq *APP (vlax-get-acad-object))
(setq *DOC (vla-get-ActiveDocument *APP))
(setq *BLK (vla-get-blocks *DOC))
(vlax-for blk *BLK
    (setq AllLst (cons (GetNestedName blk) AllLst))
)
(foreach n AllLst
    (setq bkTree (cons (Tree (car n)) bkTree))
)
(princ bkTree)   ; Now BkTree is the return value, it's a blockDef tree.
(princ)
)
;;;Get all names of Nested Blocks in A blockDef
(defun GetNestedName (blk / lst iName)
(vlax-for n blk
    (if (or
          (= (vla-get-objectname n) "AcDbBlockReference")
          (= (vla-get-objectname n) "AcDbMInsertBlock")
      )
      (progn
      (setq iName (vla-get-name n))
      (if (not (member iName lst))
          (setq lst (cons iName lst))
      )
      )
    )
)
(cons (vla-get-name blk) lst)
)
;;;to Construct The BlockDef Tree
(defun Tree (name / lst)
(foreach n (cdr (assoc name AllLst))
    (setq lst (cons (Tree n) lst))
)
(if lst
    (cons name (list lst))
    name
)
)
;;;作者:Leeben
(defun AllBlkNInBlkdef (blkn / blkdef e typ bn bnl e-l nl)
(setq ;bnl    '()
blkdef (tblobjname "block" blkn)
)
(while (setq e (entnext blkdef))
    (setq typ (cdr (assoc 0 (entget e))))
    (if (= typ "INSERT")
      (setq bn (vla-get-name (vlax-ename->vla-object e))
   bnl (if bn
    (cons (if (setq nl (AllBlkNInBlkdef bn))
       (list bn nl)
       bn
   )
   bnl
    )
)
      )
    )
    (setq blkdef e)
)
bnl
)
(defun c:ABnInBl (/ i en ss blknlst ABblknlst)
(setq ss   (ssget '((0 . "INSERT")))
;ABblknlst '()
)
(if ss
    (repeat (setq i (sslength ss))
      (setq en       (ssname ss (setq i (1- i)))
   blkn      (vla-get-name (vlax-ename->vla-object en))
   blknlst   (AllBlkNInBlkdef blkn)
   ABblknlst (cons (if blknlst
    (list blkn blknlst)
    blkn
         )
         ABblknlst
      )
      )
    )
    (princ "*** 你没有选择任何图块 ***")
)
(princ ABblknlst)
(princ)
)

yansu 发表于 2009-12-19 20:28:00

首先感谢2楼的朋友,不过好像有点问题,运行出错。我不太懂编程,还请朋友们帮忙。

yoyoho 发表于 2009-12-20 12:16:00

<p>感谢楼主提供程序</p><p>程序运行O.K.</p>

jsdtzjm 发表于 2011-1-6 17:08:43

复制了,晚上回家研究一下

chenry676 发表于 2021-4-20 20:35:14

楼主得到统计子块插件了吗?

chenry676 发表于 2021-4-29 15:37:24

yoyoho 发表于 2009-12-20 12:16
感谢楼主提供程序程序运行O.K.

请问您统计子块代码整理清楚了吗?
页: [1]
查看完整版本: [求助]如何统计块中子块的数量