找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1678|回复: 0

[求助]:VBA中选择集问题

[复制链接]
发表于 2007-10-18 08:36:49 | 显示全部楼层 |阅读模式

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

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

×
我要选择封闭多义线内的实体,点集已经构建好了用acSelectionSetWindowPolygon总是选择不到实体。 zjxzj.SelectByPolygon acSelectionSetWindowPolygon, zb, groupCode, dataCode’这里zjxzj总是空的。
还请高手多多指点。
Sub jhfsc() '街坊线上传到金图数据库中
Dim cn As New ADODB.Connection
Dim gdeo As New ADODB.Recordset
Dim gdeov As New ADODB.Recordset
Dim gdv3 As New ADODB.Recordset
Dim sqllj, gdeolj, gdeovlj, gdv3lj, jfh As String
Dim jfmj As Double '街坊面积
Dim ftype(0 To 1) As Integer
Dim maxvid, vid, eoid, maxeoid As Long
Dim fdata(0 To 1) As Variant
ftype(0) = 0: fdata(0) = "LWPOLYLINE"
ftype(1) = 8: fdata(1) = "街坊线"
Dim ddzb(), sjzb() As Double '顶点坐标
Dim dds, mode As Integer
Dim zb As Variant
Dim ltime As Date
sqllj = "provider=sqloledb.1;password= ;persist security info=true;user id=sa;initial catalog=wzlz ;data source=hbxx"
cn.Open sqllj

  gdv3lj = "select maxvid=max(vid) from gdv3"
  gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic
  Do While Not gdv3.EOF
    maxvid = gdv3.Fields("maxvid")
    gdv3.MoveNext
  Loop
gdv3.Close

gdeolj = "select maxeoid=max(eoid) from gdeo"
gdeo.Open gdeolj, cn, adOpenForwardOnly, adLockBatchOptimistic
If Not gdeo.EOF Then
maxeoid = gdeo.Fields("maxeoid")
End If
gdeo.Close


On Error Resume Next
   Dim xzj As AcadSelectionSet
   If Not IsNull(ThisDrawing.SelectionSets.Item("st")) Then
     Set xzj = ThisDrawing.SelectionSets.Item("st")
     xzj.Delete
     End If
  Set xzj = ThisDrawing.SelectionSets.Add("st") '新建选择集
  'MsgBox xzj.Name
  xzj.Select acSelectionSetAll, , , ftype, fdata '选择街坊线
  Dim ty As AcadEntity
  
  For Each ty In xzj
  Dim i As Integer
  dds = (UBound(ty.Coordinates) + 1) / 2
  zb = ty.Coordinates
  jfmj = ty.Area '街坊面积
    ReDim ddzb(dds * 3 - 1)
    ReDim sjzb(dds - 1, 1)
    For i = 0 To dds - 1
    ddzb(3 * i) = zb(2 * i) 'y
    ddzb(3 * i + 1) = zb(2 * i + 1) 'x
    ddzb(3 * i + 2) = 0
    sjzb(i, 0) = zb(2 * i)
    sjzb(i, 1) = zb(2 * i + 1)
    Next i '提取端点坐标
   
   
jfh = tqjfh(ddzb)

  'gdeolj = "select * from gdeo where description=' " & jfh & "'"
  cn.Execute "insert into gdeo (eoid,description,lastuser,lastaction,synchronized,btf,lastupdatetime,area,st) values(" & maxeoid + 1 & "," & jfh & " ,"",0,1,0," & ltime & "," & jfmj & ",1"

  For i = 0 To dds - 1
  gdv3lj = "select * from gdv3 where x=" & sjzb(i, 1) & " and y= " & sjzb(i, 0) & ""
  gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic
  If Not gdv3.EOF Then
    vid = gdv3.Fields("vid")
  Else
    vid = maxvid + 1
    cn.Execute "insert into gdv3 (vid,eoid,vn,x,y,h,vsp,vxys,vhs,vc,lastupdatetime,vt) values (" & vid & ", " & maxeoid + 1 & "," & sjzb(i, 1) & "," & sjzb(i, 0) & ",0,2,1,1,0," & ltime & ",99)"
  End If
    cn.Execute "insert into gdeov (eoid,eovo,eovid) values (" & maxeoid + 1 & "," & i + 1 & "," & vid & ")"
   maxvid = maxvid + 1
  
  Next
  
  
  
  maxeoid = maxeoid + 1
  Next 'or Each ty In xzj
  
  
End Sub


Function tqjfh(zb) As String '提取街坊号
On Error Resume Next
  Dim zjxzj As AcadSelectionSet
     If Not IsNull(ThisDrawing.SelectionSets.Item("zjst")) Then
     Set zjxzj = ThisDrawing.SelectionSets.Item("zjst")
     zjxzj.Delete
     End If
  Set zjxzj = ThisDrawing.SelectionSets.Add("zjst") '新建选择集
  ReDim gpCode(0 To 1) As Integer
    gpCode(0) = 0
    gpCode(1) = 8
    ReDim dataValue(0 To 1) As Variant
    dataValue(0) = "MTEXT"
    dataValue(1) = "街坊注记"
   
    Dim groupCode As Variant, dataCode As Variant
    groupCode = gpCode
    dataCode = dataValue
   
    zjxzj.SelectByPolygon acSelectionSetWindowPolygon, zb, groupCode, dataCode’这里zjxzj总是空的。
    'zjxzj.SelectByPolygon acSelectionSetWindowPolygon, pointsArray, groupCode, dataCode
  jfh = "320506" + zjxzj.Item(0).TextString '
  '以上提取街坊坐标和街坊号
tqjfh = jfh
End Function
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-16 13:14 , Processed in 0.301460 second(s), 33 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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