.NET

Reply
Active Contributor
Basha Sk
Posts: 43
Registered: ‎11-07-2006
Message 1 of 9 (182 Views)

Last Created Object

182 Views, 8 Replies
12-11-2006 04:49 AM
Hi All,
How can we get the last created object in the drawing using C#.Net. Thanks in Advance.

Regards,
Basha
Contributor
explosive_ice
Posts: 19
Registered: ‎12-05-2006
Message 2 of 9 (182 Views)

Re: Last Created Object

12-11-2006 05:40 AM in reply to: Basha Sk
Maybe
Object obj;
obj = ThisDrawing.ModelSpace.Item(ThisDrawing.ModelSpace.Count - 1)
Active Contributor
Basha Sk
Posts: 43
Registered: ‎11-07-2006
Message 3 of 9 (182 Views)

Re: Last Created Object

12-11-2006 09:20 PM in reply to: Basha Sk
HI,
I know this and it is in VBA, but i need it in C#.
Regards,
Basha
Contributor
javenkat
Posts: 17
Registered: ‎10-13-2006
Message 4 of 9 (182 Views)

Re: Last Created Object

12-12-2006 12:59 PM in reply to: Basha Sk
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
*Tony Tanzillo
Message 5 of 9 (182 Views)

Re: Last Created Object

12-12-2006 02:42 PM in reply to: Basha Sk
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)
*Tony Tanzillo
Message 6 of 9 (182 Views)

Re: Last Created Object

12-12-2006 02:42 PM in reply to: Basha Sk
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
Contributor
martinduke2653
Posts: 19
Registered: ‎12-04-2005
Message 7 of 9 (182 Views)

Re: Last Created Object

12-13-2006 01:45 PM in reply to: Basha Sk
Tony,

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

Regards,

Martin.
Active Contributor
Basha Sk
Posts: 43
Registered: ‎11-07-2006
Message 8 of 9 (182 Views)

Re: Last Created Object

12-14-2006 05:05 AM in reply to: Basha Sk
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
Contributor
javenkat
Posts: 17
Registered: ‎10-13-2006
Message 9 of 9 (182 Views)

Re: Last Created Object

12-14-2006 10:01 AM in reply to: Basha Sk
using Autodesk.AutoCAD.DatabaseServices;
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.