Example #1
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...", ""));

            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 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("Pipe.ByPoints completed.", ""));

            return(new Pipe(oType, oSystemType, s, e, l));
        }
Example #2
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));
        }
Example #3
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));
        }
Example #4
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));
        }
Example #5
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 }
            });
        }
Example #6
0
        public 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...", ""));

            if (!SessionVariables.ParametersCreated)
            {
                UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
            }

            var totalTransform = RevitUtils.DocumentTotalTransform();

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

            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];
                end   = points[i + 1];

                curve = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(start, end);

                sp = start.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
                ep = end.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(start.X, 3));
                pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(start.Y, 3));
                pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(start.Z, 3));
                var soe = featureline.GetStationOffsetElevationByPoint(start);
                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(end);
                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);

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

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

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

            points.Clear();

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

            return(new Dictionary <string, object>()
            {
                { "Conduit", output }, { "Fittings", fittings }
            });
        }