this does not work for me can you see anything wrong with mine. The issue is on the 2nd promptselectionresult not finding anything and returning and error status
Public Shared Sub removePoles()
On Error GoTo errorHandle
'' Get the current Document & Database
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'' Get the current document editor
Dim acDocEd As Editor = acDoc.Editor
'' Create a TypedValue array to define the filter criteria
Dim acTypValAr(0) As TypedValue
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "PLOH*"), 0)
'' Assign the filter criteria to a SelectionFilter object
Dim acSelFtr As SelectionFilter = New SelectionFilter(acTypValAr)
'' Request for objects to be selected in the drawing area
Dim acSSPrompt As PromptSelectionResult
acSSPrompt = acDocEd.SelectAll(acSelFtr)
'' If the prompt status is OK, objects were selected
If acSSPrompt.Status = PromptStatus.OK Then
'' Get the selected objects
Dim acSSet1 As SelectionSet
acSSet1 = acSSPrompt.Value
'' Make a second Selection Set
Dim acSSet2 As SelectionSet
'' Append the selected objects to the ObjectIDCollection
Dim acObjIDColl As ObjectIdCollection = New ObjectIdCollection
acObjIDColl = New ObjectIdCollection(acSSet1.GetObjectIds())
Dim acObjIDColl2 As ObjectIdCollection = New ObjectIdCollection
'' Iterate through all poles
For i = acObjIDColl.Count - 1 To 0 Step -1
Dim p1 As Point3d
Dim p2 As Point3d
Dim acEnt As Entity
'' Start a transaction
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction
'' Get the objectID from found object collection id's
Dim acObjID As ObjectId = acObjIDColl.Item(i)
'' Get the entity from object id
acEnt = acTrans.GetObject(acObjID, OpenMode.ForRead)
'' Dispose Transaction
End Using
'' Check if type of entity is a block reference
If TypeOf (acEnt) Is BlockReference Then
'' Cast to block reference
Dim acBlkRef As BlockReference = DirectCast(acEnt, BlockReference)
'' Get Crossing window of block reference
p1 = New Point3d(acBlkRef.Position.X - 0.01, acBlkRef.Position.Y - 0.01, acBlkRef.Position.Z)
p2 = New Point3d(acBlkRef.Position.X + 0.01, acBlkRef.Position.Y + 0.01, acBlkRef.Position.Z)
End If
'' Select anything found at the sampe points
acTypValAr.SetValue(New TypedValue(DxfCode.LayerName, "*"), 0)
'' Create a filter from type value
acSelFtr = New SelectionFilter(acTypValAr)
'' Get all objects in cross window using filter and select anything at the same point
acSSPrompt = acDocEd.SelectCrossingWindow(p1, p2, acSelFtr)
'' Check if prompt is good and items were found
If acSSPrompt.Status = PromptStatus.OK Then
'' Apply results to make a selection set
acSSet2 = acSSPrompt.Value
'' Get objects Id's from new Selection set
acObjIDColl2 = New ObjectIdCollection(acSSet2.GetObjectIds())
'' Check if one or more items were found
If acObjIDColl2.Count = 1 Then
'' Clear out block reference
acObjIDColl2.RemoveAt(0)
'' Delete itrm from selection set one
'acSSet1.Item(i).Delete()
Else
'' Clear selection Set 2
End If
End If
Next
'' Delete both selection setes
'acSSet1.Delete()
'acSSet2.Delete()
End If
Exit Sub
errorHandle:
MsgBox(Err.Description & vbCrLf & "Error number " & Err.Number, vbExclamation, "Error")
Resume Next
End Sub