明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3834|回复: 11

[分享]将块的一些信息提取到EXCEL

  [复制链接]
发表于 2005-1-28 09:53:00 | 显示全部楼层 |阅读模式
前不久从台湾买了一本书,其中有一个将块的一些信息提取到EXCEL的程序很不错,拿来与诸位分享。这个范例不错,至少我能看懂。:) (defun c:blk2xls (/ apl-exit initexcel endexcel datacell dorow dotable appxls
xlsworkbooks newbook newsheet newitem xlscells objs count
ent claves numrow title blkss blksub blk_qty k0 i0 blkname
xscale yscale zscale rotang
blkdxf numcol insert0)
;;;1.定义离开函数
(defun apl-exit (msg)
(endexcel)
(prompt msg)
(setq *error* oer)
)
;;;2.initexcel用来初始M Excel
(defun initexcel ()
(setq appxls (vlax-get-or-create-object "excel.application")
xlsworkbooks (vlax-get-property appxls "workbooks")
newbook (vlax-invoke-method xlsworkbooks "add")
newsheet (vlax-get-property newbook "sheets")
newitem (vlax-get-property newsheet "item" 1)
xlscells (vlax-get-property newitem "cells")
)
(vla-put-visible appxls :vlax-true)
)
;;;3.endexcel用来释放excel
(defun endexcel ()
(vlax-release-object xlscells)
(vlax-release-object newitem)
(vlax-release-object newsheet)
(vlax-release-object newbook)
(vlax-release-object xlsworkbooks)
(vlax-release-object appxls)
)
;;;4.datacell将value填入numrow,col的格子中
(defun datacell (nurow col value)
(vlax-put-property xlscells "item" numrow col (vl-princ-to-string value))
)
(setq oer *error*
*error* apl-exit
)
(vl-load-com)
(initexcel)
(setq numrow 1 numcol 0)
;;;5.列出表头
(datacell numrow (setq numcol (1+ numcol)) "Bock name")
(datacell numrow (setq numcol (1+ numcol)) "X scale")
(datacell numrow (setq numcol (1+ numcol)) "Y scale")
(datacell numrow (setq numcol (1+ numcol)) "Z scale")
(datacell numrow (setq numcol (1+ numcol)) "Angle")
(datacell numrow (setq numcol (1+ numcol)) "Number")
;;;6.依次处理各图块的参考
(setq blkdxf (tblnext "BLOCK" t))
(while blkdxf ;while1
(setq blkname (cdr (assoc 2 blkdxf))
blkss (ssget "x" (list (cons 0 "INSERT") (cons 2 blkname)))
)
(setq i0 0)
(if blkss
(setq blkss_qty (sslength blkss)) ;写出块的数量
(setq blkss_qty 0);图面上没有这个块则数量为0
)
(while (< i0 blkss_qty) ;while2 ;当有这个图块时;;;7.依条件建立图块参考的选集
(setq insert0 (ssname blkss i0)
xscale (cdr (assoc 41 (entget insert0)))
yscale (cdr (assoc 42 (entget insert0)))
zscale (cdr (assoc 43 (entget insert0)))
rotang (cdr (assoc 50 (entget insert0)))
blksub (ssget "x" (list (cons 0 "INSERT")
(cons 2 blkname)
(cons 41 xscale)
(cons 42 yscale)
(cons 43 zscale)
(cons 50 rotang)))
blkss_qty (- blkss_qty (sslength blksub))
numrow (1+ numrow)
numcol 0
k0 0
)
(while (< k0 (sslength blksub)) ;while3
(setq blkss (ssdel (ssname blksub k0) blkss))
(setq k0 (1+ k0))
);end whlie3
;;;8.写入资料
(datacell numrow (setq numcol (1+ numcol)) blkname)
(datacell numrow (setq numcol (1+ numcol)) (rtos xscale))
(datacell numrow (setq numcol (1+ numcol)) (rtos yscale))
(datacell numrow (setq numcol (1+ numcol)) (rtos zscale))
(datacell numrow (setq numcol (1+ numcol)) (rtos (* 180 (/ rotang pi))))
(datacell numrow (setq numcol (1+ numcol)) (rtos (sslength blksub) 2 0))
);end while2
(setq blkdxf (tblnext "BLOCK"))
);END WHILE1 (endexcel)
(setq *error* oer)
(princ)
)

评分

参与人数 1明经币 +1 收起 理由
langjs + 1

查看全部评分

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2023-4-29 12:27:54 | 显示全部楼层
學習了,多謝分享!!
发表于 2012-2-13 11:49:44 | 显示全部楼层
什么书,很不错
发表于 2012-2-13 14:06:44 | 显示全部楼层
书名是什么????????
发表于 2012-2-14 00:47:04 | 显示全部楼层
搞了半天,还是这个最实用易懂,最简洁!
发表于 2012-2-14 01:02:20 | 显示全部楼层
确实不错的说
发表于 2012-2-14 19:39:18 | 显示全部楼层
学习了,多谢分享!!
发表于 2012-2-15 18:39:11 | 显示全部楼层
2005年就有了,但偶才看到,谢谢分享
发表于 2012-2-16 09:17:33 | 显示全部楼层
过来学习,版主辛苦了!
发表于 2012-2-16 10:51:47 | 显示全部楼层
学习了,多谢分享!!
发表于 2012-3-16 23:42:12 | 显示全部楼层
很好  我真好需要
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-16 16:38 , Processed in 0.191170 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表