.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
There is a SelectLast option:
PromptSelectionResult acSSPrompt; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; acSSPrompt = ed.SelectLast();
Gaston Nunez
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Ok that helps, what would i use to delete what i selected with the editor?
Thanks
Vince
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
You should start a transaction, get the last object (as entity) erase it (entity.erase), and commit the transaction and that's it. Like this (not tested, and translated from VB)
[CommandMethod("ELAST")]
public void EraseObj()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;
Editor ed = Application.DocumentManager.MdiActiveDocument.Edit or;
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.Item(0).ObjectId, OpenMode.ForWrite);
ent.Erase();
}
acTrans.Commit();
}
}
Gaston Nunez
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I have not used it and of course 'not supported' but maybe you can search for
Autodesk.AutoCAD.Internal.Utils.EntLast();
and see if people have had success
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks for this sample, i'm having an issue with the line:
ent = acTrans.GetObject(ss.(0).ObjectId, OpenMode.ForWrite);
.
Visual Studio 2010 and AutoCAD 2012 are telling me that there is no definition for ss.item and thus i cannot compile. As i missing a reference?
Thanks
Vince
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Colors;
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Thanks jeff, i'll have a look into this as well.
Cheers
Vince
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
SelectionSet it's part of the EditorInput, and I see you are "using" it, so I have no idea why VS is telling you that. Any way the correct sintax is : ss(index).ObjectId without a dot after ss.
Gaston Nunez
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Ok, so i've got this now:
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);
ent.Erase();
}
acTrans.Commit();
}
}
}
}
But the error I have is 'ss' is a 'variable' but is used like a 'method'
Re: Erase last object
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi,
My mistake (i'm a vb guy), just change ss(0) by ss[0].
Gaston Nunez


