Author Topic: Entlast using the doc.Editor  (Read 3691 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Entlast using the doc.Editor
« on: November 30, 2007, 10:54:07 PM »

I was reading through the ObjectBrowser, ( as one does on a Saturday morning),
and this caught my eye.
public PromptSelectionResult SelectLast();
Declaring Type: Autodesk.AutoCAD.EditorInput.Editor

so I had a play.
The core of this could probably be wrapped and used as an alternative to P/Invokeing acdbEntLast().
This is pretty basic, but may be handy ..
sorry, no piccy ; you'll need to build it to see :-)
Code: [Select]
// CodeHimBelongaKwb ©  Nov 2007
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(SelectLastTest.TestCommands))]

namespace SelectLastTest
{
    public class TestCommands
    {
        [CommandMethod("SelectLast")]
        static public void testSelectLast()
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            PromptSelectionResult whatsLast = doc.Editor.SelectLast();

            if (whatsLast.Value != null
              && whatsLast.Value.Count == 1)
            {
                AcadApp.ShowAlertDialog("\nEntlast ObjectID is: "
                                        + whatsLast.Value[0].ObjectId);
            }
            else
            {
                AcadApp.ShowAlertDialog("\nOooops Nothing to see ");
            }
        }
    }
}

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entlast using the doc.Editor
« Reply #1 on: December 01, 2007, 01:10:29 AM »
Perhaps something like this is worth a try ..

added:  or would returning an Entity or DBObject be better suited ?
Code: [Select]
        /// <summary>
        /// Return the ObjectID of the last entity in the DataBase
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        static public ObjectId SelectLastEnt(Document doc)       
        {           
            PromptSelectionResult LastEnt = doc.Editor.SelectLast();
            if (LastEnt.Value != null && LastEnt.Value.Count == 1)
            {
                 return  LastEnt.Value[0].ObjectId;
            }
            return ObjectId.Null;
        }



        [CommandMethod("TestIt")]
        static public void testSelectLastEnt()
        {           
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;

            // bla, bla

            ObjectId LastDBEntID = SelectLastEnt(doc);

            if (LastDBEntID.IsNull)
            {
                // oops
                return;
            }
            AcadApp.ShowAlertDialog("\nEntlast ObjectID is: "
                                        + LastDBEntID);
        }
« Last Edit: December 01, 2007, 01:26:36 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entlast using the doc.Editor
« Reply #2 on: December 01, 2007, 01:57:34 AM »
.. though this seems to work ..
Code: [Select]
// CodeHimBelongaKwb ©  Nov 2007
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using DdTMan = Autodesk.AutoCAD.DatabaseServices.TransactionManager;

[assembly: CommandClass(typeof(SelectLastTest.TestCommands))]

namespace SelectLastTest
{
    public class TestCommands
    {
        /// <summary>
        /// Return the ObjectID of the last entity in the DataBase
        /// </summary>
        /// <param name="db"></param>
        /// <returns></returns>
        static public ObjectId SelectLastEnt(Document doc)       
        {           
            PromptSelectionResult LastEnt = doc.Editor.SelectLast();
            if (LastEnt.Value != null && LastEnt.Value.Count == 1)
            {
                 return  LastEnt.Value[0].ObjectId;
            }
            return ObjectId.Null;
        }


        [CommandMethod("TestIt")]
        static public void testSelectLastEnt()
        {           
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
           
            // bla, bla

            ObjectId LastDBEntID = SelectLastEnt(doc);

            if (LastDBEntID.IsNull)
            {
                // oops
                return;
            }
            DdTMan tm = db.TransactionManager;
            DBObject LastDBObject;
            using (Transaction tr = tm.StartTransaction())
            {
               LastDBObject = tm.GetObject(LastDBEntID, OpenMode.ForRead, true);
            }         

            AcadApp.ShowAlertDialog("\nEntlast ObjectID is: "
                                        + LastDBEntID
                                     + "\nEntlast Type is: "   
                                        + LastDBObject                                       
                                        );
        }

    }
}

edit/added: a picky for joe.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Entlast using the doc.Editor
« Reply #3 on: December 01, 2007, 08:25:53 PM »

Quote
public static ObjectId EntLast();
 
Declaring Type: Autodesk.AutoCAD.Internal.Utils
Assembly: acmgdinternal, Version=17.2.0.0


Quote
public static extern unsafe int modopt(CallConvCdecl) acdbEntLast(int modopt(IsLong)* modopt(IsConst) modopt(IsConst));
 
Declaring Type: <Module>
Assembly: acmgdinternal, Version=17.2.0.0



[**have patience grasshopper]
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.