Hi, everyone.
The following code is working very well.
But, After excuting layer merge, excuting the following code,
occurs eWasErased error. How should I do with my code?
Private Sub SLF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SLF.Click
Application.DocumentManager.MdiActiveDocument.LockDocument()
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Try
Dim entselopt As PromptEntityOptions = New PromptEntityOptions(vbCrLf + "Select Entity: ")
entselopt.AllowNone = False
entselopt.AllowObjectOnLockedLayer = True
Dim entselres As PromptEntityResult = ed.GetEntity(entselopt)
If entselres.Status <> PromptStatus.OK Then Exit Sub
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim Ent As Entity = trans.GetObject(entselres.ObjectId, OpenMode.ForRead, False, True)
Dim lt As LayerTable = trans.GetObject(db.LayerTableId, OpenMode.ForRead, False, True)
lt.UpgradeOpen()
Dim ltr As LayerTableRecord = trans.GetObject(lt.Item(Ent.Layer), OpenMode.ForWrite, False, True)
For Each objId As ObjectId In lt
If Not objId.IsErased Then
Dim lyr As LayerTableRecord = CType(trans.GetObject(objId, OpenMode.ForWrite), LayerTableRecord)
If Ent.Layer.ToString = lyr.Name AndAlso objId <> db.Clayer Then
lyr.IsOff = True
End If
End If
Next
trans.Commit()
Application.DocumentManager.MdiActiveDocument.Editor.Regen()
End Using
Catch ex As Exception
ed.WriteMessage("Error: " + ex.Message)
End Try
End Sub