本帖最后由 77077 于 2014-2-24 22:09 编辑
求大师们帮个忙,做一个块属性提取到excel的lsp。
要求:1.只提取“地块_控制信息”这个图层上的属性块。2.结果输出到excel
图中蓝色字体为表头,绿色字体为内容,以前一直用“attext”命令来提取,发现不能直接提取到excel,而且效率极慢。
最后多谢大师们了,提供lsp源码,我初学者,不会编写lsp,只略会些修改。
经过搜索,终于找到合适的源码了.感谢Gu_xl大大~块属性输出到csv!- (defun c:tt (/ d r ss n obj atts)
- (while (setq d (tblnext "block" (null d)))
- (setq r (cons (cdr (assoc 2 d)) r))
- )
- (and r
- (setq filename (getfiled "属性输出文件名" "" "csv" 1))
- )
- (if filename
- (progn
- (setq f (open filename "w"))
- (foreach name r
- (setq ss (ssget '((0 . "INSERT"))));选择对象,修改这里.
- (if ss
- (progn
- (setq atts (append
- (vlax-invoke (setq obj (vlax-ename->vla-object (ssname ss 0))) 'GetConstantAttributes)
- (vlax-invoke obj 'GetAttributes)
- )
- )
- (princ "序号," f)
- (foreach att atts
- (princ (vla-get-TagString att) f)
- (princ "," f)
- );求出属性列表,写表头
- (princ "\n" f)
- (setq n -1)
- (repeat (sslength ss)
- (setq obj (vlax-ename->vla-object (ssname ss (setq n (1+ n)))))
- (setq atts (append
- (vlax-invoke obj 'GetConstantAttributes)
- (vlax-invoke obj 'GetAttributes)
- )
- )
- (princ (1+ n) f) (princ "," f)
- (foreach att atts
- (princ (vla-get-TextString att) f) (princ "," f)
- )
- (princ "\n" f);写出属性值
- )
- )
- )
- )
- (close f)
- )
- )
- )
|