using System;
using System.Reflection;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using AcGe = Autodesk.AutoCAD.Geometry;
//////////////////////////////////////////////////////////////////////////
// Необходимо подключить ссылку на AcMPolygonMGD.dll !!!
//////////////////////////////////////////////////////////////////////////
[assembly: CommandClass(typeof(MakeContour.MyCommands))]
namespace MakeContour
{
public class MyCommands
{
static MyCommands()
{
AcRx.SystemObjects.DynamicLinker.LoadModule("AcMPolygonObj" + AcAp.Application.Version.Major + ".dbx", false, false);
}
[CommandMethod("TestPointInContour")]
public void TestPointInContour()
{
AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument;
AcDb.Database db = doc.Database;
AcEd.Editor ed = doc.Editor;
AcEd.PromptPointOptions pr = new AcEd.PromptPointOptions("\nУкажите точку: ");
AcEd.PromptPointResult res = ed.GetPoint(pr);
if (res.Status != AcEd.PromptStatus.OK) return;
AcEd.PromptEntityOptions pre = new AcEd.PromptEntityOptions("\nУкажите контур: ");
pre.SetRejectMessage("Это не контур (полилиния)");
pre.AddAllowedClass(typeof(AcDb.Polyline), true);
AcEd.PromptEntityResult rese = ed.GetEntity(pre);
if (rese.Status != AcEd.PromptStatus.OK) return;
using (AcDb.MPolygon mp = new AcDb.MPolygon()) {
using (AcDb.Polyline poly = rese.ObjectId.Open(AcDb.OpenMode.ForRead) as AcDb.Polyline) {
try {
mp.AppendLoopFromBoundary(poly, true, AcGe.Tolerance.Global.EqualPoint);
if (mp.IsPointOnLoopBoundary(res.Value, 0, AcGe.Tolerance.Global.EqualPoint)) {
ed.WriteMessage("\nТочка на границе контура!");
} else if (mp.IsPointInsideMPolygon(res.Value, AcGe.Tolerance.Global.EqualPoint).Count > 0) {
ed.WriteMessage("\nТочка внутри контура!");
} else {
ed.WriteMessage("\nТочка вне контура!");
}
} catch { }
}
}
}
}
}