Beispiel #1
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 }
            });
        }
Beispiel #2
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);

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