• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    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();

    Please use plain text.
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    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!

     

    Please use plain text.
    Mentor
    Posts: 230
    Registered: ‎04-11-2010

    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

    Please use plain text.
    Distinguished Contributor
    vince1327
    Posts: 117
    Registered: ‎11-02-2011

    Re: Erase last object

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

    No worries, thanks again!

    Please use plain text.