Dim sset As AcadSelectionSet ‘在添加以前加个判断语句,看test是否存在 (1) Set sset = acadApp.ActiveDocument.SelectionSets.Add("test") sset.SelectOnScreen If IsNull(acadApp.ActiveDocument.SelectionSets.item("test")) Then Exit Sub Set frm_chamfer_objcs.sset = sset frm_chamfer_objcs.Show (2) acadApp.ActiveDocument.SelectionSets("test").Delete加在(2)的位置,frm_chamfer_objcs.sset 的窗体中的选择集变成nothing了 加在(1)那位置呢,第一次执行会出错,以后就好了
给一个函数给你参考,里面有判断的语句。
Public Function CreateSelectionSet(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