/// <summary> /// Create a Revit Floor given it's curve outline and Level /// </summary> /// <param name="outline">The outline.</param> /// <param name="floorType">Type of the floor.</param> /// <param name="level">The level.</param> /// <param name="structural">if set to <c>true</c> [structural].</param> /// <returns> /// The floor /// </returns> public static SlopedFloor ByOutlineTypeAndLevel(Autodesk.DesignScript.Geometry.PolyCurve outline, Revit.Elements.FloorType floorType, Revit.Elements.Level level, bool structural) { Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel started...", "")); try { var profile = new CurveArray(); Autodesk.DesignScript.Geometry.Plane plane = Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints( outline.Curves().Cast <Autodesk.DesignScript.Geometry.Curve>().Select(x => x.StartPoint)); Vector normal = plane.Normal; if (normal.Dot(Vector.ZAxis()) <= 0) { normal = normal.Reverse(); } Autodesk.DesignScript.Geometry.Point origin = plane.Origin; Autodesk.DesignScript.Geometry.Point end = origin.Add(normal); Autodesk.DesignScript.Geometry.Point projection = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, -1000); end = Autodesk.DesignScript.Geometry.Point.ByCoordinates(end.X, end.Y, end.Z + 1000); Autodesk.DesignScript.Geometry.Point intersection = null; var result = plane.Intersect(Autodesk.DesignScript.Geometry .Line.ByStartPointEndPoint(end, projection)); if (result.Length > 0) { intersection = result[0] as Autodesk.DesignScript.Geometry.Point; } else { var message = "Couldn't find intersection"; Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", message)); throw new Exception(message); } Autodesk.DesignScript.Geometry.Curve temp = Autodesk.DesignScript.Geometry.Line.ByBestFitThroughPoints(new Autodesk.DesignScript.Geometry.Point[] { origin, intersection }); PolyCurve flat = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY() .Offset(temp.StartPoint.Z)).Explode().Cast <Autodesk.DesignScript.Geometry.Curve>().ToList()); Autodesk.DesignScript.Geometry.Curve flatLine = temp.PullOntoPlane(Autodesk.DesignScript.Geometry.Plane.XY().Offset(temp.StartPoint.Z)); if (Math.Abs(Math.Abs(plane.Normal.Dot(Vector.ZAxis())) - 1) < 0.00001) { var f = Revit.Elements.Floor.ByOutlineTypeAndLevel(flat, floorType, level); f.InternalElement.Parameters.Cast <Autodesk.Revit.DB.Parameter>() .First(x => x.Id.IntegerValue.Equals(Autodesk.Revit.DB.BuiltInParameter.FLOOR_PARAM_IS_STRUCTURAL)) .Set(structural ? 1 : 0); plane.Dispose(); flatLine.Dispose(); flat.Dispose(); origin.Dispose(); end.Dispose(); projection.Dispose(); intersection.Dispose(); temp.Dispose(); return(new SlopedFloor(f.InternalElement as Autodesk.Revit.DB.Floor)); } double slope = (temp.EndPoint.Z - temp.StartPoint.Z) / flatLine.Length; foreach (Autodesk.DesignScript.Geometry.Curve c in flat.Curves()) { profile.Append(c.ToRevitType()); } Autodesk.Revit.DB.Line slopeArrow = flatLine.ToRevitType() as Autodesk.Revit.DB.Line; var ft = floorType.InternalElement as Autodesk.Revit.DB.FloorType; var lvl = level.InternalElement as Autodesk.Revit.DB.Level; var floor = new SlopedFloor(profile, slopeArrow, slope, ft, lvl, structural); floor.Level = level; floor.Floortype = floorType; floor.Structural = structural; //DocumentManager.Regenerate(); plane.Dispose(); flatLine.Dispose(); flat.Dispose(); origin.Dispose(); end.Dispose(); projection.Dispose(); intersection.Dispose(); temp.Dispose(); Utils.Log(string.Format("SlopedFloor.ByOutlineTypeAndLevel completed.", "")); return(floor); } catch (Exception ex) { Utils.Log(string.Format("ERROR: SlopedFloor.ByOutlineTypeAndLevel {0}", ex.Message)); throw ex; } }
/// <summary> /// Create a Revit Floor given it's curve outline and Level /// </summary> /// <param name="outline"></param> /// <param name="floorType"></param> /// <param name="level"></param> /// <returns>The floor</returns> public static Floor ByOutlineTypeAndLevel(PolyCurve outline, FloorType floorType, Level level) { if (outline == null) { throw new ArgumentNullException("outline"); } if (floorType == null) { throw new ArgumentNullException("floorType"); } if ( level == null ) { throw new ArgumentNullException("level"); } if (!outline.IsClosed) { throw new ArgumentException("The input PolyCurve is not closed"); } var ca = new CurveArray(); outline.Curves().ForEach(x => ca.Append(x.ToRevitType())); return new Floor(ca, floorType.InternalFloorType, level.InternalLevel ); }
public static bool IsPolyline(this PolyCurve polycurve) { return(polycurve.Curves().All(c => c.IsLinear())); }