private void CreateHiddenButterflyRoof(CurveArray footPrint, double slope, XYZ slopeDirection) { Polygon roofPolygon = new Polygon(footPrint); List <Line> cutLines = new List <Line>(); XYZ divisionDirection = new XYZ(-slopeDirection.Y, slopeDirection.X, 0); List <CurveArray> convexFootPrint = roofPolygon.DividePolygonInHalf(divisionDirection, out Line cutLine); cutLines.Add(cutLine); foreach (CurveArray curveArray in convexFootPrint) { // get a roof type FilteredElementCollector collector = new FilteredElementCollector(document); collector.OfClass(typeof(RoofType)); RoofType roofType = collector.FirstElement() as RoofType; // create the foot print of the roof ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray(); FootPrintRoof footPrintRoof = document.Create.NewFootPrintRoof(curveArray, roofLevel, roofType, out footPrintToModelCurveMapping); // apply the slope for the cutLines ModelCurveArrayIterator iterator = footPrintToModelCurveMapping.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { ModelCurve modelCurve = iterator.Current as ModelCurve; Curve curve = modelCurve.GeometryCurve; if (VerifyIntersectionInArray(curve, cutLines)) { footPrintRoof.set_DefinesSlope(modelCurve, true); footPrintRoof.set_SlopeAngle(modelCurve, slope); } } } CreateParapetWall(footPrint); }
/// <summary> /// Aplies the slope in a determined FootPrintRoof. /// </summary> /// <param name="overhang">The overhang value.</param> /// <param name="slope">The slope of the roof</param> /// <param name="slopeDirection">The vector that represents the directions that the slope should be applied.</param> /// <param name="footPrintRoof">The Roof</param> /// <param name="footPrintToModelCurveMapping">The ModelCurveArray generated with the roof instance.</param> private static void ApplySlope(double overhang, double slope, XYZ slopeDirection, FootPrintRoof footPrintRoof, ModelCurveArray footPrintToModelCurveMapping) { ModelCurveArrayIterator iterator = footPrintToModelCurveMapping.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { ModelCurve modelCurve = iterator.Current as ModelCurve; Curve curve = modelCurve.GeometryCurve; XYZ curveDirection = VectorManipulator.GetCurveDirection(curve); if (curveDirection.DotProduct(slopeDirection) == 0) { footPrintRoof.set_DefinesSlope(modelCurve, true); footPrintRoof.set_SlopeAngle(modelCurve, slope); } double elevation = -(overhang - UnitUtils.ConvertToInternalUnits(0.1, UnitTypeId.Meters)) / 3; footPrintRoof.set_Offset(modelCurve, elevation); } }
void f(Document doc) { // Before invoking this sample, select some walls // to add a roof over. Make sure there is a level // named "Roof" in the document. Level level = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .Where <Element>(e => !string.IsNullOrEmpty(e.Name) && e.Name.Equals("Roof")) .FirstOrDefault <Element>() as Level; RoofType roofType = new FilteredElementCollector(doc) .OfClass(typeof(RoofType)) .FirstOrDefault <Element>() as RoofType; // Get the handle of the application Application application = doc.Application; // Define the footprint for the roof based on user selection CurveArray footprint = application.Create .NewCurveArray(); UIDocument uidoc = new UIDocument(doc); ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds(); if (selectedIds.Count != 0) { foreach (ElementId id in selectedIds) { Element element = doc.GetElement(id); Wall wall = element as Wall; if (wall != null) { LocationCurve wallCurve = wall.Location as LocationCurve; footprint.Append(wallCurve.Curve); continue; } ModelCurve modelCurve = element as ModelCurve; if (modelCurve != null) { footprint.Append(modelCurve.GeometryCurve); } } } else { throw new Exception( "Please select a curve loop, wall loop or " + "combination of walls and curves to " + "create a footprint roof."); } ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray(); FootPrintRoof footprintRoof = doc.Create.NewFootPrintRoof( footprint, level, roofType, out footPrintToModelCurveMapping); ModelCurveArrayIterator iterator = footPrintToModelCurveMapping.ForwardIterator(); iterator.Reset(); while (iterator.MoveNext()) { ModelCurve modelCurve = iterator.Current as ModelCurve; footprintRoof.set_DefinesSlope(modelCurve, true); footprintRoof.set_SlopeAngle(modelCurve, 0.5); } }
public Result setup_roof() { FilteredElementCollector collector = new FilteredElementCollector(doc); collector.OfClass(typeof(RoofType)); RoofType roofType = collector.FirstElement() as RoofType; Transaction trans = new Transaction(doc); string jsonFilePath = @"C:\Users\John\AppData\Roaming\Autodesk\Revit\Addins\2019\data.json"; List <mylevels> items; List <XYZ[]> coords = new List <XYZ[]>(); using (StreamReader r = new StreamReader(jsonFilePath)) { string json = r.ReadToEnd(); items = JsonConvert.DeserializeObject <List <mylevels> >(json); } List <int> slopes = new List <int>(); int i; foreach (mylevels l in items) { if (l.level == level.Name) { dataset = l.sets; } } foreach (mysets s in dataset) { if (s.type == "roof") { using (trans = new Transaction(doc)) { trans.Start("roof"); CurveArray footprint = new CurveArray(); Level roof_level = level; if (s.base_level != null) { roof_level = new FilteredElementCollector(doc) .OfClass(typeof(Level)) .Cast <Level>().FirstOrDefault(q => q.Name == s.base_level); } walls p = null; foreach (walls w in s.walls) { XYZ a = w.coords[0] is null ? new XYZ(p.coords[1][0] / 12.0, p.coords[1][1] / 12.0, roof_level.Elevation) : new XYZ(w.coords[0][0] / 12.0, w.coords[0][1] / 12.0, roof_level.Elevation); XYZ b = new XYZ(w.coords[1][0] / 12.0, w.coords[1][1] / 12.0, roof_level.Elevation); Line line = Line.CreateBound(a, b); footprint.Append(line); p = w; } ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray(); FootPrintRoof footprintRoof = doc.Create.NewFootPrintRoof(footprint, roof_level, roofType, out footPrintToModelCurveMapping); ModelCurveArrayIterator iterator = footPrintToModelCurveMapping.ForwardIterator(); iterator.Reset(); i = 0; while (iterator.MoveNext()) { ModelCurve modelCurve = iterator.Current as ModelCurve; if (s.walls[i].define_slope) { footprintRoof.set_DefinesSlope(modelCurve, true); // footprintRoof.set_SlopeAngle(modelCurve, 0.5); } if (s.walls[i].roof_offset != 0) { footprintRoof.set_Offset(modelCurve, s.walls[i].roof_offset / 12.0); } i++; } trans.Commit(); } } } return(Result.Succeeded); }