关于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> <p>修改为如下试试:</p><p>Dim ssetObj As AcadSelectionSet<br/> on error resume netx</p><p> Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")<br/> if err>0 then</p><p> ThisDrawing.SelectionSets.delete("TEST_SSET")<br/> Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")</p><p> endif<br/><br/><br/> ' Add objects to a selection set by prompting user to select on the screen<br/></p><p> ssetObj.SelectOnScreen<br/></p> <p>谢谢楼上的回复!</p><p>不过好象其中的:ThisDrawing.SelectionSets.delete("TEST_SSET")</p><p>有点问题啊,SelectionSets本身并没有Delete方法啊<br/><br/></p> <p> '创建安全选择集<br/> If Not IsNull(ThisDrawing.SelectionSets.Item("SS5")) Then<br/> Set sstext = ThisDrawing.SelectionSets.Item("SS5")<br/> sstext.Delete<br/> End If<br/> Set sstext = ThisDrawing.SelectionSets.Add("SS5")</p><p>按这种方式设置选择集就行了。</p> <p>问题已经解决 ,多谢谢两位不吝赐教!</p><p>明道真是个好地方!</p> <p>因为运行一次,选择集TEST_SSET已经存在,可以使用如下办法:</p><p>'创建过滤器的函数<br/>Public Sub BuildFilter(TypeArray, dataArray, ParamArray gCodes())<br/> Dim fType() As Integer, fData()<br/> Dim index As Long, i As Long<br/> <br/> index = LBound(gCodes) - 1<br/> For i = LBound(gCodes) To UBound(gCodes) Step 2<br/> index = index + 1<br/> ReDim Preserve fType(0 To index)<br/> ReDim Preserve fData(0 To index)<br/> fType(index) = CInt(gCodes(i))<br/> fData(index) = gCodes(i + 1)<br/> Next<br/> TypeArray = fType: dataArray = fData<br/> <br/>End Sub</p><p>'创建空间选择集的函数<br/>Public Function CreateSelectionSet(Optional ssName As String = "ss") As AcadSelectionSet</p><p> Dim ss As AcadSelectionSet<br/> On Error Resume Next<br/> Set ss = ThisDrawing.SelectionSets(ssName)<br/> If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)<br/> ss.Clear<br/> Set CreateSelectionSet = ss</p><p>End Function</p><p>'返回Thisdrawing,使用CreateSelectionSet和BuildFilter</p><p> '定义空白选择集<br/> Dim LwPSelSet As AcadSelectionSet<br/> Set LwPSelSet = CreateSelectionSet<br/> <br/> <br/> '建立选择集过滤器<br/> Dim TypeArray As Variant<br/> Dim DateArray As Variant<br/> BuildFilter TypeArray, DateArray, 0, "LWPOLYLINE", 8, "jmd"<br/> '0 是类型 8是图层</p><p><br/> LwPSelSet.SelectOnScreen TypeArray, DateArray ’其中TypeArray和DateArray是可选项</p><p></p>
页:
[1]