.NET

Reply
Distinguished Contributor
vince1327
Posts: 117
Registered: ‎11-02-2011
Message 11 of 14 (124 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 (121 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: 582
Registered: ‎04-11-2010
Message 13 of 14 (119 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 (117 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
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.