Ejemplo n.º 1
0
        /***************************************************/

        public static Autodesk.Revit.DB.Electrical.CableTrayType ToRevitElementType(this oM.MEP.System.SectionProperties.CableTraySectionProperty property, Document document, IEnumerable <BuiltInCategory> categories = null, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (property == null || document == null)
            {
                return(null);
            }

            Autodesk.Revit.DB.Electrical.CableTrayType elementType = refObjects.GetValue <Autodesk.Revit.DB.Electrical.CableTrayType>(document, property.BHoM_Guid);
            if (elementType != null)
            {
                return(elementType);
            }

            settings = settings.DefaultIfNull();

            elementType = property.ElementType(document, categories, settings) as Autodesk.Revit.DB.Electrical.CableTrayType;
            if (elementType != null)
            {
                return(elementType);
            }

            List <Autodesk.Revit.DB.Electrical.CableTrayType> trayTypes = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Electrical.CableTrayType)).Cast <Autodesk.Revit.DB.Electrical.CableTrayType>().ToList();

            if (property.SectionProfile.ElementProfile is BH.oM.Spatial.ShapeProfiles.BoxProfile)
            {
                elementType = trayTypes.FirstOrDefault(x => x.FamilyName == "Cable Tray with Fittings");
            }

            if (elementType != null)
            {
                BH.Engine.Reflection.Compute.RecordNote($"CableTray is being pushed as the first type available in the Revit model, in this case {elementType.Name}.");
            }
            else
            {
                return(null);
            }

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

            refObjects.AddOrReplace(property, elementType);
            return(elementType);
        }
Ejemplo n.º 2
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);
        }