.NET

Reply
Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 11 of 14 (114 Views)

Re: Erase last object

03-21-2012 06:30 AM in reply to: gasty1001

Haha didn't even notice that. Now when i change it to ss[0], i get 

 

Error 1 Cannot implicitly convert type 'Autodesk.AutoCAD.DatabaseServices.DBObject' to 'Autodesk.AutoCAD.DatabaseServices.Entity'. An explicit conversion exists (are you missing a cast?) C:\Users\user\Dropbox\Programming\Cad\Cad\TheProgram\Drawing Commands\Copy of AREA.cs 28 27 Commands

 

 

if (ss.Count > 0)
{
ent = acTrans.GetObject(ss[0].ObjectId, OpenMode.ForWrite);
ent.Erase();
}
acTrans.Commit();

Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 12 of 14 (111 Views)

Re: Erase last object

03-21-2012 06:47 AM in reply to: vince1327

Scratch that, fixed it :smileywink:

 

public void EraseObj()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
PromptSelectionResult acSSPrompt;
acSSPrompt = ed.SelectLast();
Entity ent;
SelectionSet ss = acSSPrompt.Value;

if (ss.Count > 0)
{
ent = acTrans.GetObject(ss[0].ObjectId, OpenMode.ForWrite) as Entity;
ent.Erase();
}
acTrans.Commit();
}
}
}
}

 

Thanks a million for your help!

 

Valued Mentor
gasty1001
Posts: 477
Registered: ‎04-11-2010
Message 13 of 14 (109 Views)

Re: Erase last object

03-21-2012 07:02 AM in reply to: vince1327

Hi,

 

Glad to help you, sorry the mistake, i feel much comfortable with vb 'cause I'd like to see "End this", "End That"... instead of a lot of brackets at the end of a block of code.

 

Gaston Nunez

Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 14 of 14 (107 Views)

Re: Erase last object

03-21-2012 07:11 AM in reply to: gasty1001

No worries, thanks again!

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 or visit the Installation and Licensing Forum to get help installing your software.