Exemple #1
0
        public static List <IBHoMObject> FromRevit(this Autodesk.Revit.DB.Electrical.CableTray cableTray, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            switch (discipline)
            {
            case Discipline.Architecture:
            case Discipline.Physical:
            case Discipline.Environmental:
                return(new List <IBHoMObject>(cableTray.CableTrayFromRevit(settings, refObjects)));

            default:
                return(null);
            }
        }
Exemple #2
0
        public static IProfile Profile(this Autodesk.Revit.DB.Electrical.CableTray cableTray, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            // Cable Trays are always rectangular
            double boxHeight    = cableTray.Height.ToSI(UnitType.UT_Electrical_CableTraySize);
            double boxWidth     = cableTray.Width.ToSI(UnitType.UT_Electrical_CableTraySize);
            double boxThickness = 0.001519;
            double outerRadius  = 0;
            double innerRadius  = 0;

            return(BH.Engine.Spatial.Create.BoxProfile(boxHeight, boxWidth, boxThickness, outerRadius, innerRadius));
        }
Exemple #3
0
        public static IEnumerable <IBHoMObject> FromRevit(this Autodesk.Revit.DB.Electrical.CableTray cableTray, Discipline discipline, Transform transform = null, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            IEnumerable <IElement1D> result = null;

            switch (discipline)
            {
            case Discipline.Architecture:
            case Discipline.Physical:
            case Discipline.Environmental:
                result = new List <IElement1D>(cableTray.CableTrayFromRevit(settings, refObjects));
                break;
            }

            if (result != null && transform?.IsIdentity == false)
            {
                TransformMatrix bHoMTransform = transform.FromRevit();
                result = result.Select(x => x.ITransform(bHoMTransform));
            }

            return(result?.Cast <IBHoMObject>().ToList());
        }
Exemple #4
0
        public static List <BH.oM.MEP.System.CableTray> CableTrayFromRevit(this Autodesk.Revit.DB.Electrical.CableTray revitCableTray, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            // Reuse a BHoM cable tray from refObjects if it has been converted before
            List <BH.oM.MEP.System.CableTray> bhomCableTrays = refObjects.GetValues <BH.oM.MEP.System.CableTray>(revitCableTray.Id);

            if (bhomCableTrays != null)
            {
                return(bhomCableTrays);
            }
            else
            {
                bhomCableTrays = new List <BH.oM.MEP.System.CableTray>();
            }

            // Section properties
            BH.oM.MEP.System.SectionProperties.CableTraySectionProperty sectionProperty = BH.Revit.Engine.Core.Query.CableTraySectionProperty(revitCableTray, settings);

            // Orientation angle
            double orientationAngle = revitCableTray.OrientationAngle(settings);

            bool isStartConnected = false;
            bool isEndConnected   = false;
            List <BH.oM.Geometry.Line> queried = Query.LocationCurveMEP(revitCableTray, out isStartConnected, out isEndConnected, settings);

            Vector revitCableTrayVector = BH.Engine.Geometry.Modify.RoundCoordinates(VectorFromRevit((revitCableTray.Location as LocationCurve).Curve.GetEndPoint(0) - (revitCableTray.Location as LocationCurve).Curve.GetEndPoint(1)), 4).Normalise();

            for (int i = 0; i < queried.Count; i++)
            {
                BH.oM.Geometry.Line        segment     = queried[i];
                BH.oM.MEP.System.CableTray thisSegment = new CableTray
                {
                    StartPoint         = segment.StartPoint(),
                    EndPoint           = segment.EndPoint(),
                    SectionProperty    = sectionProperty,
                    ConnectionProperty = new CableTrayConnectionProperty(),
                    OrientationAngle   = orientationAngle
                };

                Vector bhomCableTrayVector = BH.Engine.Geometry.Modify.RoundCoordinates((thisSegment.StartPoint - thisSegment.EndPoint), 4).Normalise();

                if (queried.Count > 1)
                {
                    if (i == 0) //meaning it's the start segment of the revit cable tray that was split
                    {
                        if (BH.Engine.Geometry.Query.IsEqual(revitCableTrayVector, bhomCableTrayVector))
                        {
                            thisSegment.ConnectionProperty.IsStartConnected = isStartConnected;
                            thisSegment.ConnectionProperty.IsEndConnected   = true;
                        }
                        else
                        {
                            thisSegment.ConnectionProperty.IsStartConnected = true;
                            thisSegment.ConnectionProperty.IsEndConnected   = isStartConnected;
                        }
                    }
                    else if (i == queried.Count - 1) //meaning it's the end segment of the revit cable tray that was split
                    {
                        if (BH.Engine.Geometry.Query.IsEqual(revitCableTrayVector, bhomCableTrayVector))
                        {
                            thisSegment.ConnectionProperty.IsStartConnected = true;
                            thisSegment.ConnectionProperty.IsEndConnected   = isEndConnected;
                        }
                        else
                        {
                            thisSegment.ConnectionProperty.IsStartConnected = isEndConnected;
                            thisSegment.ConnectionProperty.IsEndConnected   = true;
                        }
                    }
                    else //meaning it's all mid segments of the revit cable tray that was split
                    {
                        thisSegment.ConnectionProperty.IsStartConnected = true;
                        thisSegment.ConnectionProperty.IsEndConnected   = true;
                    }
                }
                else
                {
                    if (BH.Engine.Geometry.Query.IsEqual(revitCableTrayVector, bhomCableTrayVector))
                    {
                        thisSegment.ConnectionProperty.IsStartConnected = isStartConnected;
                        thisSegment.ConnectionProperty.IsEndConnected   = isEndConnected;
                    }
                    else
                    {
                        thisSegment.ConnectionProperty.IsStartConnected = isEndConnected;
                        thisSegment.ConnectionProperty.IsEndConnected   = isStartConnected;
                    }
                }

                //Set identifiers, parameters & custom data
                thisSegment.SetIdentifiers(revitCableTray);
                thisSegment.CopyParameters(revitCableTray, settings.ParameterSettings);
                thisSegment.SetProperties(revitCableTray, settings.ParameterSettings);
                bhomCableTrays.Add(thisSegment);
            }

            refObjects.AddOrReplace(revitCableTray.Id, bhomCableTrays);
            return(bhomCableTrays);
        }
Exemple #5
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static Autodesk.Revit.DB.Electrical.CableTray ToRevitCableTray(this oM.MEP.System.CableTray cableTray, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (document == null)
            {
                return(null);
            }

            // Check valid cableTray object
            if (cableTray == null)
            {
                return(null);
            }

            // Construct Revit Cable Tray
            Autodesk.Revit.DB.Electrical.CableTray revitTray = refObjects.GetValue <Autodesk.Revit.DB.Electrical.CableTray>(document, cableTray.BHoM_Guid);
            if (revitTray != null)
            {
                return(revitTray);
            }

            // Settings
            settings = settings.DefaultIfNull();

            // CableTray type
            Autodesk.Revit.DB.Electrical.CableTrayType trayType = cableTray.SectionProperty.ToRevitElementType(document, new List <BuiltInCategory> {
                BuiltInCategory.OST_CableTrayRun
            }, settings, refObjects) as Autodesk.Revit.DB.Electrical.CableTrayType;
            if (trayType == null)
            {
                BH.Engine.Reflection.Compute.RecordError("No valid family has been found in the Revit model. CableTray creation requires the presence of the default CableTray Family Type.");
                return(null);
            }

            // End points
            XYZ start = cableTray.StartPoint.ToRevit();
            XYZ end   = cableTray.EndPoint.ToRevit();

            // Level
            Level level = document.LevelBelow(Math.Min(start.Z, end.Z), settings);

            if (level == null)
            {
                return(null);
            }

            SectionProfile sectionProfile = cableTray.SectionProperty?.SectionProfile;

            BoxProfile elementProfile = sectionProfile.ElementProfile as BoxProfile;

            if (elementProfile == null)
            {
                return(null);
            }

            revitTray = Autodesk.Revit.DB.Electrical.CableTray.Create(document, trayType.Id, start, end, level.Id);
            if (revitTray == null)
            {
                BH.Engine.Reflection.Compute.RecordError("No Revit CableTray has been created. Please check inputs prior to push attempt.");
                return(null);
            }

            // Copy parameters from BHoM object to Revit element
            revitTray.CopyParameters(cableTray, settings);

            // Set Orientation angle
            double orientationAngle = cableTray.OrientationAngle;

            if (Math.Abs(orientationAngle) > settings.AngleTolerance)
            {
                ElementTransformUtils.RotateElement(document, revitTray.Id, Line.CreateBound(start, end), orientationAngle);
            }

            // Set Height
            double profileHeight = elementProfile.Height;

            revitTray.SetParameter(BuiltInParameter.RBS_CABLETRAY_HEIGHT_PARAM, profileHeight);

            // Set Width
            double profileWidth = elementProfile.Width;

            revitTray.SetParameter(BuiltInParameter.RBS_CABLETRAY_WIDTH_PARAM, profileWidth);

            refObjects.AddOrReplace(cableTray, revitTray);
            return(revitTray);
        }
Exemple #6
0
        public static BH.oM.MEP.System.SectionProperties.SectionProfile CableTraySectionProfile(this Autodesk.Revit.DB.Electrical.CableTray revitCableTray, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            IProfile profile = revitCableTray.Profile(settings);

            // Create a section profile
            if (profile != null)
            {
                return(BH.Engine.MEP.Create.SectionProfile(profile as dynamic, 0, 0));
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public static BH.oM.MEP.System.SectionProperties.CableTraySectionProperty CableTraySectionProperty(this Autodesk.Revit.DB.Electrical.CableTray revitCableTray, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            // Cable Tray section profile
            SectionProfile sectionProfile = revitCableTray.CableTraySectionProfile(settings);

            // Cable Tray section property
            return(BH.Engine.MEP.Create.CableTraySectionProperty(new oM.Physical.Materials.Material(), sectionProfile));
        }