magnus2005 发表于 2022-7-6 21:58:42

创建selectionset模块

我需要模块1来选择集,模块2来使用选择集。
模块1:
Public Function CreateSelectionSet1(Optional ssName As String = "ss") As AcadSelectionSet

   Dim ss As AcadSelectionSet
   
   On Error Resume Next
   Set ss = ThisDrawing.SelectionSets(ssName)
   If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
   ss.Clear
   Set CreateSelectionSet = ss

End Function
模块2:
sub useIT

selset = CreateSelectionSet1
msgbox(selset.count)
end sub


“.count”是使用的示例,但这也不起作用。
错误:“参数非可选”。
如果它是另一个可变f.e字符串,而不是ACADSelectionSet,则它可以工作

RICVBA 发表于 2022-7-6 23:44:46

 
 
修改如下
 
Option Explicit


Sub useIT()
Dim selset As AcadSelectionSet
Set selset = CreateSelectionSet1
MsgBox (selset.Count)
End Sub

Public Function CreateSelectionSet1(Optional ssName As String = "ss") As AcadSelectionSet
   Dim ss As AcadSelectionSet

   On Error Resume Next
   Set ss = ThisDrawing.SelectionSets(ssName)
   If Err Then Set ss = ThisDrawing.SelectionSets.Add(ssName)
   ss.Clear
   Set Create SelectionSet1 = ss
End Function

 
您错过了(请参阅红色/粗体文本-不知道为什么我无法将红色设置为Selectionset1 word中的“1”字符):
-“selset=CreateSelectionSet1”语句开头的“Set”关键字
-“CreateSelectionSet1”函数中的正确函数名引用
 
此外,我在模块的开头添加了“Option Explicit”语句。我总是发现这很有帮助,因为它迫使你明确地声明所有变量,从而不留下一些隐式变量,这最终会更好地理解我在做什么
页: [1]
查看完整版本: 创建selectionset模块