Ok... I did some corrections, this one works on all the cases.
INTF = if does not find the intersection, select the faces in inverse sequence.
INTF2 = works in all cases.
Let me know if works for you.
edit: removed extraction of vertex 4 not required.
[CommandMethod("INTF", CommandFlags.Modal)]
public void cmd_intersFaces()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions peo = new PromptEntityOptions("");
peo.Message = "\n<Enter to exit>/Select first 3d face (to project)";
peo.SetRejectMessage("\n***Object must be a 3d face. \n");
peo.AddAllowedClass(typeof(Face), true);
peo.AllowNone = true;
PromptEntityResult per1 = ed.GetEntity(peo);
if (per1.Status != PromptStatus.OK) return;
peo.Message = "\n<Enter to exit>/Select second 3d face (projection plane)";
PromptEntityResult per2 = ed.GetEntity(peo);
if (per2.Status != PromptStatus.OK) return;
Point3dCollection points = new Point3dCollection();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;
Face faceProject = tr.GetObject(per1.ObjectId, OpenMode.ForWrite, false) as Face;
Face facePlane = tr.GetObject(per2.ObjectId, OpenMode.ForWrite, false) as Face;
Point3d p1, p2, p3;
p1 = facePlane.GetVertexAt(0);
p2 = facePlane.GetVertexAt(1);
p3 = facePlane.GetVertexAt(2);
Vector3d vU = p2.GetAsVector() - p1.GetAsVector();
Vector3d vV = p3.GetAsVector() - p1.GetAsVector();
Plane projectionPlane = new Plane(p1, vU, vV);
facePlane.IntersectWith(faceProject, Intersect.ExtendArgument, projectionPlane, points, 0, 0);
#region debug print message and points
ed.WriteMessage("\nPoints count: {0} \n", points.Count.ToString());
foreach (Point3d pt in points)
{
DBPoint point = new DBPoint();
point.Position = pt;
btr.AppendEntity(point);
tr.AddNewlyCreatedDBObject(point, true);
}
#endregion
tr.Commit();
}
}
[CommandMethod("INTF2", CommandFlags.Modal)]
public void cmd_intersFaces2()
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
PromptEntityOptions peo = new PromptEntityOptions("");
peo.Message = "\n<Enter to exit>/Select first 3d face (to project)";
peo.SetRejectMessage("\n***Object must be a 3d face. \n");
peo.AddAllowedClass(typeof(Face), true);
peo.AllowNone = true;
PromptEntityResult per1 = ed.GetEntity(peo);
if (per1.Status != PromptStatus.OK) return;
peo.Message = "\n<Enter to exit>/Select second 3d face (projection plane)";
PromptEntityResult per2 = ed.GetEntity(peo);
if (per2.Status != PromptStatus.OK) return;
Point3dCollection points = new Point3dCollection();
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, false) as BlockTableRecord;
Face faceProject = tr.GetObject(per1.ObjectId, OpenMode.ForWrite, false) as Face;
Face facePlane = tr.GetObject(per2.ObjectId, OpenMode.ForWrite, false) as Face;
Point3d p1, p2, p3;
p1 = facePlane.GetVertexAt(0);
p2 = facePlane.GetVertexAt(1);
p3 = facePlane.GetVertexAt(2);
Vector3d vU = p2.GetAsVector() - p1.GetAsVector();
Vector3d vV = p3.GetAsVector() - p1.GetAsVector();
Plane projectionPlane = new Plane(p1, vU, vV);
facePlane.IntersectWith(faceProject, Intersect.ExtendArgument, projectionPlane, points, 0, 0);
if (points.Count == 0)
{
p1 = faceProject.GetVertexAt(0);
p2 = faceProject.GetVertexAt(1);
p3 = faceProject.GetVertexAt(2);
vU = p2.GetAsVector() - p1.GetAsVector();
vV = p3.GetAsVector() - p1.GetAsVector();
projectionPlane = new Plane(p1, vU, vV);
faceProject.IntersectWith(facePlane, Intersect.ExtendArgument, projectionPlane, points, 0, 0);
}
#region debug print message and points
ed.WriteMessage("\nPoints count: {0} \n", points.Count.ToString());
foreach (Point3d pt in points)
{
DBPoint point = new DBPoint();
point.Position = pt;
btr.AppendEntity(point);
tr.AddNewlyCreatedDBObject(point, true);
}
#endregion
tr.Commit();
}
}