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