.NET

Reply
Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 11 of 14 (123 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 (120 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!

 

Distinguished Mentor
gasty1001
Posts: 578
Registered: ‎04-11-2010
Message 13 of 14 (118 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 (116 Views)

Re: Erase last object

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

No worries, thanks again!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!