예제 #1
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);

                if (!SessionVariables.ParametersCreated)
                {
                    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 }
            });
        }
예제 #2
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));
        }