[求助]VBA选择集问题(急)
本帖最后由 作者 于 2007-10-18 17:22:37 编辑 <br /><br /> <p>各位高手:我要选择一封闭多义线内的图元,构建好坐标集后有时能选择到实体有时候选择不到时怎么回事?lisp中用"wf"就能选中,在vba中用acSelectionSetWindowPolygon总是有问题。</p><p>请高手指点!下面是代码</p><p>Sub jhfsc() '街坊线上传到金图数据库中<br/> Dim cn As New ADODB.Connection<br/> Dim gdeo As New ADODB.Recordset<br/> Dim gdeov As New ADODB.Recordset<br/> Dim gdv3 As New ADODB.Recordset<br/> Dim sqllj, gdeolj, gdeovlj, gdv3lj, jfh As String<br/> Dim jfmj As Double '街坊面积<br/> Dim ftype(0 To 1) As Integer<br/> Dim maxvid, vid, eoid, maxeoid As Long<br/> Dim fdata(0 To 1) As Variant<br/> ftype(0) = 0: fdata(0) = "LWPOLYLINE"<br/> ftype(1) = 8: fdata(1) = "街坊线"<br/> Dim ddzb(), sjzb() As Double '顶点坐标<br/> Dim dds, mode As Integer<br/> Dim zb As Variant<br/> Dim ltime As Date<br/> sqllj = "provider=sqloledb.1;password= ;persist security info=true;user id=sa;initial catalog=wzlz ;data source=hbxx"<br/> cn.Open sqllj<br/> <br/> gdv3lj = "select maxvid=max(vid) from gdv3"<br/> gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/> Do While Not gdv3.EOF<br/> maxvid = gdv3.Fields("maxvid")<br/> gdv3.MoveNext<br/> 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> <br/> On Error Resume Next<br/> Dim xzj As AcadSelectionSet<br/> If Not IsNull(ThisDrawing.SelectionSets.Item("st")) Then<br/> Set xzj = ThisDrawing.SelectionSets.Item("st")<br/> xzj.Delete<br/> End If<br/> Set xzj = ThisDrawing.SelectionSets.Add("st") '新建选择集<br/> 'MsgBox xzj.Name<br/> xzj.Select acSelectionSetAll, , , ftype, fdata '选择街坊线<br/> Dim ty As AcadEntity<br/> <br/> For Each ty In xzj<br/> Dim i As Integer<br/> dds = (UBound(ty.Coordinates) + 1) / 2<br/> zb = ty.Coordinates<br/> jfmj = ty.Area '街坊面积<br/> ReDim ddzb(dds * 3 - 1)<br/> ReDim sjzb(dds - 1, 1)<br/> For i = 0 To dds - 1<br/> ddzb(3 * i) = zb(2 * i) 'y<br/> ddzb(3 * i + 1) = zb(2 * i + 1) 'x<br/> ddzb(3 * i + 2) = 0<br/> sjzb(i, 0) = zb(2 * i)<br/> sjzb(i, 1) = zb(2 * i + 1)<br/> Next i '提取端点坐标<br/> <br/> <br/> jfh = tqjfh(ddzb)<br/> <br/> 'gdeolj = "select * from gdeo where description=' " & jfh & "'"<br/> cn.Execute "insert into gdeo (eoid,description,lastuser,lastaction,synchronized,btf,lastupdatetime,area,st) values(" & maxeoid + 1 & "," & jfh & " ,"",0,1,0," & ltime & "," & jfmj & ",1"</p><p> For i = 0 To dds - 1<br/> gdv3lj = "select * from gdv3 where x=" & sjzb(i, 1) & " and y= " & sjzb(i, 0) & ""<br/> gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/> If Not gdv3.EOF Then<br/> vid = gdv3.Fields("vid")<br/> Else<br/> vid = maxvid + 1<br/> 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)"<br/> End If<br/> cn.Execute "insert into gdeov (eoid,eovo,eovid) values (" & maxeoid + 1 & "," & i + 1 & "," & vid & ")"<br/> maxvid = maxvid + 1<br/> <br/> Next<br/> <br/> <br/> <br/> maxeoid = maxeoid + 1<br/> Next 'or Each ty In xzj<br/> <br/> <br/>End Sub</p><p><br/>Function tqjfh(zb) As String '提取街坊号<br/> On Error Resume Next<br/> Dim zjxzj As AcadSelectionSet<br/> If Not IsNull(ThisDrawing.SelectionSets.Item("zjst")) Then<br/> Set zjxzj = ThisDrawing.SelectionSets.Item("zjst")<br/> zjxzj.Delete<br/> End If<br/> Set zjxzj = ThisDrawing.SelectionSets.Add("zjst") '新建选择集<br/> ReDim gpCode(0 To 1) As Integer<br/> gpCode(0) = 0<br/> gpCode(1) = 8<br/> ReDim dataValue(0 To 1) As Variant<br/> dataValue(0) = "MTEXT"<br/> dataValue(1) = "街坊注记"<br/> <br/> Dim groupCode As Variant, dataCode As Variant<br/> groupCode = gpCode<br/> dataCode = dataValue<br/> <br/> zjxzj.SelectByPolygon acSelectionSetWindowPolygon, zb, groupCode, dataCode'这里总是选择不到实体。<br/> 'zjxzj.SelectByPolygon acSelectionSetWindowPolygon, pointsArray, groupCode, dataCode<br/> jfh = "320506" + zjxzj.Item(0).TextString '<br/> '以上提取街坊坐标和街坊号<br/>tqjfh = jfh<br/>End Function</p><p><br/></p><p></p> laoxie_198发表于2007-10-18 8:31:00static/image/common/back.gif各位高手:我要选择一封闭多义线内的图元,构建好坐标集后有时能选择到实体有时候选择不到时怎么回事?lisp中用\"wf\"就能选中,在vba中用acSelectionSetWindowPolygon总是有问题。.........&n<p></p> 本帖最后由 作者 于 2007-10-19 20:27:06 编辑
不是屏幕选择。zb是一个坐标集,我要选择zb构成的多义线内的图元。总是提示“参数 pointslist(位于selectbypolygon)中无效。我看过书了坐标是我写的格式的呀!怎么回事呢?还请各位大虾帮帮忙。 <p>高手们:帮我看看到底怎么回事吧?就被这点给挡住了。下不下去了!</p><p>麻烦大家了!</p> <p>有时选不到。你在选择前用下zoom all。如果出错看看zb是不是三维坐标。</p> 我用zoom all了,zb就是三维坐标。今天在单位里运行就没问题的。真的很奇怪! 问题终于自己解决了。
页:
[1]