/// <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); } }
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); }