.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get ObjectId of the PolyLine that I just create!

3 REPLIES 3
Reply
Message 1 of 4
Babak
474 Views, 3 Replies

Get ObjectId of the PolyLine that I just create!

Get ObjectId of the PolyLine that I just create!

This code shows me this Error: FATAL ERROR: Unhandled e0434f4dh Exception at 7c812a5bh

I want to get "my3dPoly" objectid, it's the object that I just create by this code...

private ObjectIdDrawPoly(Polyline3d my3dPoly)
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager transMgr = db.TransactionManager;
Transaction trans = transMgr.StartTransaction();
try
{
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(my3dPoly);
trans.AddNewlyCreatedDBObject(my3dPoly, true);
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{ ed.WriteMessage("Error Message: " + ex.Message); }
finally
{ if (my3dPoly != null) my3dPoly.Dispose(); }

//--> Error is Here!!!
return my3dPoly.ObjectId;
}


Thank You For Your Help,
Babak
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Babak

This is the routine that i use to insert a generic entity and work fine also
with polyline

Ciao

GPaolo



Public Shared Function HmInsEnt(ByRef Entity As AcDb.Entity, _

Optional ByRef Color As String = "-1", _

Optional ByRef Layer As String = "-1", _

Optional ByVal LineType As String = "-1") As AcDb.ObjectId

Dim Ed As AcEd.Editor = Editor

Dim db As AcDb.Database = Database

Dim tm As DBTransMan = TransactionManager

Dim myT As AcDb.Transaction = tm.StartTransaction

Dim objId As AcDb.ObjectId = Nothing

Try

Dim bt As AcDb.BlockTable = myT.GetObject(db.BlockTableId,
AcDb.OpenMode.ForRead, False)

AcAs.Application.DocumentManager.MdiActiveDocument.LockDocument(AcAs.Documen
tLockMode.AutoWrite, Nothing, Nothing, True)

Dim btr As AcDb.BlockTableRecord =
myT.GetObject(bt(AcDb.BlockTableRecord.ModelSpace), _

AcDb.OpenMode.ForWrite, False)

If Color <> "-1" Then

Entity.ColorIndex = Color

End If

If Layer <> "-1" Then

Entity.Layer = Layer

End If

If LineType <> "-1" Then

Select Case Entity.GetType.Name.ToUpper

Case "DBTEXT", "MTEXT"

Case Else

Entity.Linetype = LineType

End Select

End If

objId = btr.AppendEntity(Entity)

tm.AddNewlyCreatedDBObject(Entity, True)

myT.Commit()

Return objId

Catch ex As Exception

Return Nothing

Finally

myT.Dispose()

AcAs.Application.DocumentManager.MdiActiveDocument.LockDocument.Dispose()

End Try

End Function

ha scritto nel messaggio news:5365319@discussion.autodesk.com...
Get ObjectId of the PolyLine that I just create!

This code shows me this Error: FATAL ERROR: Unhandled e0434f4dh Exception
at 7c812a5bh

I want to get "my3dPoly" objectid, it's the object that I just create by
this code...

private ObjectIdDrawPoly(Polyline3d my3dPoly)
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager transMgr =
db.TransactionManager;
Transaction trans = transMgr.StartTransaction();
try
{
BlockTableRecord btr =
(BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(my3dPoly);
trans.AddNewlyCreatedDBObject(my3dPoly, true);
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{ ed.WriteMessage("Error Message: " + ex.Message); }
finally
{ if (my3dPoly != null) my3dPoly.Dispose(); }

//--> Error is Here!!!
return my3dPoly.ObjectId;
}


Thank You For Your Help,
Babak
Message 3 of 4
Babak
in reply to: Babak

Thank you very much, this line helped me 😉
objId = btr.AppendEntity(Entity)

Thank you again,
Babak
Message 4 of 4
Anonymous
in reply to: Babak

Your problem is that you called my3dPoly.Dispose() in finally{} block, then
you refer its ObjectId property in "return" statement. There is no need to
call Dispose() to the Polyline entity at all, especially, when it is passed
in from outside the method (I believe you created the polyline and then call
this method to only add it into database and get ObjectId as return. In this
case, even you do not need this polyline, you should do it when executing of
this method finishes and returns to your calling procedure, just for the
sake of readability). Actually, the Dispose() call does nothing but cause
the error: the actual Polyline has been added into database, so it stays in
memory until you erase it, why "dispose" it?

wrote in message news:5365319@discussion.autodesk.com...
Get ObjectId of the PolyLine that I just create!

This code shows me this Error: FATAL ERROR: Unhandled e0434f4dh Exception
at 7c812a5bh

I want to get "my3dPoly" objectid, it's the object that I just create by
this code...

private ObjectIdDrawPoly(Polyline3d my3dPoly)
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager transMgr =
db.TransactionManager;
Transaction trans = transMgr.StartTransaction();
try
{
BlockTableRecord btr =
(BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
btr.AppendEntity(my3dPoly);
trans.AddNewlyCreatedDBObject(my3dPoly, true);
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{ ed.WriteMessage("Error Message: " + ex.Message); }
finally
{ if (my3dPoly != null) my3dPoly.Dispose(); }

//--> Error is Here!!!
return my3dPoly.ObjectId;
}


Thank You For Your Help,
Babak

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost