using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using System.Runtime.InteropServices;
[assembly: CommandClass(typeof(Multiply_Nested_Select_Test.MyCommands))]
namespace Multiply_Nested_Select_Test
{
public class MyCommands
{
[CommandMethod("SelectNestedTest", CommandFlags.Modal)]
public void MyCommand()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
XrefGraph xg = db.GetHostDwgXrefGraph(true);
Point3d pt1 = new Point3d();
Point3d pt2 = new Point3d();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
SpecifySelectionWindow(out pt1, out pt2, db, ed);//Это метод для задания секущей рамки
/////////////////////////////////////////////////////////////////////////////
//Код выбора вложенных объектов рамкой
ResultBuffer resbuf = new ResultBuffer();
string arg = "_N:D";
IntPtr ptrPoint1 = Marshal.UnsafeAddrOfPinnedArrayElement(
pt1.ToArray(), 0);
IntPtr ptrPoint2 = Marshal.UnsafeAddrOfPinnedArrayElement(
pt2.ToArray(), 0);
ArxImports.ads_name sset;
PromptStatus prGetResult = ArxImports.acedSSGet(
arg, ptrPoint1, ptrPoint2, resbuf.UnmanagedObject, out sset);
int len;
ArxImports.acedSSLength(ref sset, out len);
ed.WriteMessage("\n" + len.ToString());
/////////////////////////////////////////////////////////////////////////////
tr.Commit();
}
}
private static bool SpecifySelectionWindow(out Point3d pt1, out Point3d pt2, Database db, Editor adocEd)
{
pt1 = new Point3d();
pt2 = new Point3d();
Transaction tr = db.TransactionManager.StartTransaction();
using (tr)
{
try
{
PromptPointOptions ppo = new PromptPointOptions("\n\tSpecify a first corner: ");
PromptPointResult ppr = adocEd.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return false;
PromptCornerOptions pco = new PromptCornerOptions("\n\tOther corner: ", ppr.Value);
PromptPointResult pcr = adocEd.GetCorner(pco);
if (pcr.Status != PromptStatus.OK) return false;
pt1 = ppr.Value;
pt2 = pcr.Value;
if (pt1.X == pt2.X || pt1.Y == pt2.Y)
{
adocEd.WriteMessage("\nInvalid point specification");
return false;
}
tr.Commit();
return true;
}
catch (System.Exception ex)
{
adocEd.WriteMessage(ex.Message + "\n" + ex.StackTrace);
return false;
}
}
}
}
//Класс в котором задаются методы для доступа к функциям ObjectARX, который я взял из примера
class ArxImports
{
public struct ads_name
{
public IntPtr a;
public IntPtr b;
};
[StructLayout(LayoutKind.Sequential, Size = 32)]
public struct resbuf { }
[DllImport("accore.dll",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
ExactSpelling = true)]
public static extern PromptStatus acedSSGet(
string str, IntPtr pt1, IntPtr pt2,
IntPtr filter, out ads_name ss);
[DllImport("accore.dll",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
ExactSpelling = true)]
public static extern PromptStatus acedSSFree(ref ads_name ss);
[DllImport("accore.dll",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
ExactSpelling = true)]
public static extern PromptStatus acedSSLength(
ref ads_name ss, out int len);
[DllImport("accore.dll",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Unicode,
ExactSpelling = true)]
public unsafe static extern PromptStatus acedSSNameX(
resbuf** rbpp, ref ads_name ss, int i);
}
}