static public TrussInfo BuildTrussAtRidge(XYZ currentPointOnRidge, EdgeInfo currentEdgeInfo, IList <XYZ> currentSupportPoints) { TrussInfo trussInfo = null; XYZ currentTopPoint = currentEdgeInfo.GetTrussTopPoint(currentPointOnRidge); //If we cant get the point that means that the projection failed if (currentTopPoint == null) { return(trussInfo); } if (currentSupportPoints == null || currentSupportPoints.Count == 0) { currentSupportPoints = currentEdgeInfo.ProjectSupportPointsOnRoof(currentPointOnRidge); } if (currentSupportPoints.Count == 0) { if (currentEdgeInfo.RoofLineType != RoofLineType.Ridge) { return(trussInfo); } IList <EdgeInfo> endConditionList = currentEdgeInfo.GetEndConditions(1); if (endConditionList.Count != 2) { return(trussInfo); } EdgeInfo edge0 = endConditionList[0]; EdgeInfo edge1 = endConditionList[1]; if ((edge0.RoofLineType != RoofLineType.Valley && edge0.RoofLineType != RoofLineType.Gable) || edge1.RoofLineType != RoofLineType.Valley && edge1.RoofLineType != RoofLineType.Gable) { return(trussInfo); } Line line0 = edge0.Curve as Line; Line line1 = edge1.Curve as Line; if (line0 == null || line1 == null) { return(trussInfo); } double height = currentEdgeInfo.GetCurrentRoofHeight(); Line currentRigeLine = currentEdgeInfo.Curve as Line; XYZ rigePointFlatten = new XYZ(currentTopPoint.X, currentTopPoint.Y, height); XYZ intersectingPointValleyOrGable0 = GeometrySupport.GetRoofIntersectionFlattenLines(currentRigeLine, currentTopPoint, line0, height); XYZ intersectingPointValleyOrGable1 = GeometrySupport.GetRoofIntersectionFlattenLines(currentRigeLine, currentTopPoint, line1, height); if (intersectingPointValleyOrGable0 == null || intersectingPointValleyOrGable1 == null) { return(trussInfo); } //TODO Change this to the double of max distance between Trusses double maxDistance = 20; XYZ supportPoint0 = currentEdgeInfo.GetSupportPoint(intersectingPointValleyOrGable0, currentRigeLine.Direction, maxDistance); XYZ supportPoint1 = currentEdgeInfo.GetSupportPoint(intersectingPointValleyOrGable1, currentRigeLine.Direction, maxDistance); if (supportPoint0 == null || supportPoint1 == null) { return(trussInfo); } currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List <XYZ> { supportPoint0, supportPoint1 }, currentEdgeInfo); trussInfo = GeometrySupport.GetTrussInfo(currentTopPoint, supportPoint0, supportPoint1); if (trussInfo == null) { return(trussInfo); } return(trussInfo); } else if (currentSupportPoints.Count == 1) { if (currentEdgeInfo.RoofLineType != RoofLineType.RidgeSinglePanel) { return(trussInfo); } XYZ projectedPointOnEave = currentSupportPoints[0]; XYZ projectedPointOnRidge = new XYZ(currentTopPoint.X, currentTopPoint.Y, projectedPointOnEave.Z); currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List <XYZ> { projectedPointOnEave }, currentEdgeInfo); double height = currentTopPoint.DistanceTo(projectedPointOnRidge); trussInfo = new TrussInfo(projectedPointOnEave, projectedPointOnRidge, height); trussInfo.TopChords.Append(Line.CreateBound(currentTopPoint, projectedPointOnEave)); trussInfo.BottomChords.Append(Line.CreateBound(projectedPointOnRidge, projectedPointOnEave)); //Document doc = CurrentRoof.Document; //FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint2")).FirstOrDefault() as FamilySymbol; //doc.Create.NewFamilyInstance(projectedPointOnEave, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); //doc.Create.NewFamilyInstance(projectedPointOnRidge, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); //doc.Create.NewFamilyInstance(currentTopPoint, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); return(trussInfo); } else if (currentSupportPoints.Count == 2) { if (currentEdgeInfo.RoofLineType != RoofLineType.Ridge) { return(trussInfo); } XYZ firstPointOnEave = currentSupportPoints[0]; XYZ secondPointOnEave = currentSupportPoints[1]; if (firstPointOnEave == null || secondPointOnEave == null) { return(trussInfo); } currentTopPoint = GeometrySupport.AdjustTopPointToRoofAngle(currentTopPoint, new List <XYZ> { firstPointOnEave, secondPointOnEave }, currentEdgeInfo); trussInfo = GeometrySupport.GetTrussInfo(currentTopPoint, firstPointOnEave, secondPointOnEave); if (trussInfo == null) { return(trussInfo); } //Document doc = CurrentRoof.Document; //FamilySymbol fs = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_GenericModel).WhereElementIsElementType().Where(type => type.Name.Contains("DebugPoint2")).FirstOrDefault() as FamilySymbol; //doc.Create.NewFamilyInstance(firstPointOnEave, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); //doc.Create.NewFamilyInstance(secondPointOnEave, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); //doc.Create.NewFamilyInstance(currentTopPoint, fs, Autodesk.Revit.DB.Structure.StructuralType.NonStructural); return(trussInfo); } return(trussInfo); }
internal XYZ GetTrussTopPoint(XYZ currentPointOnRidge) { if (RoofLineType == RoofLineType.Ridge) { return(currentPointOnRidge); } //If the is not a Ridge this MUST be a SinglePanelRidge if (RoofLineType == RoofLineType.RidgeSinglePanel) { return(currentPointOnRidge); } Line currentRidgeLine = Curve.Clone() as Line; if (currentRidgeLine == null) { throw new Exception("The ridge is not a straight line!"); } ModelCurveArrArray sketchModels = CurrentRoof.GetProfiles(); double minDist = double.MaxValue; ModelCurve targetEave = null; XYZ projectedPoint = null; double currentRoofTotalHeight = GetCurrentRoofHeight(); foreach (ModelCurveArray currentCurveArr in sketchModels) { foreach (ModelCurve currentCurve in currentCurveArr) { Curve targetGeoCurve = currentCurve.GeometryCurve; Line targetGeoLine = targetGeoCurve as Line; if (targetGeoLine == null) { throw new Exception("Eave is not a straight line"); } targetGeoLine = targetGeoLine.Flatten(currentRoofTotalHeight); double currentDist = targetGeoLine.Project(currentPointOnRidge).Distance; if (currentDist < minDist) { minDist = currentDist; targetEave = currentCurve; projectedPoint = targetGeoLine.Project(currentPointOnRidge).XYZPoint; } } } double overHang = 0; try { overHang = CurrentRoof.get_Overhang(targetEave); } catch { } XYZ ridgePointFlatten = new XYZ(currentPointOnRidge.X, currentPointOnRidge.Y, currentRoofTotalHeight); //We just need to get the side that the eave is to move the point to that direction //so we dont need to get a specific eave, lets just project the first one with infinite bounds to get the direction if (RelatedRidgeEaves == null || RelatedRidgeEaves.Count == 0) { RelatedRidgeEaves = GetRelatedEaves(); } if (RelatedRidgeEaves == null || RelatedRidgeEaves.Count == 0) { throw new Exception("Related eave or eaves to current singleRidge was not found"); } Curve eaveCurve = RelatedRidgeEaves[0].AsCurve(); if (eaveCurve as Line == null) { throw new Exception("Related eave is not a straight line!"); } Line eaveLine = eaveCurve as Line; XYZ lineIntersectionPoint = GeometrySupport.GetRoofIntersectionFlattenLines(currentRidgeLine, ridgePointFlatten, eaveLine, currentRoofTotalHeight); if (lineIntersectionPoint == null) { throw new Exception("No Intersection between eave could be estabilished!"); } XYZ overHangdirection = Line.CreateBound(projectedPoint, lineIntersectionPoint).Direction.Normalize(); XYZ pointOnOverhang = projectedPoint.Add(overHangdirection.Multiply(overHang)); //We will get the point on the overhang because if we are working with a single panel ridge it may have overhangs XYZ pointOnSupport = GetSupportPoint(pointOnOverhang, currentRidgeLine.Direction.Normalize()); //Now we will shoot the point up on the Roof XYZ startingPoint = new XYZ(pointOnSupport.X, pointOnSupport.Y, pointOnSupport.Z - 1); ReferenceIntersector currentRefIntersect = new ReferenceIntersector(CurrentRoof.Id, FindReferenceTarget.Element, CurrentRoof.Document.ActiveView as View3D); ReferenceWithContext currenRefContext = currentRefIntersect.FindNearest(startingPoint, XYZ.BasisZ); if (currenRefContext == null) { return(null); } XYZ projectedPointOnRoof = currenRefContext.GetReference().GlobalPoint; return(projectedPointOnRoof); }