/// <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 #2
0
 /// <summary>
 /// Initialize a CableTray element.
 /// </summary>
 /// <param name="instance"></param>
 private void InitObject(Autodesk.Revit.DB.Electrical.CableTray instance)
 {
     Autodesk.Revit.DB.MEPCurve fi = instance as Autodesk.Revit.DB.MEPCurve;
     InternalSetMEPCurve(fi);
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CableTray"/> class.
 /// </summary>
 /// <param name="instance">The instance.</param>
 protected CableTray(Autodesk.Revit.DB.Electrical.CableTray instance)
 {
     SafeInit(() => InitObject(instance));
 }