找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 970|回复: 0

[求助]:再求高手相助

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

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

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

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



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.1;Persist 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
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-25 00:00 , Processed in 0.169576 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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