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

Last Created Object

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
977 Views, 8 Replies

Last Created Object

Hi All,
How can we get the last created object in the drawing using C#.Net. Thanks in Advance.

Regards,
Basha
8 REPLIES 8
Message 2 of 9
explosive_ice
in reply to: Anonymous

Maybe
Object obj;
obj = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
Message 3 of 9
Anonymous
in reply to: Anonymous

HI,
I know this and it is in VBA, but i need it in C#.
Regards,
Basha
Message 4 of 9
Anonymous
in reply to: Anonymous

How about :

Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

using (Transaction tr = db.TransactionManager.StartTransaction()) {
BlockTable BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
ObjectId modelSpaceId = BlockTable["*MODEL_SPACE"];
BlockTableRecord modelSpace = tr.GetObject(modelSpaceId, OpenMode.ForRead) as BlockTableRecord;
BlockTableRecordEnumerator iter = modelSpace.GetEnumerator();
ObjectId lastObjId = new ObjectId();
while (iter.MoveNext()) {
lastObjId = iter.Current;
}
DBObject lastObject = tr.GetObject(lastObjId, OpenMode.ForRead);
tr.Commit();
}

HTH
Jai
Message 5 of 9
Anonymous
in reply to: Anonymous

This isn't the VBA newsgroup.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5421292@discussion.autodesk.com...
Maybe
Object obj;
obj = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
Message 6 of 9
Anonymous
in reply to: Anonymous

you can P/Invoke acdbEntLast().


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5422395@discussion.autodesk.com...
HI,
I know this and it is in VBA, but i need it in C#.
Regards,
Basha
Message 7 of 9
martinduke2653
in reply to: Anonymous

Tony,

Pardon my ignorance but could you please explain to me how to Invoke acdbentlast() in VB?

Regards,

Martin.
Message 8 of 9
Anonymous
in reply to: Anonymous

Hi Venkat,
I tried your code, but it is giving an error
"The type or namespace name 'BlockTableRecordEnumerator' could not be found (are you missing a using directive or an assembly reference?)"

Regards,
Basha
Message 9 of 9
Anonymous
in reply to: Anonymous

using Autodesk.AutoCAD.DatabaseServices;

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