using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(PolyInters.Utils))]
namespace PolyInters
{
public class Utils
{
[CommandMethod("GetInters", CommandFlags.Modal)]
public void GetInters()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
if (doc == null) return;
Editor ed = doc.Editor;
PromptEntityOptions pr3d =
new PromptEntityOptions("\nВыберите 3d-полилинию: ");
pr3d.SetRejectMessage("Это не 3d-полилиния!");
pr3d.AddAllowedClass(typeof(Polyline3d), false);
PromptEntityResult rs3d = ed.GetEntity(pr3d);
if (rs3d.Status != PromptStatus.OK) return;
PromptEntityOptions pr2d =
new PromptEntityOptions("\nВыберите 2d-полилинию: ");
pr2d.SetRejectMessage("Это не 2d-полилиния!");
pr2d.AddAllowedClass(typeof(Polyline2d), false);
pr2d.AddAllowedClass(typeof(Polyline), false);
PromptEntityResult rs2d = ed.GetEntity(pr2d);
if (rs2d.Status != PromptStatus.OK) return;
#pragma warning disable 0618
using (Polyline3d p3d = rs3d.ObjectId.Open(OpenMode.ForRead) as Polyline3d)
using (Curve p2d = rs2d.ObjectId.Open(OpenMode.ForRead) as Curve)
#pragma warning restore 0618
{
Plane pl = new Plane(Point3d.Origin, Vector3d.ZAxis);
using (Curve3d c3d = p3d.GetGeCurve())
using (Curve3d c2d = p2d.GetGeCurve())
{
// Проецируем обе кривые на плоскость X0Y
using (Curve3d c3dProject = c3d.GetOrthoProjectEntity(pl) as Curve3d)
using (Curve3d c2dProject = c2d.GetOrthoProjectEntity(pl) as Curve3d)
{
using (CurveCurveIntersector3d cInt =
new CurveCurveIntersector3d(c3dProject, c2dProject, Vector3d.ZAxis))
{
int nInt = cInt.NumberOfIntersectionPoints;
if (nInt > 0)
{
cInt.OrderWithRegardsTo1(); // Упорядочиваем точки по 3d-полиниии
for (int i = 0; i < nInt; i++)
{
if (cInt.IsTransversal(i)) // Это пересечение, а не касание
{
Point3d pnt2d = cInt.GetIntersectionPoint(i);
// Вертикальная линия
using (Line3d line = new Line3d(pnt2d, Vector3d.ZAxis))
{
// Находим проекцию точки пересечения на 3D-полилинию
using (CurveCurveIntersector3d cIntVert =
new CurveCurveIntersector3d(c3d, line, Vector3d.ZAxis))
{
if (cIntVert.NumberOfIntersectionPoints > 0)
{
Point3d pnt3d = cIntVert.GetIntersectionPoint(0);
ed.WriteMessage("\nТочка пересечения {0} = {1}", i, pnt3d);
}
}
}
}
}
}
else
{
ed.WriteMessage("\nПересечений не нашли...");
}
}
}
}
}
}
}
}