.NET

Reply
Active Member
Babak
Posts: 8
Registered: ‎10-12-2006
Message 1 of 4 (219 Views)

Get ObjectId of the PolyLine that I just create!

219 Views, 3 Replies
10-17-2006 11:31 PM
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
*GPaolo
Message 2 of 4 (219 Views)

Re: Get ObjectId of the PolyLine that I just create!

10-17-2006 11:42 PM 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
Active Member
Babak
Posts: 8
Registered: ‎10-12-2006
Message 3 of 4 (219 Views)

Re: Get ObjectId of the PolyLine that I just create!

10-18-2006 12:47 AM in reply to: Babak
Thank you very much, this line helped me :smileywink:
objId = btr.AppendEntity(Entity)

Thank you again,
Babak
*Norman Yuan
Message 4 of 4 (219 Views)

Re: Get ObjectId of the PolyLine that I just create!

10-18-2006 07:13 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community