[原创]cad图形写入SQL数据库实例
<p>Sub sc()<br/>Dim dwname, tymc As String<br/>Dim cn As New ADODB.Connection<br/>Dim rst As New ADODB.Recordset<br/>Dim poin As New ADODB.Recordset<br/>Dim tyl As New ADODB.Recordset<br/>Dim block As New ADODB.Recordset 'block表处理<br/>Dim klj, blj, lx, point, tylj, yhmm As String<br/>yhmm = ""<br/>Dim tysx As String<br/>Dim id, cadid, js, bh, dwsm, tyidh As Long<br/>Dim mytime As Date<br/>Dim mj As Double<br/>Dim dds, mm As Integer '图元计算<br/>dds = 0<br/>mm = 0<br/>Dim plzb As Variant '顶点坐标数组<br/>mytime = CDate(Date)<br/>Dim ob As AcadEntity<br/>For Each ob In ThisDrawing.ModelSpace<br/>If ob.layer = "图形单位名称" Then<br/> txmc = Trim$(ob.TextString)<br/> z = InStr(txmc, ";")<br/> tymc = Mid$(txmc, z + 1, (Len(txmc) - z))<br/> If Right$(tymc, 1) = "}" Then<br/> tymc = Mid$(tymc, 1, (Len(tymc) - 1))<br/> End If<br/> End If<br/>Next ob<br/>If tymc <> "" Then<br/>dwname = tymc<br/>point = "select * from point order by pointid desc"<br/>tylj = "select * from tylj where tyid in (select cadid from tysx where dwid in (select dwid from tyname where dwname=" & dwname & "))"<br/>blj = "select * from tysx where dwid in (select dwid from tyname where dwname= '" & dwname & "')"<br/>'klj = "provider=sqloledb.1;password=;persist security info=true;user id=sa;initial catalog=cad ;data source=huangbin" '库连接字符串<br/>klj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>cn.Open klj '连接数据库<br/>dwsm = 0<br/>rst.Open "select * from tyname order by dwid desc", cn, adOpenDynamic, adLockBatchOptimistic<br/>Do While Not rst.EOF<br/> dwsm = rst.Fields("dwid") '统计单位数目最大号<br/> GoTo 2<br/> 'rst.MoveNext<br/>Loop<br/>2: rst.Close<br/>rst.Open "select * from tyname where dwname='" & dwname & "'", cn, adOpenDynamic, adLockBatchOptimistic<br/>If rst.EOF Then<br/> mm = mm + 1<br/> cn.Execute "insert into tyname values(" & dwsm + 1 & ",'" & dwname & "','', " & mytime & ")"<br/> Else<br/> yhm = Trim(rst.Fields("sm"))<br/> If yhm = "" Then<br/> MsgBox "数据已经上传"<br/> End<br/> End If<br/>End If<br/>rst.Close<br/>Dim obj As AcadEntity<br/>Dim obj1 As AcadEntity<br/>Dim obj2 As AcadEntity<br/>Dim obj3 As AcadEntity<br/>Dim obj4 As AcadEntity<br/>Dim obj5 As AcadEntity 'text<br/>Dim obj6 As AcadEntity<br/>Dim obj7 As AcadEntity<br/>'rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic<br/>'----------以下删除库中多余的图元信息<br/>rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic<br/>kzsj obj, cn, dwname '将所有图元添加扩展数据<br/>findid dwname, cn<br/>cn.Execute "delete tylj from tylj where tyid not in (select cadid from tysx)"<br/>cn.Close<br/>'----------以上删除库中多余的图元信息<br/>For Each obj In ThisDrawing.ModelSpace<br/>cn.Open klj '<br/>Dim xtype As Variant<br/>Dim xdata As Variant<br/>obj.GetXData "", xtpye, xdata<br/>tyidh = xdata(4)</p><p>Set obj1 = obj<br/>Set obj2 = obj<br/>Set obj3 = obj<br/>Set obj4 = obj<br/>Set obj5 = obj<br/>Set obj6 = obj<br/>dds = dds + 1 '图元统计<br/>tysx = obj.ObjectName<br/>Dim i As Integer<br/> rst.Open "select * from tysx where cadid =" & tyidh & "", cn, adOpenStatic, adLockReadOnly<br/> If Not rst.EOF Then<br/> id = rst.Fields("cadid")<br/> cadid = rst.Fields("cadid")<br/> End If<br/> rst.Close<br/> rst.Open "select * from tysx", cn, adOpenDynamic, adLockBatchOptimistic<br/> If cadid = xdata(4) Then '图元修改<br/> cn.Execute "update tysx set time=" & mytime & " where cadid=" & tyidh & ""<br/> poin.Open point, cn, adOpenDynamic, adLockBatchOptimistic '打开point表连接<br/> Select Case tysx<br/> Case "AcDbPolyline": '是pl线时<br/> xgpline poin, rst, tylj, obj3, cn, xdata(4) '将值插入到tylj表中<br/> Case "AcDbLine": '是l线时<br/> xgli poin, rst, tylj, obj4, cn, xdata(4) '将值插入到point表中<br/> Case "AcDbMText"<br/> mytex poin, tylj, obj6, cn, xdata(4)<br/> Case "AcDbText"<br/> ytex poin, tylj, obj6, cn, xdata(4)<br/> Case "AcDbBlockReference" '块<br/> blockxg point, tylj, obj, cn, xdata(4)<br/> End Select<br/> Else '图元新增<br/> If mm = 1 Then<br/> If obj.ObjectName = "AcDbPolyline" Then<br/> If obj.Closed = "True" Then<br/> cn.Execute "insert into tysx values (" & tyidh & ", '" & tysx & "', " & mytime & "," & dwsm + 1 & ",'" & obj.layer & "',1,'" & obj.Linetype & "','" & obj.color & "')"<br/> Else<br/> cn.Execute "insert into tysx values (" & tyidh & ", '" & tysx & "', " & mytime & "," & dwsm + 1 & ",'" & obj.layer & "',0 ,'" & obj.Linetype & "','" & obj.color & "')"<br/> End If<br/> Else<br/> cn.Execute "insert into tysx values (" & tyidh & ", '" & tysx & "', " & mytime & "," & dwsm + 1 & ",'" & obj.layer & "',0 ,'" & obj.Linetype & "','" & obj.color & "')" '将图元信息插入tysx表中<br/> End If<br/> Else<br/> If obj.ObjectName = "AcDbPolyline" Then<br/> If obj.Closed = "True" Then<br/> cn.Execute "insert into tysx values (" & tyidh & ", '" & tysx & "', " & mytime & "," & dwsm & ",'" & obj.layer & "',1,'" & obj.Linetype & "','" & obj.color & "')"<br/> Else<br/> cn.Execute "insert into tysx values (" & tyidh & ", '" & tysx & "', " & mytime & "," & dwsm & ",'" & obj.layer & "',0 ,'" & obj.Linetype & "','" & obj.color & "')"<br/> End If<br/> Else<br/> cn.Execute "insert into tysx values (" & tyidh & ", '" & tysx & "', " & mytime & "," & dwsm & ",'" & obj.layer & "',0 ,'" & obj.Linetype & "')" '将图元信息插入tysx表中<br/> End If<br/> End If<br/> poin.Open point, cn, adOpenDynamic, adLockBatchOptimistic '打开point表连接<br/> Select Case tysx<br/> Case "AcDbPolyline": '是pl线时<br/> pline poin, tylj, obj2, cn, tyidh '将值插入到tylj表中<br/> Case "AcDbLine": '是l线时<br/> li poin, tylj, obj1, cn, tyidh '将值插入到point表中<br/> Case "AcDbMText" '新增text'<br/> mtex poin, tylj, obj5, cn, tyidh<br/> Case "AcDbText"<br/> tex poin, tylj, obj5, cn, tyidh<br/> Case "AcDbBlockReference" '块新增<br/> blockadd point, tylj, obj, cn, tyidh<br/> Case "AcDbPoint" '点<br/> pointad point, tylj, obj, cn, tyidh<br/> <br/> End Select<br/> <br/> End If<br/> rst.Close<br/> rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic</p><p><br/> cn.Close<br/>Next obj<br/>'MsgBox ("上传完毕")<br/>Else<br/>MsgBox ("没有单位名称")<br/>End<br/>End If<br/>cn.Open , klj<br/>cn.Execute "update tyname set sm='" & yhmm & "' where dwname like '%" & dwname & "%'"<br/>MsgBox ("数据上传完毕")<br/>cn.Close<br/>End<br/>End Sub<br/>Private Sub ytex(point, ty1, obj6 As AcadEntity, cn, tyidh) 'text修改<br/>Dim zb As Variant<br/>Dim dh, zjjd As Double<br/>dh = 0<br/>Dim ztgd As Double<br/>zjjd = obj6.Rotation<br/>ztgd = obj6.Height<br/>zb = obj6.InsertionPoint<br/>txmc = Trim$(obj6.TextString)<br/> z = InStr(txmc, ";")<br/> tymc = Mid$(txmc, z + 1, (Len(txmc) - z))<br/> If Right$(tymc, 1) = "}" Then<br/> tymc = Mid$(tymc, 1, (Len(tymc) - 1))<br/> End If<br/>cn.Execute "update point set x=" & zb(0) & ",y=" & zb(1) & " from point where pointid in (select pointid from tytext where cadid=" & tyidh & " )"<br/>cn.Execute "update tytext set nr='" & tymc & "',layer='" & obj6.layer & "',ztdx=" & ztgd & " ,zjjd= " & zjjd & "from tytext where cadid=" & tyidh & ""<br/>cn.Execute "update tysx set color='" & obj6.color & "' from tysx where cadid=" & tyidh & ""</p><p>End Sub<br/>Private Sub mytex(point, ty1, obj As AcadEntity, cn, tyidh) '多行文字修改<br/>Dim zb As Variant<br/>Dim dh, zjjd As Double<br/>Dim width As DataTypeEnum<br/>dh = 0<br/>Dim ztgd As Double<br/>width = obj.width<br/>zjjd = obj.Rotation<br/>ztgd = obj.Height<br/>zb = obj.InsertionPoint<br/>txmc = Trim$(obj.TextString)<br/> z = InStr(txmc, ";")<br/> tymc = Mid$(txmc, z + 1, (Len(txmc) - z))<br/> If Right$(tymc, 1) = "}" Then<br/> tymc = Mid$(tymc, 1, (Len(tymc) - 1))<br/> End If<br/>cn.Execute "update point set x=" & zb(0) & ",y=" & zb(1) & " from point where pointid in (select pointid from tytext where cadid=" & tyidh & " )"<br/>cn.Execute "update tytext set nr='" & tymc & "',layer='" & obj.layer & "',ztdx=" & ztgd & " ,zjjd= " & zjjd & " , width =" & width & " from tytext where cadid=" & tyidh & ""<br/>cn.Execute "update tysx set color='" & obj6.color & "' from tysx where cadid=" & tyidh & ""<br/>End Sub</p><p>Private Sub tex(point, ty1, obj5 As AcadEntity, cn, tyidh) 'text新增<br/>Dim ztgd, zjjd As Double<br/>Dim wjwidth As Double<br/>ztgd = obj5.Height<br/>Dim zb As Variant<br/>Dim dh, ydh As Double<br/>dh = 0<br/>Dim pt As New ADODB.Recordset<br/>pt.Open "select * from point order by pointid desc", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not pt.EOF Then<br/> dh = pt.Fields("pointid")<br/>End If '计算点总数<br/>pt.Close<br/>zb = obj5.InsertionPoint<br/>zjjd = obj5.Rotation<br/>txmc = Trim$(obj5.TextString)<br/> z = InStr(txmc, ";")<br/> tymc = Mid$(txmc, z + 1, (Len(txmc) - z))<br/> If Right$(tymc, 1) = "}" Then<br/> tymc = Mid$(tymc, 1, (Len(tymc) - 1))<br/> End If<br/> cn.Execute "insert into tylj values( " & tyidh & ",1," & dh + 1 & ")" '图元连接<br/>pt.Open "select *from point where x=" & zb(0) & " and y=" & zb(0) & " ", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not pt.EOF Then<br/> ydh = pt.Fields("pointid")<br/> cn.Execute "insert into tytext values(" & tyidh & ",'" & tymc & "','" & obj5.layer & "'," & ztgd & ",ydh, " & zjjd & ")" '角度<br/> Else<br/> cn.Execute "insert into tytext values(" & tyidh & ",'" & tymc & "','" & obj5.layer & "'," & ztgd & "," & dh + 1 & ", " & zjjd & " ,0)"<br/> cn.Execute "insert into point values( " & dh + 1 & ",'' ," & zb(0) & "," & zb(1) & ",'')"<br/>End If</p><p>End Sub<br/>Private Sub mtex(point, ty1, obj As AcadEntity, cn, tyidh) '多行文字新增<br/>Dim ztgd, zjjd As Double<br/>Dim wjwidth As Double<br/>ztgd = obj.Height<br/>Dim zb As Variant<br/>Dim dh, ydh As Double<br/>dh = 0<br/>Dim pt As New ADODB.Recordset<br/>pt.Open "select * from point order by pointid desc", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not pt.EOF Then<br/> dh = pt.Fields("pointid")<br/>End If '计算点总数<br/>pt.Close<br/>wjwidth = obj.width<br/>zb = obj.InsertionPoint<br/>zjjd = obj.Rotation<br/>txmc = Trim$(obj.TextString)<br/> z = InStr(txmc, ";")<br/> tymc = Mid$(txmc, z + 1, (Len(txmc) - z))<br/> If Right$(tymc, 1) = "}" Then<br/> tymc = Mid$(tymc, 1, (Len(tymc) - 1))<br/> End If<br/> cn.Execute "insert into tylj values( " & tyidh & ",1," & dh + 1 & ")" '图元连接<br/>pt.Open "select *from point where x=" & zb(0) & " and y=" & zb(0) & " ", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not pt.EOF Then<br/> ydh = pt.Fields("pointid")<br/> cn.Execute "insert into tytext values(" & tyidh & ",'" & tymc & "','" & obj.layer & "'," & ztgd & ",ydh, " & zjjd & "," & wjwidth & ")" '角度<br/> Else<br/> cn.Execute "insert into tytext values(" & tyidh & ",'" & tymc & "','" & obj.layer & "'," & ztgd & "," & dh + 1 & ", " & zjjd & " ," & wjwidth & ")"<br/> cn.Execute "insert into point values( " & dh + 1 & ",'' ," & zb(0) & "," & zb(1) & ",'')"<br/>End If</p><p>End Sub<br/>Private Sub xgpline(point, rst, ty1, obj3 As AcadEntity, cn, tyidh) '原有pl线处理过程<br/>Dim plzb As Variant '顶点坐标数组<br/>Dim ss, dh As Integer<br/>Dim js As Integer<br/>Dim sql As String<br/>js = 0<br/>dh = 1<br/>Dim xw As New ADODB.Recordset<br/>sql = "select qq=sum(pointid) from point where pointid in (select pointid from tylj where tyid =" & tyidh & ") "<br/>xw.Open sql, cn, adOpenDynamic, adLockBatchOptimistic<br/>Do While Not xw.EOF '判断数据库里点数<br/> js = xw.Fields("qq")<br/> GoTo 4<br/> 'xw.MoveNext<br/> Loop<br/>4: plzb = obj3.Coordinates<br/> ss = (UBound(plzb) + 1) / 2 '图形中本图元点数<br/> If js = ss Then<br/> Dim zb As Variant<br/> For i = 0 To ss - 1<br/> zb = obj3.Coordinate(i) '单个点坐标<br/> cn.Execute "update point set x=" & zb(0) & ",y=" & zb(1) & " from point where pointid in (select pointid from tylj where tyid=" & tyidh & " and xh=" & dh & ")"<br/> dh = dh + 1<br/> Next i<br/> End If<br/> point.Close<br/> End Sub<br/>Private Sub xgli(point, rst, tyl, obj4 As AcadEntity, cn, tyidh) '原有line线处理<br/>Dim i As Integer<br/>i = 0<br/>Dim pt1 As Variant<br/>Dim pt2 As Variant<br/>pt1 = obj4.StartPoint<br/>pt2 = obj4.EndPoint<br/>cn.Execute "update point set x=" & pt1(0) & ",y=" & pt1(1) & " from point where pointid in (select pointid from tylj where tyid=" & tyidh & " and xh=1)"<br/>cn.Execute "update point set x=" & pt2(0) & ",y=" & pt2(1) & " from point where pointid in (select pointid from tylj where tyid=" & tyidh & " and xh=2)"</p><p><br/>End Sub<br/>Private Sub blockxg(point, ty1, obj As AcadEntity, cn, tyidh) '原有块处理<br/>Dim zb As Variant<br/>Dim x, y, z As Integer<br/>Dim jd As Double<br/>Dim blockname As String<br/>x = obj.XScaleFactor<br/>y = obj.YScaleFactor<br/>z = obj.Zsxalefactor<br/>zb = obj.InsertionPoint<br/>jd = obj.Rotation * 57.28970065<br/>blockname = obj.name<br/>cn.Execute "update point set x=" & zb(0) & ",y=" & zb(1) & " from point where pointid in (select pointid from tylj where tyid=" & tyidh & ")"<br/>cn.Execute "update block set xs=" & x & " ,yx= " & y & ", zs=" & z & " ,jd=" & jd & " from block where cadid=" & tyidh & ""<br/>End Sub<br/>Private Sub blockadd(point, ty1, obj As AcadEntity, cn, tyidh) '新增块处理<br/>Dim block As New ADODB.Recordset<br/>Dim zb As Variant<br/>Dim dh, x, y, z As Integer<br/>Dim crjd As Double '插入角度<br/>x = obj.XScaleFactor<br/>y = obj.YScaleFactor<br/>z = obj.ZScaleFactor<br/>zb = obj.InsertionPoint<br/>crjd = obj.Rotation * 57.29578049</p><p>l = 1<br/>blockname = obj.name<br/>block.Open "select pointid from point order by pointid desc", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not block.EOF Then<br/>dh = block.Fields("pointid")<br/>Else<br/>dh = 0<br/>End If<br/>cn.Execute "insert into tylj values( " & tyidh & ",1," & dh + 1 & ")" '图元连接<br/>cn.Execute "insert into point values( " & dh + 1 & ",'' ," & zb(0) & "," & zb(1) & ",'')" '点表<br/>cn.Execute "insert into block values(" & tyidh & " ,'" & blockname & " '," & x & "," & y & ", " & z & " ," & crjd & "," & dh + 1 & ") " '块属性。</p><p><br/>End Sub<br/>Private Sub pointad(point, ty, obj As AcadEntity, cn, tyidh) '新增点的处理<br/>Dim zb As Variant<br/>Dim po As New ADODB.Recordset<br/>po.Open "select * from point order by pointid desc", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not po.EOF Then<br/> dh = po.Fields("pointid")<br/> Else<br/> dh = 0<br/> End If<br/> po.Close<br/> <br/>zb = obj.Coordinates<br/>cn.Execute "insert into tylj values( " & tyidh & ",1," & dh + 1 & ")" '图元连接<br/>cn.Execute "insert into point values( " & dh + 1 & ",'' ," & zb(0) & "," & zb(1) & ",'')" '点表<br/>End Sub<br/>Private Sub pline(point, tyl, obj2 As AcadEntity, cn, tyidh) '新建pl线处理过程<br/>Dim mx As New ADODB.Recordset<br/> Dim plzb As Variant '顶点坐标数组<br/> Dim ss, dh As Integer<br/> dh = 0<br/> Do While Not point.EOF<br/> 'dh = dh + 1<br/> dh = point.Fields("pointid")<br/> GoTo l<br/> Loop<br/>l: plzb = obj2.Coordinates<br/> ss = (UBound(plzb) + 1) / 2<br/> Dim zb As Variant<br/> For i = 0 To ss - 1<br/> zb = obj2.Coordinate(i) '单个点坐标<br/> mx.Open "select * from point where x=" & zb(0) & " and y=" & zb(1) & "", cn, adOpenDynamic, adLockBatchOptimistic<br/> If Not mx.EOF Then<br/> cn.Execute "insert into tylj values( " & tyidh & "," & i + 1 & "," & mx.Fields("pointid") & ")"<br/> Else<br/> cn.Execute "insert into tylj values( " & tyidh & "," & i + 1 & "," & dh + 1 & ")"<br/> cn.Execute "insert into point values( " & dh + 1 & ",'' ," & zb(0) & "," & zb(1) & ",'')"<br/> dh = dh + 1<br/> End If<br/> mx.Close<br/> Next i<br/> point.Close<br/>End Sub<br/>Private Sub li(poin, tyl, obj1 As AcadEntity, cn, tyidh) '新建line线处理<br/>Dim mx As New ADODB.Recordset<br/>Dim i, j, s As Integer<br/>i = 0<br/>Dim pt1 As Variant<br/>Dim pt2 As Variant<br/>pt1 = obj1.StartPoint<br/>pt2 = obj1.EndPoint<br/>Do While Not poin.EOF<br/>i = poin.Fields("pointid")<br/> 'i = i + 1<br/> GoTo q<br/> 'poin.MoveNext<br/> Loop '计算点数<br/>q: mx.Open "select * from point where x=" & pt1(0) & " and y=" & pt1(1) & "", cn, adOpenDynamic, adLockBatchOptimistic<br/> If Not mx.EOF Then<br/> cn.Execute "insert into tylj values( " & tyidh & ",1," & mx.Fields("pointid") & ")"<br/> Else<br/> cn.Execute "insert into point values( " & i + 1 & ",'' ," & pt1(0) & "," & pt1(1) & ",'')"<br/> cn.Execute "insert into tylj values( " & tyidh & ",1," & i + 1 & ")"<br/> End If<br/> mx.Close<br/> i = i + 1<br/> mx.Open "select * from point where x=" & pt2(0) & " and y=" & pt2(1) & "", cn, adOpenDynamic, adLockBatchOptimistic<br/> If Not mx.EOF Then<br/> cn.Execute "insert into tylj values(" & tyidh & ",2," & mx.Fields("pointid") & ")"<br/> Else<br/> cn.Execute "insert into point values( " & i + 1 & ",'' ," & pt2(0) & "," & pt2(1) & ",'')"<br/> cn.Execute "insert into tylj values( " & tyidh & ",2," & i + 1 & ")"<br/> End If<br/> poin.Close<br/> 'tyl.Close</p><p>End Sub<br/>Private Sub kzsj(obj As AcadEntity, cn, dwname) '加扩展数据<br/>wj = "d:\b.txt"<br/>Open wj For Append As #1<br/>Dim sjk As New ADODB.Recordset<br/>Dim id As Long<br/>id = 0<br/>sjk.Open "select * from tysx order by cadid desc ", cn, adOpenDynamic, adLockReadOnly<br/>Do While Not sjk.EOF<br/> id = sjk.Fields("cadid")<br/> GoTo w<br/> 'sjk.MoveNext<br/>Loop<br/>w: sjk.Close<br/>For Each obj In ThisDrawing.ModelSpace<br/>Dim xtype As Variant<br/>Dim xdata As Variant<br/>obj.GetXData "", xtpye, xdata<br/>If VarType(xdata) = 0 Then '判断是否有扩展数据。<br/>Dim datatype(0 To 7) As Integer<br/>Dim data(0 To 7) As Variant<br/>datatype(0) = 1001: data(0) = "tete"<br/>datatype(1) = 1000: data(1) = dwname<br/>datatype(2) = 1003: data(2) = "0"<br/>datatype(3) = 1040: data(3) = 1.232<br/>datatype(4) = 1041: data(4) = id + 1<br/>datatype(5) = 1070: data(5) = 5656<br/>datatype(6) = 1071: data(6) = 32332<br/>datatype(7) = 1042: data(7) = 10<br/>obj.SetXData datatype, data<br/>ThisDrawing.Application.Update<br/>id = id + 1<br/>Write #1, data(4)<br/>End If<br/>Next obj<br/>Close #1<br/>End Sub<br/>Private Function dqkzsj(obj As AcadEntity) '读取扩展数据<br/>Dim id As Long<br/>Dim xtype As Variant<br/>Dim xdata As Variant<br/>obj.GetXData "", xtpye, xdata<br/>id = tyidh<br/>End Function</p><p>'图形中删除图元时库中也删除。<br/>Private Sub findid(dwname, cn)<br/>Dim js As Integer<br/>Dim id As Long<br/>Dim rst1 As New ADODB.Recordset<br/>rst1.Open "select * from tysx where dwid in (select dwid from tyname where dwname='" & dwname & "')", cn, adOpenDynamic, adLockBatchOptimistic</p><p> Do While Not rst1.EOF<br/> js = 0<br/> id = rst1.Fields("cadid")<br/> For Each obj In ThisDrawing.ModelSpace<br/> Dim xtype As Variant<br/> Dim xdata As Variant<br/> obj.GetXData "", xtpye, xdata<br/> If id = xdata(4) Then<br/> js = js + 1<br/> End If<br/> 'cn.Execute "delete tytable where id= " & obj.ObjectID & ""<br/> Next obj<br/> If js = 0 Then<br/> cn.Execute "delete tysx where cadid=" & rst1.Fields("cadid") & ""<br/> End If<br/> rst1.MoveNext<br/> Loop<br/>rst1.Close<br/> <br/> <br/>End Sub</p><p></p> 好的,学习学习。 <p>不足的地方请指出</p> <p>谢谢你分享!</p> <p>多谢您提供的宝贵代码!</p> <p>大家互相学习吗?</p><p></p> <p>程序还简洁,但数据库表太多,也不利于以后读取数据库信息再作图,实现网络协同。用一个表写入所有平面图形几何信息那就好了。 </p> <p>写到同一个表里,数据太混乱了.读取信息在作图的模块我已经写好了,感觉在图形数据很大的时候运行速度比较吗,正在想办法改进.还请高手们多多执教</p> <p>我论文的一部分正是在做这东西 , 我思路是把二维图形信息入库,建了三个表,一个用于作图时读取数据用的,一个总表,是对所进行操作和所操作图形信息查询用的, 还有一个就是删除图形的表(避免画出重复的图)。 我可能是机子配置所限,在一次录入大量复杂图形信息时比较慢(例如一次录入很多复杂多段线)。在读取大量信息画图是还算快。</p><p> 写在同一表不混乱,且避免重复建表的麻烦。使数据库维护和查询更方便。</p> <p>谢谢楼上的朋友,我去试试将数据写在一个表里。不过感觉有点混乱了。</p>
页:
[1]
2