明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1131|回复: 0

再求高手帮忙!!

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

下面我的代码怎么总是有错误?

读取不了集合里的图元,不知道问题出在那?请高手指点

Private Sub CommandButton3_Click()
Dim sjk As New ADODB.Connection
Dim dw As New ADODB.Recordset
Dim text As New ADODB.Recordset
Dim ty As New ADODB.Recordset
Dim tylj As New ADODB.Recordset
Dim point As New ADODB.Recordset
Dim pointtext As New ADODB.Recordset
Dim sjklj, dwname As String
Dim x, y As Double
Dim tylx As String
sjklj = "Provider=MSDASQL.1ersist Security Info=False;Data Source=hbcad"
sjk.Open sjklj '打开库连接
dwname = InputBox("请输入单位名称")
ty.Open "select * from tysx where dwid in (select dwid from tyname where dwname='" & dwname & "')", sjk, adOpenDynamic, adLockBatchOptimistic
If ty.EOF Then
MsgBox ("库中没有此单位")
End
End If

Do While Not ty.EOF
tc = ty.Fields("larer") '图层
  tylj.Open "select * from tylj where tyid=" & ty.Fields("cadid") & " order by xh asc", sjk, adOpenDynamic, adLockBatchOptimistic
  tylx = ty.Fields("tylx") '图元类型
  If tylx = "AcDbMText" Or tylx = "AcDbText" Then
  te ty.Fields("cadid"), ty.Fields("larer"), sjk '注记
  End If
  Do While Not tylj.EOF
  point.Open "select *from point where pointid=" & tylj.Fields("pointid") & " ", sjk, adOpenDynamic, adLockBatchOptimistic
   Select Case tylx
    Case "AcDbPolyline" '是多段线时
    ThisDrawing.SendCommand "_pline" & vbCr
    x = point.Fields("x")
    y = point.Fields("y")
    ThisDrawing.SendCommand x & "," & y & vbCr
    Case "AcDbLine" '是line线时
    ThisDrawing.SendCommand "_line" & vbCr
    x = point.Fields("x")
    y = point.Fields("y")
    ThisDrawing.SendCommand x & "," & y & vbCr
  End Select
  tylj.MoveNext
  point.Close
 Loop
 If tylx = "AcDbPolyline" Then
 ThisDrawing.SendCommand "c" & vbCr
 Else
  If tylx = "AcDbLine" Then
  ThisDrawing.SendCommand "" & vbCr
  End If
 End If
tjkzsj ty.Fields("cadid"), dwname, tc
 tylj.Close
ty.MoveNext
Loop
ty.Close
MsgBox ("数据下载完毕")
End Sub

Private Sub te(cadid, tc, sjk) '下载注记
 Dim text As New ADODB.Recordset
 Dim pointtext As New ADODB.Recordset
 text.Open "select * from tytext where cadid=" & cadid & "", sjk, adOpenDynamic, adLockBatchOptimistic
 pointtext.Open "select *from point where pointid in (select pointid from tytext where cadid=" & cadid & ")", sjk, adOpenDynamic, adLockBatchOptimistic
    ThisDrawing.SendCommand "_text" & vbCr
    ThisDrawing.SendCommand pointtext.Fields("x") & "," & pointtext.Fields("y") & vbCr
    ThisDrawing.SendCommand text.Fields("ztdx") & vbCr
    ThisDrawing.SendCommand 0 & vbCr
    ThisDrawing.SendCommand text.Fields("nr") & vbCr
    ThisDrawing.SendCommand "" & vbCr
    text.Close
  pointtext.Close
 
End Sub
Private Sub tjkzsj(cadid, dwname, tc) '将新增的图元添加上扩展数据
wj = "d:\a.txt"
Open wj For Append As #1
Dim ty As AcadEntity
Dim layer As AcadLayer
Set layer = ThisDrawing.Layers.Add(tc)
Dim i As Long
i = ThisDrawing.ModelSpace.Count - 1;为什么我的i值总是-1呀!cad里明明有图元的呀
Set ty = ThisDrawing.ModelSpace.Item(i)

'Dim ssget As AcadSelectionSet
'On Error Resume Next
'If Not IsNull(ThisDrawing.SelectionSets.Item("xzj")) Then
 'Set ssget = ThisDrawing.SelectionSets.Item("xzj")
 'ssget.Delete
'End If
'Set ssget = ThisDrawing.SelectionSets.Add("xzj")
'ssget.Select acSelectionSetLast
'For Each ty In ssget
ty.layer = tc
ty.Update
Dim datatype(0 To 7) As Integer
Dim data(0 To 7) As Variant
datatype(0) = 1001: data(0) = "xdata"
datatype(1) = 1000: data(1) = dwname
datatype(2) = 1003: data(2) = "0"
datatype(3) = 1040: data(3) = 1.232
datatype(4) = 1041: data(4) = cadid
datatype(5) = 1070: data(5) = 5656
datatype(6) = 1071: data(6) = 32332
datatype(7) = 1042: data(7) = 10
ty.SetXData datatype, data
ThisDrawing.Application.Update
Dim xtype As Variant
Dim xdata As Variant
ty.GetXData "", xtpye, xdata
Write #1, tc, xdata(4)
'Next ty
'Write #1, tc, xdata(4)
Close #1
'kckzsj ty
'ssget.Delete
End Sub

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

本版积分规则

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

GMT+8, 2024-11-26 22:44 , Processed in 0.140990 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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