14.2 创建数据表(VBA二次开发教程)
<P><FONT face=宋体 size=2>按照14.2创建数据表的要求做了一个3DSolid,一个line </FONT></P><P><FONT size=1></FONT></P>
<P><FONT size=1>碰到的问题是在 3Dsolid 在加入到VBASample.mdb数据库中,从debug.print 得到了3DSolid的ID号是2129993344,但ID号就是不能添加到数据库中.</FONT></P>
<P><FONT size=1></FONT> </P>
<P><FONT size=1>第339页的程序摘录</FONT></P>
<P><FONT size=1>For Each obj In ThisDrawing.ModelSpace<BR> Debug.Print obj.ObjectName<BR> Debug.Print obj.ObjectID<BR> Select Case obj.ObjectName<BR> Case "AcDbLine":<BR> rst.Open "SELECT id FROM line", cn, adOpenForwardOnly, adLockReadOnly, adCmdText<BR> pt1 = obj.StartPoint<BR> pt2 = obj.EndPoint<BR> <BR> If Not FindObj(rst, obj.ObjectID) Then ' 新建的直线的处理<BR> cmd.CommandText = "INSERT INTO line(id,X1,Y1,X2,Y2) VALUES(" & _<BR> "'" & obj.ObjectID & "'," & pt1(0) & "," & pt1(1) & "," & pt2(0) & "," & pt2(1) & ");"<BR> Else ' 修改的直线的处理<BR> cmd.CommandText = "UPDATE line SET X1=" & pt1(0) & ",Y1=" & pt1(1) & ",X2=" & _<BR> pt2(0) & ",Y2=" & pt2(1) & " WHERE id='" & obj.ObjectID & "';"<BR> End If<BR> <BR> cmd.Execute<BR> rst.Close<BR> Case "AcDbCircle":<BR> rst.Open "SELECT id FROM circle", cn, adOpenForwardOnly, adLockReadOnly, adCmdText<BR> pt1 = obj.Center<BR> <BR> If Not FindObj(rst, obj.ObjectID) Then<BR> cmd.CommandText = "INSERT INTO circle(id,CenX,CenY,Rad) VALUES(" & _<BR> "'" & obj.ObjectID & "'," & pt1(0) & "," & pt1(1) & "," & obj.Radius & ");"<BR> Else<BR> cmd.CommandText = "UPDATE circle SET CenX=" & pt1(0) & ",CenY=" & pt1(1) & _<BR> ",Rad=" & obj.Radius & " WHERE id='" & obj.ObjectID & "';"<BR> End If<BR> <BR> cmd.Execute<BR> rst.Close<BR>'将原程序的arc改为<BR> Case "AcDb3DSOLID":<BR> rst.Open "SELECT id FROM 3DSOLID", cn, adOpenForwardOnly, adLockReadOnly, adCmdText<BR> pt1 = obj.Center<BR> <BR> If Not FindObj(rst, obj.ObjectID) Then<BR> cmd.CommandText = "INSERT INTO 3DSOLID(id,CenX,CenY,Rad,StartAng,EndAng) VALUES(" & _<BR> "'" & obj.ObjectID & "'," & pt1(0) & "," & pt1(1) & "," & obj.Radius & "," & _<BR> obj.StartAngle & "," & obj.EndAngle & ");"<BR> Else<BR> cmd.CommandText = "UPDATE 3DSOLID SET CenX=" & pt1(0) & ",CenY=" & pt1(1) & _<BR> ",Rad=" & obj.Radius & ",StartAng=" & obj.StartAngle & ",EndAng=" & _<BR> obj.EndAngle & " WHERE id='" & obj.ObjectID & "';"<BR> End If<BR> <BR> cmd.Execute<BR> rst.Close<BR> End Select<BR> Next obj</FONT></P>
<P> Debug.Print obj.ObjectName<BR> Debug.Print obj.ObjectID<BR>打印结果<BR>AcDb3dSolid ----- 3dsolid <BR> 2129993344 <BR>AcDbLine ---------- line<BR> 2129993352 </P>
<P>-----------------------------<BR>"3DSOLID"的特性表为 <BR>((-1 . <图元名: 7ef51e80>) (0 . "3DSOLID") (330 . <图元名: 7ef51cf8>) (5 . <BR>"88") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 . <BR>"AcDbModelerGeometry") (70 . 1) (1 . "mogoo kk m o ") <BR></P>
<P>求教</P>
<P>这段程序如何改,理由是什么?<BR>同理,还有插入的块程序如何写,理由是什么?</P> <P>这段代码的作用是将图元的信息登记到数据库中。</P>
<P>首先按图元的类型,如直线、圆等,分别获取图元的信息,如直线,取起点和终点,圆,取圆心和半径,然后判断数据库中是否存在该图元的记录,如果存在,则更新,不存在,则插入一条新的记录。</P>
<P>对于插入的块,类型是AcDbBlockReference,可以记录的是插入点、块名、比例、旋转角度等信息。</P>
页:
[1]