Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShapePoint"/> class.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="featureline">The featureline.</param>
        /// <param name="id">The initial ID of the ShapePoint.</param>
        internal ShapePoint(Point point, Featureline featureline, int id = 0)
        {
            this.UniqueId = Guid.NewGuid().ToString();
            this._id      = id;

            this.Corridor      = featureline.Baseline.CorridorName;
            this.BaselineIndex = featureline.Baseline.Index;
            this.RegionIndex   = featureline.BaselineRegionIndex;

            this.Side = featureline.Side;
            this.Code = featureline.Code;

            var soe = featureline.GetStationOffsetElevationByPoint(point);

            this.Station   = (double)soe["Station"];
            this.Offset    = (double)soe["Offset"];
            this.Elevation = (double)soe["Elevation"];

            this.RegionRelative   = this.Station - featureline.Start;                            // 1.1.0
            this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start); // 1.1.0

            this.Point       = point;
            this.Featureline = featureline;

            this.RevitPoint = point.Transform(RevitUtils.DocumentTotalTransform()) as Point;
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a PipePlaceholder by two points.
        /// </summary>
        /// <param name="pipeType">Type of the pipe.</param>
        /// <param name="systemType">Type of the system.</param>
        /// <param name="start">The start.</param>
        /// <param name="end">The end.</param>
        /// <param name="level">The level.</param>
        /// <returns></returns>
        public static PipePlaceHolder ByPoints(Revit.Elements.Element pipeType, Revit.Elements.Element systemType, Autodesk.DesignScript.Geometry.Point start, Autodesk.DesignScript.Geometry.Point end, Revit.Elements.Level level)
        {
            Utils.Log(string.Format("PipePlaceHolder.ByPoints started...", ""));

            var oType          = pipeType.InternalElement as Autodesk.Revit.DB.Plumbing.PipeType;
            var oSystemType    = systemType.InternalElement as Autodesk.Revit.DB.Plumbing.PipingSystemType;
            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();
            var l      = level.InternalElement as Autodesk.Revit.DB.Level;

            if (nstart != null)
            {
                nstart.Dispose();
            }
            if (nend != null)
            {
                nend.Dispose();
            }

            Utils.Log(string.Format("PipePlaceHolder.ByPoints completed.", ""));

            return(new PipePlaceHolder(oType, oSystemType, s, e, l));
        }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
        /// <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));
        }
Ejemplo n.º 7
0
        /// <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));
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        /// <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.</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...", ""));

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

            IList <ElementId> ids = new List <ElementId>();

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            var totalTransform = RevitUtils.DocumentTotalTransform();

            for (int i = 0; i < points.Count - 1; ++i)
            {
                Autodesk.DesignScript.Geometry.Point start = points[i].Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
                var s = start.ToXyz();
                Autodesk.DesignScript.Geometry.Point 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();

            Utils.Log(string.Format("CableTray.ByPolyCurve completed.", ""));

            return(GetCableTrayByIds(ids));
        }
Ejemplo n.º 10
0
        /// <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));
        }
Ejemplo n.º 11
0
        /// <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));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Calculates the new ShapePoint location on the new Featureline using the Station, Offset and Elevation parameters.
        /// </summary>
        /// <param name="featureline">The featureline used to update the ShapePoint</param>
        /// <returns></returns>
        public ShapePoint UpdateByFeatureline(Featureline featureline)
        {
            Utils.Log(string.Format("ShapePoint.UpdateByFeatureline started...", ""));

            var p = featureline.PointByStationOffsetElevation(this.Station, this.Offset, this.Elevation, false);

            this.Point       = p;
            this.RevitPoint  = this.Point.Transform(RevitUtils.DocumentTotalTransform()) as Point;
            this.Featureline = featureline;

            this.BaselineIndex    = featureline.Baseline.Index;                                  // 1.1.0
            this.RegionIndex      = featureline.BaselineRegionIndex;                             // 1.1.0
            this.RegionRelative   = this.Station - featureline.Start;                            // 1.1.0
            this.RegionNormalized = this.RegionRelative / (featureline.End - featureline.Start); // 1.1.0
            this.Code             = featureline.Code;                                            // 1.1.0
            this.Corridor         = featureline.Baseline.CorridorName;                           // 1.1.0
            this.Side             = featureline.Side;                                            // 1.1.0

            Utils.Log(string.Format("ShapePoint.UpdateByFeatureline completed.", ""));

            return(this);
        }
Ejemplo n.º 13
0
        /// <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));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates the connection with the running session of Civil 3D.
        /// </summary>
        public CivilApplication()
        {
            Utils.InitializeLog();

            Utils.Log(string.Format("CivilApplication.CivilApplication started...", ""));

            this.mApp = this.GetApplication();

            IList <CivilDocument> documents = new List <CivilDocument>();

            foreach (var doc in this.mApp.Documents)
            {
                documents.Add(new CivilDocument(doc as AeccRoadwayDocument));
            }

            this.Documents      = documents;
            this.ActiveDocument = mApp.ActiveDocument;

            var revitDoc = RevitServices.Persistence.DocumentManager.Instance.CurrentDBDocument;

            RevitServices.Transactions.TransactionManager.Instance.EnsureInTransaction(revitDoc);

            Autodesk.Revit.DB.Units units = new Autodesk.Revit.DB.Units(Autodesk.Revit.DB.UnitSystem.Metric);

            var du = this.Documents.First()._document.Settings.DrawingSettings.UnitZoneSettings.DrawingUnits;

            Utils.Log(string.Format("CivilApplication.Units started...", ""));

            // 1.1.0 Change Revit Document untis to match the Civil 3D Units
            if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitMeters)
            {
                units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_METERS));
            }
            else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitDecimeters)
            {
                units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMETERS));
            }
            else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitCentimeters)
            {
                units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_CENTIMETERS));
            }
            else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitMillimeters)
            {
                units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_MILLIMETERS));
            }
            else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitFeet)
            {
                units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMAL_FEET));
            }
            else if (du == Autodesk.AECC.Interop.Land.AeccDrawingUnitType.aeccDrawingUnitInches)
            {
                units.SetFormatOptions(Autodesk.Revit.DB.UnitType.UT_Length, new Autodesk.Revit.DB.FormatOptions(Autodesk.Revit.DB.DisplayUnitType.DUT_DECIMAL_INCHES));
            }
            else
            {
                throw new Exception("UNITS ERROR\nThe Civil 3D units of the Active Document are not supported in Revit.\nChange the Civil 3D Units to continue");
            }

            revitDoc.SetUnits(units);

            RevitServices.Transactions.TransactionManager.Instance.TransactionTaskDone();

            Utils.Log(string.Format("CivilApplication.Units completed.", ""));

            SessionVariables.LandXMLPath            = System.IO.Path.GetTempPath();
            SessionVariables.IsLandXMLExported      = false;
            SessionVariables.CivilApplication       = this;
            SessionVariables.ParametersCreated      = false;
            SessionVariables.DocumentTotalTransform = null;
            RevitUtils.DocumentTotalTransform();
        }
Ejemplo n.º 15
0
        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 }
            });
        }
Ejemplo n.º 16
0
 public ShapePoint SetPoint(Point point)
 {
     this.Point      = point;
     this.RevitPoint = this.Point.Transform(RevitUtils.DocumentTotalTransform()) as Point;
     return(this);
 }
Ejemplo n.º 17
0
        private static Conduit[] ByPolyCurve(Revit.Elements.Element conduitType, PolyCurve polyCurve, double maxLength)
        {
            Utils.Log(string.Format("Conduit.ByPolyCurve started...", ""));

            var totalTransform = RevitUtils.DocumentTotalTransform();

            var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType;

            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);  // this is slow

            IList <ElementId> ids = new List <ElementId>();

            TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument);

            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.Conduit p = Autodesk.Revit.DB.Electrical.Conduit.Create(DocumentManager.Instance.CurrentDBDocument, oType.Id, s, e, ElementId.InvalidElementId);
                ids.Add(p.Id);
            }

            var res = GetConduitByIds(ids);

            for (int i = 0; i < GetConduitByIds(ids).Length - 1; ++i)
            {
                Conduit ct1 = res[i];
                Conduit ct2 = res[i + 1];
                Fitting.Elbow(ct1, ct2);
            }

            TransactionManager.Instance.TransactionTaskDone();

            if (start != null)
            {
                start.Dispose();
            }
            if (end != null)
            {
                end.Dispose();
            }

            foreach (var pt in points)
            {
                if (pt != null)
                {
                    pt.Dispose();
                }
            }

            points.Clear();

            Utils.Log(string.Format("Conduit.ByPolyCurve completed.", ""));

            return(res);
        }
Ejemplo n.º 18
0
        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 }
            });
        }
Ejemplo n.º 19
0
        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 }
            });
        }