/// <summary> /// Creates a Conduit by a curve. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="curve">The curve.</param> /// <returns></returns> public static Conduit ByCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve) { Utils.Log(string.Format("Conduit.ByCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Conduit.ByCurve completed.", "")); return(new Conduit(oType, s, e)); }
/// <summary> /// Initialize a floor element /// </summary> private void InitFloor(CurveArray curveArray, Autodesk.Revit.DB.FloorType floorType, Autodesk.Revit.DB.Level level, Autodesk.Revit.DB.Line slopeArrow, double slope, bool structural) { Document doc = DocumentManager.Instance.CurrentDBDocument; TransactionManager.Instance.EnsureInTransaction(doc); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(doc); } Autodesk.Revit.DB.Floor floor = null; if (floorType.IsFoundationSlab) { // Foundation Slabs require that the profile curves are planar and horizontal // The normal must be orthogonal to the profile, hence the only possible normal is the Z Axis floor = doc.Create.NewFoundationSlab(curveArray, floorType, level, structural, XYZ.BasisZ); } else { // we assume the floor is not structural here, this may be a bad assumption floor = doc.Create.NewSlab(curveArray, level, slopeArrow, slope, structural); floor.ChangeTypeId(floorType.Id); } InternalSetFloor(floor); TransactionManager.Instance.TransactionTaskDone(); ElementBinder.CleanupAndSetElementForTrace(doc, InternalFloor); }
/// <summary> /// Creates a pipe by curve. /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="pipingSystemType">Type of the piping system.</param> /// <param name="curve">The curve.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Pipe ByCurve(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, Autodesk.DesignScript.Geometry.Curve curve, Revit.Elements.Level level) { Utils.Log(string.Format("Pipe.ByCurve started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var totalTransform = RevitUtils.DocumentTotalTransform(); var start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); var end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Pipe.ByCurve completed.", "")); return(new Pipe(oType, oSystemType, s, e, l)); }
/// <summary> /// Converts the MultiPoint into an adaptive component of the specified type. /// </summary> /// <param name="familyType">Type of the family.</param> /// <returns></returns> public AdaptiveComponent ToAdaptiveComponent(FamilyType familyType) { Utils.Log(string.Format("MultiPoint.ToAdaptiveComponent started...", "")); AdaptiveComponent output = null; try { if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } output = AdaptiveComponent.ByPoints(new Point[][] { this.ShapePoints.Points.Select(p => p.RevitPoint).ToArray() }, familyType)[0]; output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, this.SerializeJSON()); output.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); output.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); } catch (Exception ex) { Utils.Log(ex.Message); } Utils.Log(string.Format("MultiPoint.ToAdaptiveComponent completed.", "")); return(output); }
/// <summary> /// Creates a Conduit by a curve. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="curve">The curve.</param> /// <param name="featureline">The featureline.</param> /// <returns></returns> public static Conduit ByCurveFeatureline(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline) { Utils.Log(string.Format("Conduit.ByCurveFeatureline started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var pipe = Conduit.ByCurve(conduitType, curve); // new Conduit(oType, s, e); var start = curve.StartPoint; var end = curve.EndPoint; var startSOE = featureline.GetStationOffsetElevationByPoint(start); var endSOE = featureline.GetStationOffsetElevationByPoint(end); double startStation = (double)startSOE["Station"]; double startOffset = (double)startSOE["Offset"]; double startElevation = (double)startSOE["Elevation"]; double endStation = (double)endSOE["Station"]; double endOffset = (double)endSOE["Offset"]; double endElevation = (double)endSOE["Elevation"]; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } Utils.Log(string.Format("Conduit.ByCurveFeatureline completed.", "")); return(pipe); }
/// <summary> /// Creates a pipe by two points. /// </summary> /// <param name="ductType">Type of the duct.</param> /// <param name="mechanicalSystemType">Type of the mechanical system.</param> /// <param name="start">The start.</param> /// <param name="end">The end.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Duct ByPoints(Revit.Elements.Element ductType, Revit.Elements.Element mechanicalSystemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("Duct.ByPoints started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = ductType.InternalElement as Autodesk.Revit.DB.Mechanical.DuctType; var oSystemType = mechanicalSystemType.InternalElement as Autodesk.Revit.DB.Mechanical.MechanicalSystemType; start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; totalTransform.Dispose(); Utils.Log(string.Format("Duct.ByPoints completed.", "")); return(new Duct(oType, oSystemType, s, e, l)); }
/// <summary> /// Creates a CableTray by two Points. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="start">The start Point in WCS.</param> /// <param name="end">The end Point in WCS.</param> /// <returns></returns> public static CableTray ByPoints(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end) { Utils.Log(string.Format("CableTray.ByPoints started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; var totalTransform = RevitUtils.DocumentTotalTransform(); var nstart = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = nstart.ToXyz(); var nend = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = nend.ToXyz(); TransactionManager.Instance.TransactionTaskDone(); if (nstart != null) { nstart.Dispose(); } if (nend != null) { nend.Dispose(); } Utils.Log(string.Format("CableTray.ByPoints completed.", "")); return(new CableTray(oType, s, e)); }
/// <exclude /> private Element ToHorizontalFloor(FloorType floorType, Level level) { Utils.Log(string.Format("MultiPoint.ToHorizontalFloor started...", "")); try { if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } PolyCurve outline = PolyCurve.ByPoints(this.ShapePoints.Points.Select(p => p.RevitPoint).ToList(), true); outline = PolyCurve.ByJoinedCurves(outline.PullOntoPlane(Plane.XY()).Explode().Cast <Curve>().ToList()); var output = Floor.ByOutlineTypeAndLevel(outline, floorType, level); output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, SerializeJSON()); Utils.Log(string.Format("MultiPoint.ToHorizontalFloor completed.", "")); return(output); } catch (Exception ex) { Utils.Log(string.Format("ERROR: MultiPoint.ToHorizontalFloor {0}", ex.Message)); throw ex; } }
/// <summary> /// Creates a CableTray using the start and end points of a curve. /// </summary> /// <param name="cableTrayType">The CableTray Type.</param> /// <param name="curve">The Curve</param> /// <returns></returns> public static CableTray ByCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Curve curve) { if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } return(CableTrayByCurve(cableTrayType, curve)); }
/// <summary> /// Creates a pipe by curve. /// </summary> /// <param name="ductType">Type of the duct.</param> /// <param name="mechanicalSystemType">Type of the mechanical system.</param> /// <param name="level">The level.</param> /// <param name="curve">The curve.</param> /// <param name="featureline">The featureline.</param> /// <returns></returns> public static Duct ByCurveFeatureline(Revit.Elements.Element ductType, Revit.Elements.Element mechanicalSystemType, Revit.Elements.Level level, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline) { Utils.Log(string.Format("Duct.ByCurveFeatureline started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = ductType.InternalElement as Autodesk.Revit.DB.Mechanical.DuctType; var oSystemType = mechanicalSystemType.InternalElement as Autodesk.Revit.DB.Mechanical.MechanicalSystemType; var start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); var end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; var pipe = new Duct(oType, oSystemType, s, e, l); var startSOE = featureline.GetStationOffsetElevationByPoint(curve.StartPoint); var endSOE = featureline.GetStationOffsetElevationByPoint(curve.EndPoint); double startStation = (double)startSOE["Station"]; double startOffset = (double)startSOE["Offset"]; double startElevation = (double)startSOE["Elevation"]; double endStation = (double)endSOE["Station"]; double endOffset = (double)endSOE["Offset"]; double endElevation = (double)endSOE["Elevation"];; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 totalTransform.Dispose(); Utils.Log(string.Format("Duct.ByCurveFeatureline completed.", "")); return(pipe); }
/// <summary> /// Converts the MultiPoint into a floor of the specified type. /// </summary> /// <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></returns> public Element ToFloor(FloorType floorType, Level level, bool structural = true) { Utils.Log(string.Format("MultiPoint.ToFloor started...", "")); try { if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } PolyCurve outline = PolyCurve.ByPoints(this.ShapePoints.Points.Select(p => p.RevitPoint).ToList(), true); if (null == outline) { System.Windows.Forms.MessageBox.Show("Outline is null"); } Element output = null; try { output = SlopedFloor.ByOutlineTypeAndLevel(outline, floorType, level, structural); } catch (Exception ex) { Utils.Log(string.Format("ERROR: MultiPoint.ToFloor {0}", ex.Message)); output = Floor.ByOutlineTypeAndLevel(outline, floorType, level); } output.SetParameterByName(ADSK_Parameters.Instance.MultiPoint.Name, this.SerializeJSON()); output.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); output.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); Utils.Log(string.Format("MultiPoint.ToFloor completed.", "")); return(output); } catch (Exception ex) { Utils.Log(string.Format("ERROR: MultiPoint.ToFloor {0}", ex.Message)); throw ex; } }
/// <summary> /// CableTray by curve. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="curve">The curve.</param> /// <param name="featureline">The featureline.</param> /// <returns>Associates the CableTray to a Featureline.</returns> public static CableTray ByCurveFeatureline(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline) { Utils.Log(string.Format("CableTray.ByCurveFeatureline started...", "")); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var pipe = CableTrayByCurve(cableTrayType, curve); var startSOE = featureline.GetStationOffsetElevationByPoint(curve.StartPoint); var endSOE = featureline.GetStationOffsetElevationByPoint(curve.EndPoint); double startStation = (double)startSOE["Station"]; double startOffset = (double)startSOE["Offset"]; double startElevation = (double)startSOE["Elevation"]; double endStation = (double)endSOE["Station"]; double endOffset = (double)endSOE["Offset"]; double endElevation = (double)endSOE["Elevation"]; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start); // 1.1.0 pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0 Utils.Log(string.Format("CableTray.ByCurveFeatureline completed.", "")); return(pipe); }
/// <summary> /// Creates a Conduit by two points. /// </summary> /// <param name="conduitType">Type of the conduit.</param> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> /// <returns></returns> public static Conduit ByPoints(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end) { Utils.Log(string.Format("Conduit.ByPoints started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); totalTransform.Dispose(); Utils.Log(string.Format("Conduit.ByPoints completed.", "")); return(new Conduit(oType, s, e)); }
/// <summary> /// CableTray by curve. /// </summary> /// <param name="cableTrayType">Type of the cable tray.</param> /// <param name="curve">The curve.</param> /// <returns>It Uses the start and end Points of the curve to create the CableTray</returns> private static CableTray CableTrayByCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Curve curve) { Utils.Log(string.Format("CableTray.CableTrayByCurve started...", "")); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.CableTrayByCurve completed.", "")); return(new CableTray(oType, s, e)); }
/// <summary> /// Creates a pipe by two points. /// </summary> /// <param name="pipeType">Type of the pipe.</param> /// <param name="pipingSystemType">Type of the piping system.</param> /// <param name="start">The start point.</param> /// <param name="end">The end point.</param> /// <param name="level">The level.</param> /// <returns></returns> public static Pipe ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level) { Utils.Log(string.Format("Pipe.ByPoints started...", "")); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var totalTransform = RevitUtils.DocumentTotalTransform(); start = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = end.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); var l = level.InternalElement as Autodesk.Revit.DB.Level; totalTransform.Dispose(); Utils.Log(string.Format("Pipe.ByPoints completed.", "")); return(new Pipe(oType, oSystemType, s, e, l)); }
public static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element pipeType, Revit.Elements.Element pipingSystemType, PolyCurve polyCurve, Revit.Elements.Level level, double maxLength, Featureline featureline) { Utils.Log(string.Format("Pipe.ByPolyCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); var totalTransformInverse = totalTransform.Inverse(); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType; var oSystemType = pipingSystemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType; var l = level.InternalElement as Autodesk.Revit.DB.Level; double length = polyCurve.Length; int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Plumbing.Pipe p = Autodesk.Revit.DB.Plumbing.Pipe.CreatePlaceholder(DocumentManager.Instance.CurrentDBDocument, oSystemType.Id, oType.Id, l.Id, s, e); ids.Add(p.Id); } var pipeIds = Autodesk.Revit.DB.Plumbing.PlumbingUtils.ConvertPipePlaceholders(DocumentManager.Instance.CurrentDBDocument, ids); TransactionManager.Instance.TransactionTaskDone(); DocumentManager.Instance.CurrentDBDocument.Regenerate(); Pipe[] pipes = GetPipesByIds(pipeIds); foreach (Pipe pipe in pipes) { curve = pipe.Location.Transform(totalTransformInverse) as Autodesk.DesignScript.Geometry.Curve; sp = curve.StartPoint; ep = curve.EndPoint; pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(sp.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(sp.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(sp.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(sp); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(ep); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); } IList <Fitting> fittings = new List <Fitting>(); for (int i = 0; i < pipes.Length - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(pipes[i], pipes[i + 1]); } catch { } fittings.Add(fitting); } if (start != null) { start.Dispose(); } if (end != null) { end.Dispose(); } if (sp != null) { sp.Dispose(); } if (ep != null) { ep.Dispose(); } if (curve != null) { curve.Dispose(); } foreach (var item in points) { if (item != null) { item.Dispose(); } } points.Clear(); Utils.Log(string.Format("Pipe.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "Pipes", pipes }, { "Fittings", fittings } }); }
public static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.PolyCurve polyCurve, double maxLength, Featureline featureline) { Utils.Log(string.Format("CableTray.ByPolyCurve started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } double length = polyCurve.Length; var oType = cableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; IList <CableTray> output = new List <CableTray>(); IList <Fitting> fittings = new List <Fitting>(); int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); Utils.Log(string.Format("subdivisions {0}", subdivisions)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); try { points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); // This is slow } catch { points = Featureline.PointsByChord(polyCurve, maxLength); // This is slow } Utils.Log(string.Format("Points {0}", points.Count)); var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point s = null; Autodesk.DesignScript.Geometry.Point e = null; Autodesk.DesignScript.Geometry.Point sp = null; Autodesk.DesignScript.Geometry.Point ep = null; Autodesk.DesignScript.Geometry.Curve curve = null; TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); for (int i = 0; i < points.Count - 1; ++i) { s = points[i]; e = points[i + 1]; curve = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(s, e); sp = s.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; ep = e.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var pipe = new CableTray(); Autodesk.Revit.DB.MEPCurve fi; if (DocumentManager.Instance.CurrentDBDocument.IsFamilyDocument) { fi = null; } else { fi = Autodesk.Revit.DB.Electrical.CableTray.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, sp.ToXyz(), ep.ToXyz(), ElementId.InvalidElementId) as Autodesk.Revit.DB.MEPCurve; } pipe.InitObject((Autodesk.Revit.DB.Electrical.CableTray)fi); pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(s.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(s.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(s.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(s); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(e); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); output.Add(pipe); Utils.Log(string.Format("Pipe {0}", pipe.Id)); } for (int i = 0; i < output.Count - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(output[i], output[i + 1]); } catch { } fittings.Add(fitting); } TransactionManager.Instance.TransactionTaskDone(); Utils.Log(string.Format("CableTray.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "CableTray", output }, { "Fittings", fittings } }); }
private static Dictionary <string, object> ByPolyCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.PolyCurve polyCurve, double maxLength, Featureline featureline) { Utils.Log(string.Format("Conduit.ByPolyCurve started...", "")); var totalTransform = RevitUtils.DocumentTotalTransform(); var totalTransformInverse = totalTransform.Inverse(); var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType; IList <Conduit> output = new List <Conduit>(); IList <Fitting> fittings = new List <Fitting>(); double length = polyCurve.Length; int subdivisions = Convert.ToInt32(Math.Ceiling(length / maxLength)); IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); points.Add(polyCurve.StartPoint); foreach (Autodesk.DesignScript.Geometry.Point p in polyCurve.PointsAtEqualChordLength(subdivisions)) { points.Add(p); } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); for (int i = 0; i < points.Count - 1; ++i) { var s = points[i]; var e = points[i + 1]; var curve = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(s, e); UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); var sp = s.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var ep = e.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var pipe = new Conduit(oType, sp.ToXyz(), ep.ToXyz()); pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName); pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index); pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code); pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString()); pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(s.X, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(s.Y, 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(s.Z, 3)); var soe = featureline.GetStationOffsetElevationByPoint(s); pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round((double)soe["Elevation"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1); pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0); soe = featureline.GetStationOffsetElevationByPoint(e); pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round((double)soe["Station"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round((double)soe["Offset"], 3)); pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round((double)soe["Elevation"], 3)); output.Add(pipe); } for (int i = 0; i < output.Count - 1; ++i) { Fitting fitting = null; try { fitting = Fitting.Elbow(output[i], output[i + 1]); } catch { } fittings.Add(fitting); } totalTransform.Dispose(); totalTransformInverse.Dispose(); Utils.Log(string.Format("Conduit.ByPolyCurve completed.", "")); return(new Dictionary <string, object>() { { "Conduit", output }, { "Fittings", fittings } }); }
/// <summary> /// Creates a set of CableTrays following a PolyCurve specifying a maximum length. /// </summary> /// <param name="CableTrayType">The CableTray type.</param> /// <param name="polyCurve">The PolyCurve to follow in WCS.</param> /// <param name="maxLength">The maximum length of the CableTrays following the PolyCurve.</param> /// <returns></returns> private CableTray[] ByPolyCurve_(Revit.Elements.Element CableTrayType, PolyCurve polyCurve, double maxLength) { Utils.Log(string.Format("CableTray.ByPolyCurve started...", "")); if (!SessionVariables.ParametersCreated) { UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument); } var oType = CableTrayType.InternalElement as Autodesk.Revit.DB.Electrical.CableTrayType; double length = polyCurve.Length; double subdivisions = Math.Ceiling(length / maxLength); double increment = 1 / subdivisions; IList <double> parameters = new List <double>(); double parameter = 0; IList <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>(); while (parameter <= 1) { points.Add(polyCurve.PointAtParameter(parameter)); parameter = parameter + increment; } points.Add(polyCurve.EndPoint); points = Autodesk.DesignScript.Geometry.Point.PruneDuplicates(points); // TODO this is slow IList <ElementId> ids = new List <ElementId>(); TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var totalTransform = RevitUtils.DocumentTotalTransform(); Autodesk.DesignScript.Geometry.Point start = null; Autodesk.DesignScript.Geometry.Point end = null; for (int i = 0; i < points.Count - 1; ++i) { start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var s = start.ToXyz(); end = points[i + 1].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point; var e = end.ToXyz(); Autodesk.Revit.DB.Electrical.CableTray p = Autodesk.Revit.DB.Electrical.CableTray.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, s, e, ElementId.InvalidElementId); ids.Add(p.Id); } for (int i = 0; i < GetCableTrayByIds(ids).Length - 1; ++i) { CableTray ct1 = GetCableTrayByIds(ids)[i]; CableTray ct2 = GetCableTrayByIds(ids)[i + 1]; Fitting.Elbow(ct1, ct2); } TransactionManager.Instance.TransactionTaskDone(); start.Dispose(); end.Dispose(); foreach (var pt in points) { if (pt != null) { pt.Dispose(); } } points.Clear(); Utils.Log(string.Format("CableTray.ByPolyCurve completed.", "")); return(GetCableTrayByIds(ids)); }