ivy.xiaoyu 发表于 2008-5-27 08:25:00

关于SelecOnScreen的问题求教,急!

<p>最近学习VBA遇到了些困难,</p><p>其中有一个,当我试图在模块里建立一个Sub过程时:代码如下:</p><pre class="Code">Sub Example_SelectOnScreen()
      
    ' Create the selection set
    Dim ssetObj As AcadSelectionSet
    Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")
   
    ' Add objects to a selection set by prompting user to select on the screen
    ssetObj.SelectOnScreen
   
End Sub</pre><pre class="Code">问题出现在只能运行一次,运行第二次的时候就回出现"命名选择集已存在"的错误,研究了一天也没改出来,</pre><pre class="Code">请高手指教啊</pre>

xinglee 发表于 2008-5-27 09:28:00

<p>修改为如下试试:</p><p>Dim ssetObj As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; on error resume netx</p><p>&nbsp;&nbsp;&nbsp; Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")<br/>&nbsp;&nbsp;&nbsp; if err&gt;0 then</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets.delete("TEST_SSET")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")</p><p>&nbsp;&nbsp;&nbsp;endif<br/><br/><br/>&nbsp;&nbsp;&nbsp; ' Add objects to a selection set by prompting user to select on the screen<br/></p><p>&nbsp;&nbsp;&nbsp; ssetObj.SelectOnScreen<br/></p>

ivy.xiaoyu 发表于 2008-5-27 09:47:00

<p>谢谢楼上的回复!</p><p>不过好象其中的:ThisDrawing.SelectionSets.delete("TEST_SSET")</p><p>有点问题啊,SelectionSets本身并没有Delete方法啊<br/><br/></p>

hbyu2003 发表于 2008-5-27 10:38:00

<p>&nbsp;'创建安全选择集<br/>&nbsp;&nbsp;&nbsp; If Not IsNull(ThisDrawing.SelectionSets.Item("SS5")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set sstext = ThisDrawing.SelectionSets.Item("SS5")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sstext.Delete<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp; Set sstext = ThisDrawing.SelectionSets.Add("SS5")</p><p>按这种方式设置选择集就行了。</p>

ivy.xiaoyu 发表于 2008-5-27 12:15:00

<p>问题已经解决 ,多谢谢两位不吝赐教!</p><p>明道真是个好地方!</p>

robbin840311 发表于 2008-5-30 08:23:00

<p>因为运行一次,选择集TEST_SSET已经存在,可以使用如下办法:</p><p>'创建过滤器的函数<br/>Public Sub BuildFilter(TypeArray, dataArray, ParamArray gCodes())<br/>&nbsp;&nbsp;&nbsp; Dim fType() As Integer, fData()<br/>&nbsp;&nbsp;&nbsp; Dim index As Long, i As Long<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; index = LBound(gCodes) - 1<br/>&nbsp;&nbsp;&nbsp; For i = LBound(gCodes) To UBound(gCodes) Step 2<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; index = index + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve fType(0 To index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ReDim Preserve fData(0 To index)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fType(index) = CInt(gCodes(i))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fData(index) = gCodes(i + 1)<br/>&nbsp;&nbsp;&nbsp; Next<br/>&nbsp;&nbsp;&nbsp; TypeArray = fType: dataArray = fData<br/>&nbsp;&nbsp;&nbsp; <br/>End Sub</p><p>'创建空间选择集的函数<br/>Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet</p><p>&nbsp;&nbsp;&nbsp; Dim ss As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; Set ss = ThisDrawing.SelectionSets(ssName)<br/>&nbsp;&nbsp;&nbsp; If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)<br/>&nbsp;&nbsp;&nbsp; ss.Clear<br/>&nbsp;&nbsp;&nbsp; Set CreateSelectionSet = ss</p><p>End Function</p><p>'返回Thisdrawing,使用CreateSelectionSet和BuildFilter</p><p>&nbsp; '定义空白选择集<br/>&nbsp; Dim LwPSelSet As AcadSelectionSet<br/>&nbsp; Set LwPSelSet = CreateSelectionSet<br/>&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '建立选择集过滤器<br/>&nbsp; Dim TypeArray As Variant<br/>&nbsp; Dim DateArray As Variant<br/>&nbsp; BuildFilter TypeArray, DateArray, 0, "LWPOLYLINE", 8, "jmd"<br/>&nbsp; '0 是类型&nbsp; 8是图层</p><p><br/>&nbsp; LwPSelSet.SelectOnScreen TypeArray, DateArray&nbsp; ’其中TypeArray和DateArray是可选项</p><p></p>
页: [1]
查看完整版本: 关于SelecOnScreen的问题求教,急!