[求助] 求矩形的参数
小弟初学AUTOCAD 的VBA,现在想读取AutoCAD的图形信息保存到Access的数据库中,但是不知道矩形的输入参数是否就是对角线两点的坐标?其语句应该怎么写呢?<br/>例如,直线的输入格式为:insert into line(id,x1,y1,x2,y2) values('××××',×××,×××,×××,×××)<br/> 圆形的输入格式为:insert into circle(id,cenx,ceny,rad) values('××××',×××,×××,×××)<br/><br/>请问矩形应该如何输入呢?<br/><br/>请老师们不吝赐教<br/> 将文件保存成DXF后,用文本格式打开查看后,我认为矩形、三角形等并没有自身的格式,其格式实际上是聚合线,所以应按聚合线格式输入。 <br/> <p>直线有StartPoint和EndPoint属性,它是三元素数组,取0和1则为X和Y坐标值。</p><p>圆也有同样道理的属性,你可以参照对象模型。</p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;">通过对角两点绘制矩形的函数</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Function AddRectangle(varPnt1 As Variant, varPnt2 As Variant) As AcadLWPolyline</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">On Error GoTo Err_Control</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim objSpace As AcadBlock</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">If ThisDrawing.ActiveSpace = acModelSpace Then</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set objSpace = ThisDrawing.ModelSpace</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Else</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set objSpace = ThisDrawing.PaperSpace</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">End If</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim plineObj As AcadLWPolyline</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim points(0 To 7) As Double</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">points(0) = varPnt1(0): points(1) = varPnt1(1)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">points(2) = varPnt1(0): points(3) = varPnt2(1)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">points(4) = varPnt2(0): points(5) = varPnt2(1)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">points(6) = varPnt2(0): points(7) = varPnt1(1)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set plineObj = objSpace.AddLightWeightPolyline(points)</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">plineObj.Closed = True</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set AddRectangle = plineObj</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Exit_Here:</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Exit Function</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Err_Control:</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Resume Exit_Here</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">End Function</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Sub addrec()</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim pnt1 As Variant</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim pnt2 As Variant</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">pnt1 = ThisDrawing.Utility.GetPoint(, "</font>请输入角点:<font face="Times New Roman">")</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">pnt2 = ThisDrawing.Utility.GetCorner(pnt1, "</font>请输入另一角点:<font face="Times New Roman">")</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">AddRectangle pnt1, pnt2</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">End Sub</font></p> jingqin0472发表于2008-12-29 18:26:00static/image/common/back.gif通过对角两点绘制矩形的函数Function AddRectangle(varPnt1 As Variant, varPnt2 As Variant) As AcadLWPolyline On Error GoTo Err_Control Dim objSpace As AcadBlock<p>基本都是根据这个原理</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">pnt1 = ThisDrawing.Utility.GetPoint(, "</font>请输入角点:<font face="Times New Roman">")</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">pnt2 = ThisDrawing.Utility.GetCorner(pnt1, "</font>请输入另一角点:<font face="Times New Roman">")</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">计算出4个点坐标,别无它法。</font></p>
页:
[1]