naughtypack 发表于 2008-7-4 15:22:00

怎么实现让cad自动读excel数据画图

<p>每次都做这样的重复性的工作:比如</p><p>&nbsp;&nbsp;&nbsp; x&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y</p><p>&nbsp;12811.688,36918.762<br/>12814.688,36921.630<br/>12830.933,36910.515<br/>12833.933,36909.414<br/>12833.933,36909.706<br/>12836.933,36912.807<br/>12853.028,36898.523<br/>12856.028,36897.613<br/>12856.028,36897.789<br/>12859.028,36900.543<br/>12875.735,36893.257<br/>12878.735,36891.911<br/>12878.735,36891.935<br/>12881.735,36895.341<br/>12899.108,36887.486<br/>12902.108,36886.197<br/>12902.108,36885.334<br/>12905.108,36888.383<br/>把他复制到cad里面自动连线画图</p><p>有没有什么方法让其自动读数,画线呢,请高手指教啊</p>

wylong 发表于 2008-7-4 17:16:00

<p>你的这个不用通过编程解决,可以借助使用绘制多段线的方法快速绘出曲线。</p><p>&nbsp;</p><p>步骤1、选出所需画线的点的坐标值,如上图中B列数据,将其复制到剪贴板上,</p><p>步骤2、打开 AutoCAD,在命令行键入“pline”&nbsp;(画多段线线命令),出现提示:“指定起点:”,再在此位置处点击鼠标右键,弹出菜单,在菜单中选“粘贴”命令,这样在Excel中的坐标值就传送到了AutoCAD中,并自动连接成曲线,单击鼠标右键,取消继续画线状态,曲线就画好了。</p>

nhy12345678 发表于 2008-7-4 23:33:00

<p>其实简单,在CAD文件的同一目录存放EXCEL表格文件,本程序文件名为:data.xls&nbsp; 电子表格的第一个格子放X坐标,第二个格子放Y坐标,在下一行就放另外一个断点的坐标:如下所示</p><p><table cellspacing="0" cellpadding="0" width="144" border="0" style="WIDTH: 108pt; BORDER-COLLAPSE: collapse;"><colgroup><col span="2" width="72" style="WIDTH: 54pt;"></col></colgroup><tbody><tr height="19" style="HEIGHT: 14.25pt;"><td align="right" width="72" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 54pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;"><font face="宋体">0</font></td><td align="right" width="72" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 54pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent;"><font face="宋体">0</font></td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td align="right" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;"><font face="宋体">10</font></td><td align="right" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent;"><font face="宋体">10</font></td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td align="right" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;"><font face="宋体">15</font></td><td align="right" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent;"><font face="宋体">35</font></td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td align="right" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;"><font face="宋体">48</font></td><td align="right" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent;"><font face="宋体">69</font></td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td align="right" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;"><font face="宋体">79</font></td><td align="right" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent;"><font face="宋体">62</font></td></tr><tr height="19" style="HEIGHT: 14.25pt;"><td align="right" height="19" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent;"><font face="宋体">48</font></td><td align="right" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent;"><font face="宋体">97</font></td></tr></tbody></table></p><p>以下为代码部分:</p><p>Sub excelspl()<br/>Dim plineObj As AcadLWPolyline<br/>Dim attrtxt0 As String<br/>Dim attrtxt1 As String<br/>Dim corow As Long<br/>Dim p<br/>Set excelapp = CreateObject("excel.application")&nbsp; '激活excel程序<br/>excelapp.Workbooks.Open (ThisDrawing.path &amp; "/data.xls") '打开工作薄,同CAD文件一个目录ThisDrawing.path <br/>Set excelsheet = excelapp.ActiveWorkbook.Sheets("sheet1") '当前工作表为sheet1<br/>corow = excelsheet.UsedRange.Rows.Count '计算工作表的总行数<br/>ReDim p(0 To (corow * 2 - 1)) As Double '定义点坐标<br/>For i = 1 To corow<br/>&nbsp; attrtxt0 = excelsheet.Cells(i, 1).Value&nbsp; 'X坐标<br/>&nbsp; attrtxt1 = excelsheet.Cells(i, 2).Value&nbsp; 'Y坐标<br/>&nbsp; p((i - 1) * 2) = Val(attrtxt0)<br/>&nbsp; p((i - 1) * 2 + 1) = Val(attrtxt1)<br/>Next i<br/>Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(p) '画多义线<br/>End Sub</p><p>本代码测试通过!</p><p></p>

rongyifei 发表于 2008-7-5 16:40:00

学习了!

mtldsw 发表于 2008-12-30 12:23:00

弱弱的问,这个程序怎么使用?

rural_cat 发表于 2009-1-13 16:02:00

谢谢,学习了!

albert118 发表于 2009-1-23 11:07:00

<p>谢谢</p><p></p><p></p><p></p>

yangw761 发表于 2010-4-7 21:47:00

想问下高手,要是有很多行很多列的三维坐标点该如何处理啊?

helloworld87 发表于 2010-4-15 17:41:00

vba吧,应该是的。。

xiaowen 发表于 2010-6-9 16:27:00

多谢分享,学习一下.
页: [1] 2
查看完整版本: 怎么实现让cad自动读excel数据画图