Author Topic: DllImport acedEntSel  (Read 3766 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
DllImport acedEntSel
« on: October 08, 2006, 04:52:03 AM »
Is it possible to use something like this to select entities in 2005?
Thanks

Code: [Select]
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl)]
extern static private int acedEntSel(string msg , ename , pt);

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: DllImport acedEntSel
« Reply #1 on: October 08, 2006, 01:38:38 PM »
Is it possible to use something like this to select entities in 2005?
In AutoCAD 2005 or Visual Studio 2005? :)

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: DllImport acedEntSel
« Reply #2 on: October 08, 2006, 02:28:07 PM »
Hi Alexander,

Sorry Acad 2005 and VS 2005, I am just having a heck of a time selecting a single entity and geting the objectId.

Thanks
Daniel

Alexander Rivilis

  • Bull Frog
  • Posts: 214
  • Programmer from Kyiv (Ukraine)
Re: DllImport acedEntSel
« Reply #3 on: October 08, 2006, 02:37:25 PM »
Code: [Select]
using System ;
using System.Runtime.InteropServices ;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.DatabaseServices ;
using Autodesk.AutoCAD.ApplicationServices ;
using Autodesk.AutoCAD.Geometry ;

[assembly: CommandClass(typeof(Rivilis.Entsel2005))]

namespace Rivilis
{
  public class Entsel2005
  {
    const int RTNORM = 5100; /* Request succeeded */
    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
    private static extern int acedEntSel(string prompt, long [] name, double [] pt);
    [DllImport("acdb16.dll", CallingConvention=CallingConvention.Cdecl)] 
    private static extern int acdbGetObjectId(ref ObjectId objId, long [] name);   

    [CommandMethod("Test")]
    static public void test()
    {
      long   [] ent = {0,0};
      double [] pt  = {0,0,0};
      if (acedEntSel("\nSelect entity: ", ent, pt) == RTNORM)
      {
        ObjectId id = new ObjectId();
        acdbGetObjectId(ref id, ent);
        CommandLinePrompts.Message("\nEntity name: " + id.OldId.ToString("x"));
        CommandLinePrompts.Message("\nHandle: "   + id.Handle.ToString());
        Document doc = Application.DocumentManager.MdiActiveDocument;
        using (Transaction tr = doc.TransactionManager.StartTransaction())
        {
          Entity en = tr.GetObject(id,OpenMode.ForRead) as Entity;
          if (en != null)
          {
            CommandLinePrompts.Message("\nEntity class: " + en.ToString());
            CommandLinePrompts.Message("\nPick Point: " + new Point3d(pt[0],pt[1],pt[2]).ToString());
          }
        }
      }
    }
  }
}

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: DllImport acedEntSel
« Reply #4 on: October 08, 2006, 03:13:01 PM »
Wow!
Thank you so much Alexander,
You have been so helpful to all of us!
Thanks again  :-)