Entity.UpgradeOpen

Entity.UpgradeOpen

Anonymous
Not applicable
2,864 Views
2 Replies
Message 1 of 3

Entity.UpgradeOpen

Anonymous
Not applicable
i'm having issues with upgrading an entity so i can change its layer... here's what i have

{color:#333399}Dim myLock As AutoCAD.ApplicationServices.DocumentLock = myDoc.LockDocument()
Using Trans As AutoCAD.DatabaseServices.Transaction = myDb.TransactionManager.StartTransaction
{color}
{color:#333399}Try
{color}
{color:#333399}ent.UpgradeOpen()
ent.Layer = lay
ent.DowngradeOpen()
{color}
{color:#333399}Catch ex As Exception
{color}
{color:#333399}myUtility.Prompt(vbLf & "Unable to change layer: " & ex.Message)
{color}
{color:#333399}End Try
Trans.Commit()
{color}
{color:#333399}End Using myLock.Dispose(){color}

i tried it with a transaction, without a transaction, with a document lock, without a document lock, all i get is{color:#ff0000} {color}{color:#ff0000}eInvalidOpenState{color}, i'm not sure where i'm going wrong here... any help would be more than appreciated. if you need any other info let me know.

btw, i'm getting my entity from another transaction:
{color:#333399}Dim ent As AutoCAD.DatabaseServices.Entity = CType(Trans.GetObject(obId, AutoCAD.DatabaseServices.OpenMode.ForRead), AutoCAD.DatabaseServices.Entity){color}
0 Likes
2,865 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
here's what i did that worked, not sure if it's the right way, but maybe it'll help someone like me

{color:#333399}Dim myLock As AutoCAD.ApplicationServices.DocumentLock = myDoc.LockDocument()
Using Trans As AutoCAD.DatabaseServices.Transaction = myDb.TransactionManager.StartTransaction
Try
Dim wEnt As AutoCAD.DatabaseServices.Entity = CType(Trans.GetObject(ent.ObjectId, OpenMode.ForWrite), AutoCAD.DatabaseServices.Entity)
wEnt.Layer = lay
wEnt.DowngradeOpen()
Catch ex As Exception
myUtility.Prompt(vbLf & "Unable to change layer: " & ex.Message)
End Try
Trans.Commit()
End Using
myLock.Dispose()
End Sub{color}
0 Likes
Message 3 of 3

Anonymous
Not applicable
The reason that's happening is because the original transaction
that you opened the entity in has already ended when you call
UpgradeOpen().

You shouldn't use a DBObject once the transaction you got it from
has ended, and while there'll usually be no error in cases where
you do that with an entity that's open for read, doing it remains
a no-no.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:6051997@discussion.autodesk.com...
i'm having issues with upgrading an entity so i can change its layer... here's what i have

{color:#333399}Dim myLock As AutoCAD.ApplicationServices.DocumentLock = myDoc.LockDocument()
Using Trans As AutoCAD.DatabaseServices.Transaction = myDb.TransactionManager.StartTransaction
{color}
{color:#333399}Try
{color}
{color:#333399}ent.UpgradeOpen()
ent.Layer = lay
ent.DowngradeOpen()
{color}
{color:#333399}Catch ex As Exception
{color}
{color:#333399}myUtility.Prompt(vbLf & "Unable to change layer: " & ex.Message)
{color}
{color:#333399}End Try
Trans.Commit()
{color}
{color:#333399}End Using myLock.Dispose(){color}

i tried it with a transaction, without a transaction, with a document lock, without a document lock, all i get is{color:#ff0000} {color}{color:#ff0000}eInvalidOpenState{color}, i'm not sure where i'm going wrong here... any help would be more than appreciated. if you need any other info let me know.

btw, i'm getting my entity from another transaction:
{color:#333399}Dim ent As AutoCAD.DatabaseServices.Entity = CType(Trans.GetObject(obId, AutoCAD.DatabaseServices.OpenMode.ForRead), AutoCAD.DatabaseServices.Entity){color}
0 Likes