GetObjectIds to ObjectIdCollection
ObjectId() to ObjectIdCollection
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
<CommandMethod("MergeSelectionSets")> _
Public Sub MergeSelectionSets()
'' Get the current document editor
Dim acDocEd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.GetSelection()
Dim acSSet1 As SelectionSet
Dim acObjIdColl As ObjectIdCollection = New ObjectIdCollection()
'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
'' Get the selected objects
acSSet1 = acSSPrompt.Value
'' Append the selected objects to the ObjectIdCollection
acObjIdColl = New ObjectIdCollection(acSSet1.GetObjectIds())
End If
'' Request for objects to be selected in the drawing area
acSSPrompt = acDocEd.GetSelection()
Dim acSSet2 As SelectionSet
'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
acSSet2 = acSSPrompt.Value
'' Check the size of the ObjectIdCollection, if zero, then initialize it
If acObjIdColl.Count = 0 Then
acObjIdColl = New ObjectIdCollection(acSSet2.GetObjectIds())
Else
Dim acObjId As ObjectId
'' Step through the second selection set
For Each acObjId In acSSet2.GetObjectIds()
'' Add each object id to the ObjectIdCollection
acObjIdColl.Add(acObjId)
Next
End If
End If
Application.ShowAlertDialog("Number of objects selected: " & _
acObjIdColl.Count.ToString())
End Sub
‘用Copyto 可将ObjectIdCollection转为ObjectId()
Dim NewIDS As New ObjectIdCollection
Dim NewIDArray As ObjectId() = New ObjectId(NewIDS.Count - 1) {} '必须提前初始化,不能用nothing
NewIDS.CopyTo(NewIDArray, 0)
Please follow WeChat's public account ByCAD