本帖最后由 chg 于 2010-12-11 21:54 编辑
看了两个函数的解释,第一个ENTNEXT--可以通过调用entnext函数遍历复杂图元的子图元来访问复杂图元的内部结构;第二个tblnext--(tblnext “block" t)将返回块条目中的第一个块的块表,其中-2组,其组值是该块定义中的第一个图元的图元名(如果有的话),并且可以被entnext函数接受,从而扫描组成块定义的各个图元。所以写了以下一个命令,但命令运行明显不对,请大家指教。
- (defun c:aaa (/ firstblk bname bnamelist blklist cnt ename enamelist entlist nextent bname1 blk)
- (setq firstblk (tblnext "block" t)
- bname (cdr (assoc 2 firstblk))
- bnamelist (list bname)
- ename (cdr (assoc -2 firstblk))
- enamelist (list ename)
- blk (tblnext "block")
- cnt 0
- )
- (while blk
- (setq bname (cdr (assoc 2 blk))
- bnamelist (append (list bname) bnamelist)
- ename (cdr (assoc -2 blk))
- enamelist (append (list ename) enamelist)
- blk (tblnext "block")
- )
- )
- (setq bnamelist (reverse bnamelist)
- enamelist (reverse enamelist)
- bname (nth cnt bnamelist)
- ename (nth cnt enamelist)
- cnt (1+ cnt)
- nextent t
- )
- (while bname
- (while (setq nextent (entnext ename))
- (if nextent
- (progn
- (setq ename (cdr (assoc -1 (entget nextent)))
- entsort (cdr (assoc 0 (entget nextent)))
-
- )
- (if (= entsort "INSERT")
- (setq bname1 (cdr (assoc 2 (entget nextent)))
- blklist (append (list bname1) blklist)
- )
- )
- )
- )
- )
- (setq bname (nth cnt bnamelist)
- ename (nth cnt enamelist)
- cnt (1+ cnt)
- )
- )
- (princ blklist)
- (princ)
- )
|