I have a routine for Isolating selected objects. It works fine BUT not on blocks. If I try to use it on a block the block will disappear. can anyone help?
<CommandMethod("isom")> _
Public Sub objectsIsolate()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim tm As Autodesk.AutoCAD.ApplicationServices.TransactionManager = db.TransactionManager
Dim ss As SelectionSet
Dim ent As Entity = Nothing
Dim trans As Transaction = tm.StartTransaction()
Try
Dim bt As BlockTable = tm.GetObject(db.BlockTableId, OpenMode.ForRead, False)
Dim btr As BlockTableRecord = tm.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead, False, True)
'Get objectIds from user selection
Dim prmptSSopt As New PromptSelectionOptions()
prmptSSopt.PrepareOptionalDetails = True
prmptSSopt.RejectObjectsOnLockedLayers = False
prmptSSopt.MessageForAdding = "Select objects to isolate: " + vbNewLine
Dim ssRes As PromptSelectionResult = ed.GetSelection(prmptSSopt)
If Not ssRes.Status = PromptStatus.OK Then Exit Sub
ss = ssRes.Value
'make an array of objectIds from the user's selection set
Dim objIds() As ObjectId = ss.GetObjectIds()
'Make everything visible = false
For Each id As ObjectId In btr 'For Each id In drawing
ent = CType(trans.GetObject(id, OpenMode.ForWrite, False), Entity)
ent.Visible = False
Next
'Make Users selection visible
For Each objId As ObjectId In objIds
ent = CType(trans.GetObject(objId, OpenMode.ForWrite, False, True), Entity)
ent.Visible = True
Next
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Error in Isolate")
Finally
trans.Commit()
trans.Dispose()
End Try
End Sub