Lead: http://www.objectarx.net/bbs/archiver? Tid-410.html
Using System;
Using System. Collections. Generic;
Using System. text;
Using Autodesk. AutoCAD. applicationservices;
Using Autodesk. AutoCAD. colors;
Using Autodesk. AutoCAD. databaseservices;
Using Autodesk. AutoCAD. editorinput;
Using Autodesk. AutoCAD. geometry;
Using Autodesk. AutoCAD. runtime;
Using Asapp = Autodesk. AutoCAD. applicationservices. Application;
Using Dstm = Autodesk. AutoCAD. databaseservices. transactionmanager;
Using Autodesk. AutoCAD. graphicsinterface;
Using Autodesk. AutoCAD. InterOP;
Namespace Objectarxnet. Test
{
/**/ /// <Summary>
///Intersection of two spatial Curves
/// </Summary>
Public Class Intersection
{
[Commandmethod ( " Intersectiontest " )]
Public Void Intersectiontest ()
{
Editor m_ed = Application. documentmanager. mdiactivedocument. Editor;
Database m_db = Hostapplicationservices. workingdatabase;
Promptentityoptions m_peo = New Promptentityoptions ( " \ N select the first curve: " );
Promptentityresult m_per = M_ed.getentity (m_peo );
If (M_per.status ! = Promptstatus. OK) {Return;}
Objectid m_objid1 = M_per.objectid;
M_peo = New Promptentityoptions ( " \ N select the second curve: " );
M_per = M_ed.getentity (m_peo );
If (M_per.status ! = Promptstatus. OK) {Return;}
Objectid m_objid2 = M_per.objectid;
Using (Transaction m_tr = M_db.transactionmanager.starttransaction ())
{
Curve m_cur1 = (Curve) m_tr.getobject (m_objid1, openmode. forread );
Curve m_cur2 = (Curve) m_tr.getobject (m_objid2, openmode. forread );
Point3dcollection m_ints = New Point3dcollection ();
M_cur1.intersectwith (m_cur2, Intersect. onbothoperands, New Plane (), m_ints, 0 , 0 ); // All the knots obtained are on the C1 curve.
Foreach (Point3d m_pt In M_ints)
{
M_ed.writemessage ("\ N intersection of the first curve and the second curve: {0}", M_pt );
}
M_ed.writemessage ( " \ N = " );
M_ints.clear ();
M_cur2.intersectwith (m_cur1, Intersect. onbothoperands, New Plane (), m_ints, 0 , 0 ); // All the knots obtained are on the C2 curve.
Foreach (Point3d m_pt In M_ints)
{
M_ed.writemessage ("\ N intersection of the second curve and the first curve: {0}", M_pt );
}
M_tr.commit ();
}
}
}
}