明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1618|回复: 1

14.2 创建数据表(VBA二次开发教程)

[复制链接]
发表于 2006-7-11 16:40:00 | 显示全部楼层 |阅读模式

按照14.2创建数据表的要求做了一个3DSolid,一个line

碰到的问题是在 3Dsolid 在加入到VBASample.mdb数据库中,从debug.print 得到了3DSolid的ID号是2129993344,但ID号就是不能添加到数据库中.

 

第339页的程序摘录

For Each obj In ThisDrawing.ModelSpace
        Debug.Print obj.ObjectName
        Debug.Print obj.ObjectID
        Select Case obj.ObjectName
            Case "AcDbLine":
                rst.Open "SELECT id FROM line", cn, adOpenForwardOnly, adLockReadOnly, adCmdText
                pt1 = obj.StartPoint
                pt2 = obj.EndPoint
               
                If Not FindObj(rst, obj.ObjectID) Then      ' 新建的直线的处理
                    cmd.CommandText = "INSERT INTO line(id,X1,Y1,X2,Y2) VALUES(" & _
                        "'" & obj.ObjectID & "'," & pt1(0) & "," & pt1(1) & "," & pt2(0) & "," & pt2(1) & ");"
                Else                                        ' 修改的直线的处理
                    cmd.CommandText = "UPDATE line SET X1=" & pt1(0) & ",Y1=" & pt1(1) & ",X2=" & _
                        pt2(0) & ",Y2=" & pt2(1) & " WHERE id='" & obj.ObjectID & "';"
                End If
               
                cmd.Execute
                rst.Close
            Case "AcDbCircle":
                rst.Open "SELECT id FROM circle", cn, adOpenForwardOnly, adLockReadOnly, adCmdText
                pt1 = obj.Center
               
                If Not FindObj(rst, obj.ObjectID) Then
                    cmd.CommandText = "INSERT INTO circle(id,CenX,CenY,Rad) VALUES(" & _
                        "'" & obj.ObjectID & "'," & pt1(0) & "," & pt1(1) & "," & obj.Radius & ");"
                Else
                    cmd.CommandText = "UPDATE circle SET CenX=" & pt1(0) & ",CenY=" & pt1(1) & _
                        ",Rad=" & obj.Radius & " WHERE id='" & obj.ObjectID & "';"
                End If
               
                cmd.Execute
                rst.Close
'将原程序的arc改为
            Case "AcDb3DSOLID":
                rst.Open "SELECT id FROM 3DSOLID", cn, adOpenForwardOnly, adLockReadOnly, adCmdText
                pt1 = obj.Center
               
                If Not FindObj(rst, obj.ObjectID) Then
                    cmd.CommandText = "INSERT INTO 3DSOLID(id,CenX,CenY,Rad,StartAng,EndAng) VALUES(" & _
                        "'" & obj.ObjectID & "'," & pt1(0) & "," & pt1(1) & "," & obj.Radius & "," & _
                        obj.StartAngle & "," & obj.EndAngle & ");"
                Else
                    cmd.CommandText = "UPDATE 3DSOLID SET CenX=" & pt1(0) & ",CenY=" & pt1(1) & _
                        ",Rad=" & obj.Radius & ",StartAng=" & obj.StartAngle & ",EndAng=" & _
                        obj.EndAngle & " WHERE id='" & obj.ObjectID & "';"
                End If
               
                cmd.Execute
                rst.Close
        End Select
    Next obj

        Debug.Print obj.ObjectName
        Debug.Print obj.ObjectID
打印结果
AcDb3dSolid ----- 3dsolid
 2129993344
AcDbLine ---------- line
 2129993352

-----------------------------
"3DSOLID"的特性表为
((-1 . <图元名: 7ef51e80>) (0 . "3DSOLID") (330 . <图元名: 7ef51cf8>) (5 .
"88") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "0") (100 .
"AcDbModelerGeometry") (70 . 1) (1 . "mogoo kk m o          ")

求教

这段程序如何改,理由是什么?
同理,还有插入的块程序如何写,理由是什么?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2006-7-16 23:00:00 | 显示全部楼层

这段代码的作用是将图元的信息登记到数据库中。

首先按图元的类型,如直线、圆等,分别获取图元的信息,如直线,取起点和终点,圆,取圆心和半径,然后判断数据库中是否存在该图元的记录,如果存在,则更新,不存在,则插入一条新的记录。

对于插入的块,类型是AcDbBlockReference,可以记录的是插入点、块名、比例、旋转角度等信息。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-27 00:21 , Processed in 0.168131 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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