laoxie_198 发表于 2007-10-18 08:31:00

[求助]VBA选择集问题(急)

本帖最后由 作者 于 2007-10-18 17:22:37 编辑 <br /><br /> <p>各位高手:我要选择一封闭多义线内的图元,构建好坐标集后有时能选择到实体有时候选择不到时怎么回事?lisp中用"wf"就能选中,在vba中用acSelectionSetWindowPolygon总是有问题。</p><p>请高手指点!下面是代码</p><p>Sub jhfsc() '街坊线上传到金图数据库中<br/>&nbsp;Dim cn As New ADODB.Connection<br/>&nbsp;Dim gdeo As New ADODB.Recordset<br/>&nbsp;Dim gdeov As New ADODB.Recordset<br/>&nbsp;Dim gdv3 As New ADODB.Recordset<br/>&nbsp;Dim sqllj, gdeolj, gdeovlj, gdv3lj, jfh As String<br/>&nbsp;Dim jfmj As Double '街坊面积<br/>&nbsp;Dim ftype(0 To 1) As Integer<br/>&nbsp;Dim maxvid, vid, eoid, maxeoid As Long<br/>&nbsp;Dim fdata(0 To 1) As Variant<br/>&nbsp;ftype(0) = 0: fdata(0) = "LWPOLYLINE"<br/>&nbsp;ftype(1) = 8: fdata(1) = "街坊线"<br/>&nbsp;Dim ddzb(), sjzb() As Double '顶点坐标<br/>&nbsp;Dim dds, mode As Integer<br/>&nbsp;Dim zb As Variant<br/>&nbsp;Dim ltime As Date<br/>&nbsp;sqllj = "provider=sqloledb.1;password= ;persist security info=true;user id=sa;initial catalog=wzlz ;data source=hbxx"<br/>&nbsp;cn.Open sqllj<br/>&nbsp;<br/>&nbsp; gdv3lj = "select maxvid=max(vid) from gdv3"<br/>&nbsp; gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp; Do While Not gdv3.EOF<br/>&nbsp;&nbsp;&nbsp; maxvid = gdv3.Fields("maxvid")<br/>&nbsp;&nbsp;&nbsp; gdv3.MoveNext<br/>&nbsp; Loop<br/>gdv3.Close</p><p>gdeolj = "select maxeoid=max(eoid) from gdeo"<br/>gdeo.Open gdeolj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>If Not gdeo.EOF Then<br/>maxeoid = gdeo.Fields("maxeoid")<br/>End If<br/>gdeo.Close</p><p>&nbsp;<br/>&nbsp;On Error Resume Next<br/>&nbsp;&nbsp; Dim xzj As AcadSelectionSet<br/>&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.Item("st")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set xzj = ThisDrawing.SelectionSets.Item("st")<br/>&nbsp;&nbsp;&nbsp;&nbsp; xzj.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Set xzj = ThisDrawing.SelectionSets.Add("st") '新建选择集<br/>&nbsp; 'MsgBox xzj.Name<br/>&nbsp; xzj.Select acSelectionSetAll, , , ftype, fdata '选择街坊线<br/>&nbsp; Dim ty As AcadEntity<br/>&nbsp; <br/>&nbsp; For Each ty In xzj<br/>&nbsp; Dim i As Integer<br/>&nbsp; dds = (UBound(ty.Coordinates) + 1) / 2<br/>&nbsp; zb = ty.Coordinates<br/>&nbsp; jfmj = ty.Area '街坊面积<br/>&nbsp;&nbsp;&nbsp; ReDim ddzb(dds * 3 - 1)<br/>&nbsp;&nbsp;&nbsp; ReDim sjzb(dds - 1, 1)<br/>&nbsp;&nbsp;&nbsp; For i = 0 To dds - 1<br/>&nbsp;&nbsp;&nbsp; ddzb(3 * i) = zb(2 * i) 'y<br/>&nbsp;&nbsp;&nbsp; ddzb(3 * i + 1) = zb(2 * i + 1) 'x<br/>&nbsp;&nbsp;&nbsp; ddzb(3 * i + 2) = 0<br/>&nbsp;&nbsp;&nbsp; sjzb(i, 0) = zb(2 * i)<br/>&nbsp;&nbsp;&nbsp; sjzb(i, 1) = zb(2 * i + 1)<br/>&nbsp;&nbsp;&nbsp; Next i '提取端点坐标<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; <br/>&nbsp;jfh = tqjfh(ddzb)<br/>&nbsp;<br/>&nbsp; 'gdeolj = "select * from gdeo where description=' " &amp; jfh &amp; "'"<br/>&nbsp; cn.Execute "insert into gdeo (eoid,description,lastuser,lastaction,synchronized,btf,lastupdatetime,area,st) values(" &amp; maxeoid + 1 &amp; "," &amp; jfh &amp; " ,"",0,1,0," &amp; ltime &amp; "," &amp; jfmj &amp; ",1"</p><p>&nbsp; For i = 0 To dds - 1<br/>&nbsp; gdv3lj = "select * from gdv3 where x=" &amp; sjzb(i, 1) &amp; " and y= " &amp; sjzb(i, 0) &amp; ""<br/>&nbsp; gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp; If Not gdv3.EOF Then<br/>&nbsp;&nbsp;&nbsp; vid = gdv3.Fields("vid")<br/>&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; vid = maxvid + 1<br/>&nbsp;&nbsp;&nbsp; cn.Execute "insert into gdv3 (vid,eoid,vn,x,y,h,vsp,vxys,vhs,vc,lastupdatetime,vt) values (" &amp; vid &amp; ", " &amp; maxeoid + 1 &amp; "," &amp; sjzb(i, 1) &amp; "," &amp; sjzb(i, 0) &amp; ",0,2,1,1,0," &amp; ltime &amp; ",99)"<br/>&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; cn.Execute "insert into gdeov (eoid,eovo,eovid) values (" &amp; maxeoid + 1 &amp; "," &amp; i + 1 &amp; "," &amp; vid &amp; ")"<br/>&nbsp;&nbsp; maxvid = maxvid + 1<br/>&nbsp; <br/>&nbsp; Next<br/>&nbsp; <br/>&nbsp; <br/>&nbsp; <br/>&nbsp; maxeoid = maxeoid + 1<br/>&nbsp; Next 'or Each ty In xzj<br/>&nbsp; <br/>&nbsp; <br/>End Sub</p><p><br/>Function tqjfh(zb) As String '提取街坊号<br/>&nbsp;On Error Resume Next<br/>&nbsp; Dim zjxzj As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.Item("zjst")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set zjxzj = ThisDrawing.SelectionSets.Item("zjst")<br/>&nbsp;&nbsp;&nbsp;&nbsp; zjxzj.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Set zjxzj = ThisDrawing.SelectionSets.Add("zjst") '新建选择集<br/>&nbsp; ReDim gpCode(0 To 1) As Integer<br/>&nbsp;&nbsp;&nbsp; gpCode(0) = 0<br/>&nbsp;&nbsp;&nbsp; gpCode(1) = 8<br/>&nbsp;&nbsp;&nbsp; ReDim dataValue(0 To 1) As Variant<br/>&nbsp;&nbsp;&nbsp; dataValue(0) = "MTEXT"<br/>&nbsp;&nbsp;&nbsp; dataValue(1) = "街坊注记"<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim groupCode As Variant, dataCode As Variant<br/>&nbsp;&nbsp;&nbsp; groupCode = gpCode<br/>&nbsp;&nbsp;&nbsp; dataCode = dataValue<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; zjxzj.SelectByPolygon acSelectionSetWindowPolygon, zb, groupCode, dataCode'这里总是选择不到实体。<br/>&nbsp;&nbsp;&nbsp; 'zjxzj.SelectByPolygon acSelectionSetWindowPolygon, pointsArray, groupCode, dataCode<br/>&nbsp; jfh = "320506" + zjxzj.Item(0).TextString '<br/>&nbsp; '以上提取街坊坐标和街坊号<br/>tqjfh = jfh<br/>End Function</p><p><br/></p><p></p>

nigma 发表于 2007-10-19 15:24:00

laoxie_198发表于2007-10-18 8:31:00static/image/common/back.gif各位高手:我要选择一封闭多义线内的图元,构建好坐标集后有时能选择到实体有时候选择不到时怎么回事?lisp中用\"wf\"就能选中,在vba中用acSelectionSetWindowPolygon总是有问题。.........&n

<p></p>

laoxie_198 发表于 2007-10-19 19:39:00

本帖最后由 作者 于 2007-10-19 20:27:06 编辑

不是屏幕选择。zb是一个坐标集,我要选择zb构成的多义线内的图元。总是提示“参数 pointslist(位于selectbypolygon)中无效。我看过书了坐标是我写的格式的呀!怎么回事呢?还请各位大虾帮帮忙。

laoxie_198 发表于 2007-10-21 16:47:00

<p>高手们:帮我看看到底怎么回事吧?就被这点给挡住了。下不下去了!</p><p>麻烦大家了!</p>

fjfhgdwfn 发表于 2007-10-22 08:57:00

<p>有时选不到。你在选择前用下zoom all。如果出错看看zb是不是三维坐标。</p>

laoxie_198 发表于 2007-10-22 17:00:00

我用zoom all了,zb就是三维坐标。今天在单位里运行就没问题的。真的很奇怪!

laoxie_198 发表于 2007-10-22 23:25:00

问题终于自己解决了。
页: [1]
查看完整版本: [求助]VBA选择集问题(急)