public static void ductIntersectWall(ExternalCommandData cmd)
{
UIApplication uiapp = cmd.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Autodesk.Revit.DB.Document CachedDoc = uidoc.Document;
{
FilteredElementCollector WallCollector = new FilteredElementCollector(CachedDoc);
WallCollector.OfClass(typeof(Wall));
List<Wall> walls = WallCollector.Cast<Wall>().ToList();// หา กำแพง
FilteredElementCollector DuctCollector = new FilteredElementCollector(CachedDoc);
DuctCollector.OfClass(typeof(Duct)); // หา Duct
List<Duct> ducts = DuctCollector.Cast<Duct>().ToList();
List<XYZ> points = new List<XYZ>();
foreach (Duct d in ducts)
{
foreach (Wall w in walls)
{
LocationCurve lc = d.Location as LocationCurve;
Curve ductCurve = lc.Curve; // แต่ละ Duct หา เป็น เส้นCurve
XYZ intersection = null;
List<Face> wallFaces = FindWallFace(w); // หา หน้า Face ของกำแพง
foreach (Face f in wallFaces)
{
intersection = FindFaceCurve(ductCurve, f); // หาจุดตัด Face กับ เส้น duct
if (null != intersection)
points.Add(intersection);
}
}
}
StringBuilder sb = new StringBuilder();
foreach (XYZ p in points)
{
sb.AppendLine(p.ToString()); // เก็บ ไปแสดงค่าจุดตัด
}
TaskDialog.Show("duct inter wall(ft)", sb.ToString());
}
}
// support function
public static List<Face> FindWallFace(Wall wall)
{
List<Face> normalFaces = new List<Face>();
Options opt = new Options();
opt.ComputeReferences = true;
opt.DetailLevel = ViewDetailLevel.Fine;
GeometryElement e = wall.get_Geometry(opt);
foreach (GeometryObject obj in e)
{
Solid solid = obj as Solid;
if (solid != null && solid.Faces.Size > 0)
{
foreach (Face face in solid.Faces)
{
PlanarFace pf = face as PlanarFace;
if (pf != null)
{
normalFaces.Add(pf);
}
}
}
}
return normalFaces;
}
public static XYZ FindFaceCurve(Curve DuctCurve, Face WallFace)
{
//The intersection point
IntersectionResultArray intersectionR = new IntersectionResultArray();//Intersection point set
SetComparisonResult results;//Results of Comparison
results = WallFace.Intersect(DuctCurve, out intersectionR);
XYZ intersectionResult = null;//Intersection coordinate
if (SetComparisonResult.Disjoint != results)
{
if (intersectionR != null)
{
if (!intersectionR.IsEmpty)
{
intersectionResult = intersectionR.get_Item(0).XYZPoint;
}
}
}
return intersectionResult;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น