[code]
using System ;
using System.Collections;
using Autodesk.AutoCAD.Runtime ;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(ClassLibrary.Class))]
namespace ClassLibrary
{
public class Class
{
[CommandMethod("IntPoly3d")]
static public void IntPoly3d()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Polyline3d pl1 = SelectPoly3d("\nSelect first Polyline3d: ");
if (pl1 == null) return;
Polyline3d pl2 = SelectPoly3d("\nSelect second Polyline3d: ");
if (pl2 == null) return;
// We can project our plines in direction of Z axis of WCS,
// but you can use another project plane
Vector3d dir = new Vector3d(0,0,1);
Point3d orig = new Point3d (0,0,0);
// Plane of WCS
Plane planeWCS = new Plane(orig, dir);
Curve pl1_prj = pl1.GetProjectedCurve(planeWCS,dir); pl1.Dispose();
Curve pl2_prj = pl2.GetProjectedCurve(planeWCS,dir); pl2.Dispose();
Point3dCollection pts = new Point3dCollection();
pl1_prj.IntersectWith(pl2_prj,Intersect.OnBothOperands,pts,0,0);
if (pts.Count > 0)
{
ed.WriteMessage("\nNumber of intersection: {0}",pts.Count);
foreach (Point3d pt in pts) ed.WriteMessage("\n Point: {0}",pt);
}
else
{
ed.WriteMessage("\nNo intersection!");
}
pl1_prj.Dispose(); pl2_prj.Dispose();
}
static private Polyline3d SelectPoly3d(string str)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
PromptEntityResult rs = ed.GetEntity(str);
if (rs.Status == PromptStatus.OK)
{
Transaction trans = db.TransactionManager.StartTransaction();
Entity ent = (Entity)trans.GetObject(rs.ObjectId, OpenMode.ForRead);
Polyline3d pl = ent as Polyline3d;
trans.Commit();
if (pl == null) ed.WriteMessage("\nIt is not Polyline3d!");
return pl;
}
return null;
}
}
}
[/code]