示例#1
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 totalTransformInverse = totalTransform.Inverse();

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

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

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

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

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

            TransactionManager.Instance.TransactionTaskDone();

            totalTransform.Dispose();

            totalTransformInverse.Dispose();

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

            return(GetConduitByIds(ids));
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Conduit"/> class.
 /// </summary>
 /// <param name="instance">The instance.</param>
 protected Conduit(Autodesk.Revit.DB.Electrical.Conduit instance)
 {
     SafeInit(() => InitObject(instance));
 }
示例#3
0
 /// <summary>
 /// Initialize a Conduit element
 /// </summary>
 /// <param name="instance">The instance.</param>
 private void InitObject(Autodesk.Revit.DB.Electrical.Conduit instance)
 {
     Autodesk.Revit.DB.MEPCurve fi = instance as Autodesk.Revit.DB.MEPCurve;
     InternalSetMEPCurve(fi);
 }