[原创]从SQL数据库中提取数据生成CAD图形
<p>Sub xz(dww)<br/>Dim sjk As New ADODB.Connection<br/>Dim dw As New ADODB.Recordset<br/>Dim text As New ADODB.Recordset<br/>Dim ty As New ADODB.Recordset<br/>Dim tyname As New Recordset<br/>Dim tylj As New ADODB.Recordset<br/>Dim point As New ADODB.Recordset<br/>Dim pointtext As New ADODB.Recordset<br/>Dim sjklj, dwname, dwlj, yhm, tc, tc1, bh, tyxx As String<br/>yhm = "002"<br/>Dim x, y As Double<br/>Dim tylx As String<br/>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj '打开库连接<br/>'dwname = InputBox("请输入单位名称")<br/>dwzfcd = Len(dww)<br/>dwname = Trim(dww)<br/>dwlj = "select * from tyname where dwname = '" & dwname & "'"<br/>tyname.Open dwlj, sjk, adOpenDynamic, adLockBatchOptimistic<br/>If tyname.EOF Then<br/> MsgBox ("库中无此单位信息")<br/> End<br/> Else<br/> If tyname.Fields("sm") = "002" Then<br/> MsgBox ("本图形已经有用户使用")<br/> End<br/> Else<br/>ty.Open "select * from tysx where dwid in (select dwid from tyname where dwname like '%" & dwname & "%'and sm<>'002' )", sjk, adOpenDynamic, adLockBatchOptimistic<br/>Dim w As Double<br/>w = 1<br/>Do While Not ty.EOF<br/>tyxx = ty.Fields("linetype") '线性<br/>tjxx (tyxx)<br/>tylx = ty.Fields("tylx") '图元类型<br/>bh = ty.Fields("is")<br/>tc = ty.Fields("larer") '图层<br/> If tylx = "AcDbMText" Or tylx = "AcDbText" Then<br/> te ty.Fields("cadid"), ty.Fields("larer"), sjk '注记<br/> End If<br/> tylj.Open "select * from tylj where tyid=" & ty.Fields("cadid") & " order by xh asc", sjk, adOpenDynamic, adLockBatchOptimistic<br/> Do While Not tylj.EOF<br/> point.Open "select *from point where pointid=" & tylj.Fields("pointid") & " ", sjk, adOpenDynamic, adLockBatchOptimistic<br/> Select Case tylx<br/> 'Case "AcDbMText" Or "AcDbText"<br/> 'te ty.Fields("cadid"), ty.Fields("larer"), sjk '注记<br/> Case "AcDbPolyline" '是多段线时<br/> 'Dim ewlayer As AcadLayer<br/> 'Set ewlayer = ThisDrawing.Layers.Add(tc)<br/> 'ThisDrawing.ActiveLayer = ewlayer<br/> ThisDrawing.SendCommand "_pline" & vbCr<br/> x = point.Fields("x")<br/> y = point.Fields("y")<br/> ThisDrawing.SendCommand x & "," & y & vbCr<br/> Case "AcDbLine" '是line线时<br/> 'Dim wlayer As AcadLayer<br/> 'Set wlayer = ThisDrawing.Layers.Add(tc)<br/> 'ThisDrawing.ActiveLayer = wlayer<br/> ThisDrawing.SendCommand "_line" & vbCr<br/> x = point.Fields("x")<br/> y = point.Fields("y")<br/> ThisDrawing.SendCommand x & "," & y & vbCr<br/> Case "AcDbBlockReference"<br/> block point, sjk<br/> <br/> End Select<br/> tylj.MoveNext<br/> point.Close<br/> Loop<br/> If tylx = "AcDbPolyline" Then<br/> If bh = "1" Then<br/> ThisDrawing.SendCommand "c" & vbCr<br/> Else<br/> ThisDrawing.SendCommand "" & vbCr<br/> End If<br/> Else<br/> If tylx = "AcDbLine" Then<br/> ThisDrawing.SendCommand "" & vbCr<br/> End If<br/> End If<br/> Dim xzj As AcadSelectionSet<br/> ' If Not IsNull(ThisDrawing.SelectionSets.Item("s1")) Then<br/> 'Set xzj = ThisDrawing.SelectionSets.Item("s1")<br/> 'xzj.Delete<br/> 'End If<br/> ' Set xzj = ThisDrawing.SelectionSets.Add("s1")<br/> ' xzj.Select acSelectionSetLast<br/> ' Dim lr As AcadEntity<br/> ' For Each lr In xzj<br/> <br/> 'lr = xzj.Item(1)<br/> 'lr.layer = tc<br/> 'Next lr<br/>tjkzsj ty.Fields("cadid"), dwname, tc<br/> tylj.Close<br/>ty.MoveNext<br/>Loop<br/>ty.Close<br/>End If<br/>End If<br/>sjk.Execute "update tyname set sm='" & yhm & "' where dwname like '%" & dwname & "%'"<br/>MsgBox ("数据下载完毕")<br/>sjk.Close<br/>End<br/>End Sub<br/>Private Sub block(point, cn) '插入块<br/>Dim blockobject As AcadBlock<br/>Dim ljj As New ADODB.Recordset<br/>Dim blockname As String<br/>Dim zb(0 To 2) As Variant<br/>ljj.Open "select * from block where cadid in (select tyid from tylj where pointid= " & point.Fields("pointid") & ")", cn, adOpenDynamic, adLockBatchOptimistic<br/>If Not ljj.EOF Then<br/>blockname = ljj.Fields("name")<br/>zb(0) = point.Fields("x")<br/>zb(1) = point.Fields("Y")<br/>zb(2) = 0<br/>'Set bolckobject = ThisDrawing.ModelSpace.InsertBlock(zb, blockname, 1, 1, 1, 0)<br/>'ThisDrawing.ModelSpace.InsertBlock zb, blockname, ljj.Fields("xs"), ljj.Fields("ys"), ljj.Fields("zs"), 1<br/> 'ThisDrawing.SendCommand "-insert" & vbCr<br/> ThisDrawing.SendCommand "-insert" & vbCr & blockname & vbCr & point.Fields("x") & "," & point.Fields("y") & vbCr & ljj.Fields("xs") & vbCr & ljj.Fields("ys") & vbCr & ljj.Fields("zs") & vbCr & ljj.Fields("jd") & vbCr<br/> 'ThisDrawing.SendCommand blockname & vbCr<br/> 'ThisDrawing.SendCommand point.Fields("y") & "," & point.Fields("x") & vbCr<br/> 'ThisDrawing.SendCommand ljj.Fields("xs") & vbCr<br/> ' ThisDrawing.SendCommand ljj.Fields("ys") & vbCr<br/> ' ThisDrawing.SendCommand ljj.Fields("zs") & vbCr<br/> 'ThisDrawing.SendCommand 0 & vbCr<br/> 'ThisDrawing.SendCommand "" & vbCr<br/> <br/>End If<br/>ljj.Close<br/>End Sub<br/>Private Sub te(cadid, tc, sjk) '下载注记<br/>Dim jdzh As Double</p><p> Dim newlayer As AcadLayer<br/> Set newlayer = ThisDrawing.Layers.Add(tc)<br/> ThisDrawing.ActiveLayer = newlayer<br/> Dim text As New ADODB.Recordset<br/> Dim pointtext As New ADODB.Recordset<br/> text.Open "select * from tytext where cadid=" & cadid & "", sjk, adOpenDynamic, adLockBatchOptimistic<br/> pointtext.Open "select *from point where pointid in (select pointid from tytext where cadid=" & cadid & ")", sjk, adOpenDynamic, adLockBatchOptimistic<br/> jdzh = text.Fields("zjjd") / 0.017453292 '注记角度<br/> ThisDrawing.SendCommand "_text" & vbCr<br/> ThisDrawing.SendCommand pointtext.Fields("x") & "," & pointtext.Fields("y") & vbCr<br/> ThisDrawing.SendCommand text.Fields("ztdx") & vbCr<br/> ThisDrawing.SendCommand jdzh & vbCr<br/> ThisDrawing.SendCommand text.Fields("nr") & vbCr<br/> ThisDrawing.SendCommand "" & vbCr<br/> text.Close<br/> pointtext.Close</p><p>End Sub<br/>Private Sub tjkzsj(cadid, dwname, tc) '将新增的图元添加上扩展数据<br/>'On Error Resume Next<br/>wj = "d:\a.txt"<br/>Open wj For Append As #1<br/>Dim ty As AcadEntity<br/>Dim layer As AcadLayer<br/>Set layer = ThisDrawing.Layers.Add(tc)<br/>Dim i As Long<br/>i = ThisDrawing.ModelSpace.Count - 1<br/>Set ty = ThisDrawing.ModelSpace.Item(i)</p><p>'Dim ssget As AcadSelectionSet<br/>'On Error Resume Next<br/>'If Not IsNull(ThisDrawing.SelectionSets.Item("xzj")) Then<br/> 'Set ssget = ThisDrawing.SelectionSets.Item("xzj")<br/> 'ssget.Delete<br/>'End If<br/>'Set ssget = ThisDrawing.SelectionSets.Add("xzj")<br/>'ssget.Select acSelectionSetLast<br/>'For Each ty In ssget<br/>ty.layer = tc<br/>ty.Update<br/>Dim datatype(0 To 7) As Integer<br/>Dim data(0 To 7) As Variant<br/>datatype(0) = 1001: data(0) = "xdata"<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) = cadid<br/>datatype(5) = 1070: data(5) = 5656<br/>datatype(6) = 1071: data(6) = 32332<br/>datatype(7) = 1042: data(7) = 10<br/>ty.SetXData datatype, data<br/>ThisDrawing.Application.Update<br/>Dim xtype As Variant<br/>Dim xdata As Variant<br/>ty.GetXData "", xtpye, xdata<br/>Write #1, tc, xdata(4)<br/>'Next ty<br/>'Write #1, tc, xdata(4)<br/>Close #1<br/>'kckzsj ty<br/>'ssget.Delete<br/>End Sub</p><p>Private Sub kckzsj(ty As AcadEntity)<br/>Dim xtype As Variant<br/>Dim xdata As Variant<br/>ty.GetXData "", xtpye, xdata<br/>End Sub</p><p><br/>Private Sub tjtc(t As String)<br/> Dim wlayer As AcadLayer<br/> Set wlayer = ThisDrawing.Layers.Add(t)<br/> ThisDrawing.ActiveLayer = wlayer<br/>'Dim aa As AcadEntity<br/>'Dim ly As AcadLayer<br/>'Set ly = ThisDrawing.Layers.Add(t)<br/>'Dim ll As String<br/>'Dim l As Integer<br/>'i = ThisDrawing.ModelSpace.Count - 1<br/>'If i < 0 Then<br/>'i = 0<br/>'End If<br/>'Set aa = ThisDrawing.ModelSpace.Item(i)<br/>'ll = aa.layer<br/>'aa.layer = t<br/>'MsgBox (ll)<br/>End Sub<br/>Private Sub tjxx(t As String)<br/>t = Trim(t)<br/>'ThisDrawing.SendCommand "_linetype" & vbCr & s & vbCr & t & vbCr & "" & vbCr & "" & vbCr<br/> 'ThisDrawing.SendCommand "s" & vbCr<br/> 'ThisDrawing.SendCommand t & vbCr<br/> 'ThisDrawing.SendCommand "" & vbCr<br/>ThisDrawing.ActiveLinetype = ThisDrawing.Linetypes.Item(t)</p><p>End Sub</p><p><br/></p>
页:
[1]