Re: eNotOpenForRead

#2
Hi,

This error appears when try to change a property of an entity/object that opened for read-only.

Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
ent.Colorindex =1;

If you want to change a property of an entity/object be sure it opened for WRITE.

Entity ent = tr.GetObject(id, OpenMode.ForWrite) as Entity;

Regards.

Re: eNotOpenForRead

#3
Sorry to explain.

The error appears when I try to access a property of a class defined as Entity. Inside the class a trasaction create the object and appended it to database.

After that the entity is available to other functions and subs.

But after Tr.commit inside the original class has been called you can't access the object anymore, the eNotOpenForRead appears indicating it is not availble anymore.

Here is code:

<CommandMethod("CotarPonto", "CotarPonto", "CotarPonto", CommandFlags.Modal And CommandFlags.DocExclusiveLock And CommandFlags.Redraw And CommandFlags.Defun)>
Public Sub Cmd2()
' If ps Is Nothing Then
Try

While True


Using tx As Transaction = App.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()
Dim pso As New PromptSelectionOptions
pso.MessageForAdding = "Selecione>"

Dim psr As PromptSelectionResult = IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(pso)

If Not psr.Status = PromptStatus.OK Then Exit While

Dim PV As New XPV '(psr.Value(0).ObjectId)

PV.Entity = tx.GetObject(psr.Value(0).ObjectId, Teigha.DatabaseServices.OpenMode.ForRead)
PV.Retrieve()

Dim L As New Leader(PV)

' Here the L.GetObjectiD IS null

Dim id As ObjectId = L.GetObjectId

L.MyMLeaderJig()


id = L.GetObjectId
Dim DbSrv As Database = IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database

Dim bt As BlockTable = DbSrv.BlockTableId.GetObject(Teigha.DatabaseServices.OpenMode.ForRead)
Dim ms As BlockTableRecord = bt(Teigha.DatabaseServices.BlockTableRecord.ModelSpace).GetObject(Teigha.DatabaseServices.OpenMode.ForRead)

Dim Xpvl As New XPVLeader
Xpvl.Entity = tx.GetObject(id, Teigha.DatabaseServices.OpenMode.ForRead)
Xpvl.EntityToHandle = PV.Entity.Handle
Xpvl.Commit()

tx.Commit()
End Using

End While
Catch ex As System.Exception
IntelliCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString)
End Try


End Sub

Re: eNotOpenForRead

#5
Danielm103 wrote:
Sat May 30, 2020 4:51 am
commit calls the object's dispose, don't commit until you're done with the object. or reopen it.
it's different behavior than autocad, but safer.
If I Don't commit the object inside class sub it's not appended to database correctly so I can't access the object anyway. The problem is ocurring after calls COMMIT transaction ...

It's bad ... I had tried all the ways but might need to start thinking different, but these are hundred of hundreds of code lines ...

Re: eNotOpenForRead

#6
DenisSilveira wrote:
Sat May 30, 2020 9:19 am
Danielm103 wrote:
Sat May 30, 2020 4:51 am
commit calls the object's dispose, don't commit until you're done with the object. or reopen it.
it's different behavior than autocad, but safer.
If I Don't commit the object inside class sub it's not appended to database correctly so I can't access the object anyway. The problem is ocurring after calls COMMIT transaction ...

It's bad ... I had tried all the ways but might need to start thinking different, but these are hundred of hundreds of code lines ...
I am trying to use TopMostTransaction to add objects in the outer transaction ... this way is possible to access entity but must use Regen to display in the screen ... FlushGraphics would be more eficiently and light than regen