我已经发现了一个Lisp程序在这个论坛上由米克洛斯Fuccaro(谢谢)这是非常接近我需要的,我已经修改了一些,但仍然有一个问题。Lisp将命名块的属性输出到文本文件,以便导入标签打印软件,这正是我所需要的,但用逗号分隔的文本字符串需要放在一列中。
i、 e.a、b、c、d应为
一
b
c
d
我需要保留任何空白属性,这样它们就会产生一个空白行。
代码如下:
; 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;;Modified March 2009 by B.Leslie to write Attributes only and name txt file with DWG filename.(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 "F:\\ENGINEER\\GENERIC\\Label Schedule\\Extracted Labels\\MK_Equipment_" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname"))4)) ".TXT") "a") i -1) (repeat (sslength ss) (setq Edata (entget (setq e (ssname ss (setq i (1+ i)))))) (while (/= (Dxf 0 Edata) "SEQEND") (if (and (= (Dxf 0 Edata) "ATTRIB") (member (dxf 2 Edata) TagList);;if tag is on list );and (progn (setq valRow (cons (Dxf 1 Edata) ValRow)) );progn ) (setq Edata (entget (setq e (entnext e)))) );while (write-line (List2String (reverse ValRow)) file) );repeat (close file) (princ (strcat "\nDone writing file " Root "MK_Equipment.txt")) (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)
谢谢你的帮助。
布莱恩