我在另一个论坛上回复了iosa1,但认为它也应该放在这里,因为它建立在这个线程和Fuccaro的例程上。编辑第二行和第三行,以指定要提取的块名和标记名。列表中文本的大小写需要匹配块名和标记名。
- ; Global ATTribute EXtractor
- ; by Miklos Fuccaro [email="mfuccaro@hotmail.com"]mfuccaro@hotmail.com[/email]
- ;-------------------------November 2004 -------
- ;;Edited March 2006 by C. Bassler to allow specification of block and tage names to extract
- (defun gattex()
- (setq Blocklist '("Name1" "Name2" "Name3"));; ** edit to include block names to select
- (setq TagList '("Tag1" "TAG2" "Tag3"));; ** edit to include tag names to extract
- ;;create block names separated by columns, for selection filter
- (setq Blocknames (List2String BlockList))
- (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 BlockNames))))
- (if (not ss) (quit))
- (setq Root (getvar "DWGPREFIX"))
- (setq file (open (strcat Root "attributes.CSV") "a") i -1)
- (write-line (strcat Root (getvar "DWGNAME")
- " -found " (itoa (sslength ss))
- " block(s) with attributes") file)
- (repeat (sslength ss)
- (setq TagRow nil ValRow nil)
- (setq Edata (entget (setq e (ssname ss (setq i (1+ i))))))
- (write-line "" file)
- (write-line (strcat "block name:" "," (Dxf 2 Edata)) file)
- (while (/= (Dxf 0 Edata) "SEQEND")
- (if
- (and
- (= (Dxf 0 Edata) "ATTRIB")
- (member (dxf 2 Edata) TagList);;if tag is on list
- );and
- (progn
- (setq TagRow (cons (Dxf 2 Edata) TagRow))
- (setq valRow (cons (Dxf 1 Edata) ValRow))
- );progn
- )
- (setq Edata (entget (setq e (entnext e))))
- );while
- (write-line (List2String (reverse TagRow)) file)
- (write-line (List2String (reverse ValRow)) file)
- );repeat
- (close file)
- (princ (strcat "\nDone writing file " Root "attributes.csv"))
- (princ)
- );defun
- ;;-------------------------------
- (defun List2String (Alist)
- (setq NumStr (length Alist))
- (foreach Item AList
- (if (= Item (car AList));;first item
- (setq LongString (car AList))
- (setq LongString (strcat LongString "," Item))
- )
- )
- LongString
- );defun
- ;;--------------------------------
- (defun Dxf (code pairs)
- (cdr (assoc code pairs))
- )
- (gattex)
|