Beispiel #1
0
        /// <summary>
        /// Private method to get the CableTrays by ElementId
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        private static CableTray[] GetCableTrayByIds(ICollection <ElementId> ids)
        {
            Utils.Log(string.Format("CableTray.GetCableTrayByIds started...", ""));

            var pipes = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument)
                        .OfClass(typeof(Autodesk.Revit.DB.Electrical.CableTray))
                        .WhereElementIsNotElementType()
                        .Cast <Autodesk.Revit.DB.Electrical.CableTray>()
                        .Where(x => ids.Contains(x.Id))
                        .ToList();

            CableTray[] output = new CableTray[pipes.Count];

            int c = 0;

            foreach (var p in pipes)
            {
                output[c] = new CableTray(p);

                c = c + 1;
            }

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

            return(output);
        }
        /// <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));
        }
Beispiel #3
0
        /// <summary>
        /// Creates a Conduit by revit Conduit.
        /// </summary>
        /// <param name="element">The MEP Curve from Revit</param>
        /// <returns></returns>
        public static CableTray ByRevitElement(Revit.Elements.Element element)
        {
            Utils.Log(string.Format("CableTray.ByRevitElement started...", ""));

            if (element.InternalElement is Autodesk.Revit.DB.Electrical.CableTray)
            {
                var c       = element.InternalElement as Autodesk.Revit.DB.Electrical.CableTray;
                var conduit = new CableTray();
                conduit.InternalSetMEPCurve(c);
                return(conduit);
            }

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

            return(null);
        }
Beispiel #4
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 }
            });
        }