示例#1
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Sheet SheetFromRevit(this ViewSheet viewSheet, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            Sheet sheet = refObjects.GetValue <Sheet>(viewSheet.Id);

            if (sheet != null)
            {
                return(sheet);
            }

            sheet = BH.Engine.Adapters.Revit.Create.Sheet(viewSheet.Name, viewSheet.SheetNumber);

            ElementType elementType = viewSheet.Document.GetElement(viewSheet.GetTypeId()) as ElementType;

            if (elementType != null)
            {
                sheet.InstanceProperties = elementType.InstancePropertiesFromRevit(settings, refObjects);
            }

            sheet.Name = viewSheet.Name;

            //Set identifiers, parameters & custom data
            sheet.SetIdentifiers(viewSheet);
            sheet.CopyParameters(viewSheet, settings.ParameterSettings);
            sheet.SetProperties(viewSheet, settings.ParameterSettings);

            refObjects.AddOrReplace(viewSheet.Id, sheet);
            return(sheet);
        }
示例#2
0
        /***************************************************/

        public static bool SetType(this Element element, IInstance instance, RevitSettings settings)
        {
            if (element.TrySetTypeFromString(instance, settings))
            {
                return(true);
            }

            ElementType elementType = instance.Properties.ElementType(element.Document, settings);

            if (elementType == null)
            {
                elementType = instance.IElementType(element.Document, settings);
            }

            if (elementType != null)
            {
                try
                {
                    return(element.SetParameter(BuiltInParameter.ELEM_TYPE_PARAM, elementType.Id));
                }
                catch
                {
                }
            }

            return(false);
        }
示例#3
0
        /***************************************************/
        /****             Protected Methods             ****/
        /***************************************************/

        protected override IEnumerable <IBHoMObject> Read(IRequest request, ActionConfig actionConfig = null)
        {
            ICollection <ElementId> selected = this.UIDocument.Selection.GetElementIds();

            if (request == null)
            {
                BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided IRequest is null.");
                return(new List <IBHoMObject>());
            }

            RevitPullConfig pullConfig = actionConfig as RevitPullConfig;

            if (pullConfig == null)
            {
                BH.Engine.Reflection.Compute.RecordError("BHoM objects could not be read because provided actionConfig is not a valid RevitPullConfig.");
                return(new List <IBHoMObject>());
            }

            Discipline?requestDiscipline = request.Discipline(pullConfig.Discipline);

            if (requestDiscipline == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Conflicting disciplines have been detected.");
                return(new List <IBHoMObject>());
            }

            Discipline discipline = requestDiscipline.Value;

            if (discipline == Discipline.Undefined)
            {
                discipline = Discipline.Physical;
            }

            Dictionary <Document, IRequest> requestsByLinks = request.SplitRequestTreeByLinks(this.Document);

            if (requestsByLinks == null)
            {
                BH.Engine.Reflection.Compute.RecordError($"Pull failed due to issues with the request containing {nameof(FilterByLink)}. Please try to restructure the used Request and try again.");
                return(new List <IBHoMObject>());
            }

            RevitSettings settings = RevitSettings.DefaultIfNull();

            List <IBHoMObject> result = new List <IBHoMObject>();

            foreach (KeyValuePair <Document, IRequest> requestByLink in requestsByLinks)
            {
                result.AddRange(Read(requestByLink.Key, requestByLink.Value, pullConfig, discipline, settings));
            }

            bool?[] activePulls = new bool?[] { pullConfig.GeometryConfig?.PullEdges, pullConfig.GeometryConfig?.PullSurfaces, pullConfig.GeometryConfig?.PullMeshes, pullConfig.RepresentationConfig?.PullRenderMesh };
            if (activePulls.Count(x => x == true) > 1)
            {
                BH.Engine.Reflection.Compute.RecordWarning("Pull of more than one geometry/representation type has been specified in RevitPullConfig. Please consider this can be time consuming due to the amount of conversions.");
            }

            this.UIDocument.Selection.SetElementIds(selected);

            return(result);
        }
示例#4
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static SolidMaterial SolidMaterialFromRevit(this Material material, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (material == null)
            {
                return(null);
            }

            settings = settings.DefaultIfNull();

            SolidMaterial result = refObjects.GetValue <SolidMaterial>(material.Id.IntegerValue);

            if (result != null)
            {
                return(result);
            }
            else
            {
                result = new SolidMaterial();
            }

            result.Name = material.Name;
            Parameter parameter = material.get_Parameter(BuiltInParameter.ALL_MODEL_DESCRIPTION);

            if (parameter != null)
            {
                result.Description = parameter.AsString();
            }

            result.CopyCharacteristics(material);
            result.SetProperties(material, settings.ParameterSettings);

            refObjects.AddOrReplace(material.Id, result);
            return(result);
        }
示例#5
0
        /***************************************************/

        public static Element Create(IBHoMObject bHoMObject, Document document, RevitSettings settings, Dictionary <Guid, List <int> > refObjects)
        {
            if (bHoMObject == null)
            {
                NullObjectCreateError(typeof(IBHoMObject));
                return(null);
            }

            try
            {
                Element element = bHoMObject.IToRevit(document, settings, refObjects);
                bHoMObject.SetIdentifiers(element);

                //Assign Tags
                string tagsParameterName = null;
                if (settings != null)
                {
                    tagsParameterName = settings.ParameterSettings?.TagsParameter;
                }

                if (!string.IsNullOrEmpty(tagsParameterName))
                {
                    element.SetTags(bHoMObject, tagsParameterName);
                }

                return(element);
            }
            catch (Exception ex)
            {
                ObjectNotCreatedError(bHoMObject, ex);
                return(null);
            }
        }
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static List <ICurve> AnalyticalOutlines(this HostObject hostObject, RevitSettings settings = null)
        {
            AnalyticalModel analyticalModel = hostObject.GetAnalyticalModel();

            if (analyticalModel == null)
            {
                //TODO: appropriate warning or not - physical preferred?
                return(null);
            }

            settings = settings.DefaultIfNull();

            List <ICurve> wallCurves = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves).ToList().FromRevit();

            if (wallCurves.Any(x => x == null))
            {
                hostObject.UnsupportedOutlineCurveWarning();
                return(null);
            }

            List <ICurve> result = BH.Engine.Geometry.Compute.IJoin(wallCurves).ConvertAll(c => c as ICurve);

            if (result.Any(x => !x.IIsClosed()))
            {
                hostObject.NonClosedOutlineWarning();
                return(null);
            }

            return(result);
        }
示例#7
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static bool Update(this Element element, IBHoMObject bHoMObject, RevitSettings settings, bool setLocationOnUpdate)
        {
            bool isElement = new ElementIsElementTypeFilter(true).PassesFilter(element);

            if (isElement)
            {
                if (element.ISetType(bHoMObject, settings))
                {
                    element.Document.Regenerate();
                }
            }

            element.CopyParameters(bHoMObject, settings);

            if (!string.IsNullOrWhiteSpace(bHoMObject.Name) && element.Name != bHoMObject.Name)
            {
                try
                {
                    element.Name = bHoMObject.Name;
                }
                catch
                {
                }
            }

            if (setLocationOnUpdate && isElement)
            {
                element.ISetLocation(bHoMObject, settings);
            }

            return(true);
        }
示例#8
0
        public static RevitSettings RevitSettings(ConnectionSettings connectionSettings = null, FamilyLoadSettings familyLoadSettings = null, ParameterSettings parameterSettings = null, double distanceTolerance = BH.oM.Geometry.Tolerance.Distance, double angleTolerance = BH.oM.Geometry.Tolerance.Angle)
        {
            RevitSettings settings = new RevitSettings();

            if (connectionSettings != null)
            {
                settings.ConnectionSettings = connectionSettings;
            }

            if (familyLoadSettings != null)
            {
                settings.FamilyLoadSettings = familyLoadSettings;
            }

            if (parameterSettings != null)
            {
                settings.ParameterSettings = parameterSettings;
            }

            if (!double.IsNaN(distanceTolerance))
            {
                settings.DistanceTolerance = distanceTolerance;
            }

            if (!double.IsNaN(distanceTolerance))
            {
                settings.AngleTolerance = angleTolerance;
            }

            return(settings);
        }
示例#9
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static bool IsSimilar(this Curve curve1, Curve curve2, RevitSettings settings, bool flippedIsEqual = false)
        {
            if (curve2 == null || curve1 == null)
            {
                return(false);
            }

            if (curve1.IsBound != curve2.IsBound)
            {
                return(false);
            }

            if (Math.Abs(curve1.ApproximateLength - curve2.ApproximateLength) > settings.DistanceTolerance)
            {
                return(false);
            }

            IList <XYZ> xyz1 = curve1.Tessellate();
            IList <XYZ> xyz2 = curve2.Tessellate();

            if (xyz1.Count != xyz2.Count)
            {
                return(false);
            }

            for (int i = 0; i < xyz1.Count; i++)
            {
                if (!xyz1[i].IsAlmostEqualTo(xyz2[i], settings.DistanceTolerance) && (!flippedIsEqual || !xyz1[i].IsAlmostEqualTo(xyz2[xyz2.Count - 1 - i], settings.DistanceTolerance)))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#10
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static List <PolyCurve> Perimeter(this SpatialElement spatialElement, RevitSettings settings = null)
        {
            if (spatialElement == null)
            {
                return(null);
            }

            IList <IList <BoundarySegment> > boundarySegments = spatialElement.GetBoundarySegments(new SpatialElementBoundaryOptions());

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

            List <PolyCurve> results = new List <PolyCurve>();

            foreach (IList <BoundarySegment> boundarySegmentList in boundarySegments)
            {
                if (boundarySegmentList == null)
                {
                    continue;
                }

                List <BH.oM.Geometry.ICurve> curves = new List <ICurve>();
                foreach (BoundarySegment boundarySegment in boundarySegmentList)
                {
                    curves.Add(boundarySegment.GetCurve().IFromRevit());
                }

                results.Add(BH.Engine.Geometry.Create.PolyCurve(curves));
            }

            return(results);
        }
示例#11
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static ViewSheet ToRevitSheet(this Sheet sheet, Document document, RevitSettings settings = null, Dictionary <Guid, List <int> > refObjects = null)
        {
            if (sheet == null)
            {
                return(null);
            }

            ViewSheet viewSheet = refObjects.GetValue <ViewSheet>(document, sheet.BHoM_Guid);

            if (viewSheet != null)
            {
                return(viewSheet);
            }

            settings = settings.DefaultIfNull();

            viewSheet             = ViewSheet.Create(document, ElementId.InvalidElementId);
            viewSheet.Name        = sheet.SheetName;
            viewSheet.SheetNumber = sheet.SheetNumber;

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

            refObjects.AddOrReplace(sheet, viewSheet);
            return(viewSheet);
        }
示例#12
0
        /***************************************************/

        public static IBHoMObject FromRevit(this Grid grid, Discipline discipline, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            switch (discipline)
            {
            default:
                return(grid.GridFromRevit(settings, refObjects));
            }
        }
示例#13
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static bool SetLocation(this Element element, IInstance instance, RevitSettings settings)
        {
            if (instance.Location == null)
            {
                return(false);
            }

            return(SetLocation(element, instance.Location as dynamic, settings));
        }
示例#14
0
        /***************************************************/

        public static Level LevelBelow(this Document document, XYZ point, RevitSettings settings = null, bool closestIfNotFound = true)
        {
            if (point == null)
            {
                return(null);
            }

            return(document.LevelBelow(point.Z, settings, closestIfNotFound));
        }
示例#15
0
        /***************************************************/

        public static Level LevelBelow(this Document document, Curve curve, RevitSettings settings = null, bool closestIfNotFound = true)
        {
            if (curve == null || !curve.IsBound)
            {
                return(null);
            }

            return(document.LevelBelow(curve.Tessellate().Min(x => x.Z), settings, closestIfNotFound));
        }
示例#16
0
        /***************************************************/
        /****             Fallback Methods              ****/
        /***************************************************/

        public static bool SetLocation(this Element element, IGeometry geometry, RevitSettings settings)
        {
            Type type = element.GetType();

            if (AbstractRevitTypes.All(x => !x.IsAssignableFrom(type)))
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Setting Revit element location based on BHoM geometry of type {0} is currently not supported. Only parameters were updated. Revit ElementId: {1}", geometry.GetType(), element.Id));
            }

            return(false);
        }
示例#17
0
        /***************************************************/

        public static Level LevelAbove(this Document document, IGeometry geometry, RevitSettings settings = null, bool closestIfNotFound = true)
        {
            BoundingBox bbox = geometry.IBounds();

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

            return(document.LevelAbove(bbox.Max.Z.FromSI(UnitType.UT_Length), settings, closestIfNotFound));
        }
示例#18
0
        /***************************************************/
        /****              Fallback Methods             ****/
        /***************************************************/

        public static bool SetType(this Element element, IBHoMObject bHoMObject, RevitSettings settings)
        {
            Type type = element.GetType();

            if (type != typeof(Autodesk.Revit.DB.Family) && !typeof(ElementType).IsAssignableFrom(type))
            {
                BH.Engine.Reflection.Compute.RecordWarning(String.Format("Element type has not been updated based on the BHoM object due to the lacking convert method. Revit ElementId: {0} BHoM_Guid: {1}", element.Id, bHoMObject.BHoM_Guid));
            }

            return(false);
        }
示例#19
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static Space SpaceFromRevit(this SpatialElement spatialElement, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            settings = settings.DefaultIfNull();

            SpatialElementBoundaryOptions spatialElementBoundaryOptions = new SpatialElementBoundaryOptions();

            spatialElementBoundaryOptions.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
            spatialElementBoundaryOptions.StoreFreeBoundaryFaces         = false;

            return(spatialElement.SpaceFromRevit(spatialElementBoundaryOptions, settings, refObjects));
        }
示例#20
0
        /***************************************************/

        public static bool SetLocation(this Element element, IBHoMObject bHoMObject, RevitSettings settings)
        {
            Type type = element.GetType();

            if (AbstractRevitTypes.All(x => !x.IsAssignableFrom(type)))
            {
                BH.Engine.Reflection.Compute.RecordError(String.Format("Unable to set location of Revit element of type {0} based on BHoM object of type {1} beacuse no suitable method could be found. Only parameters were updated. Revit ElementId: {2} BHoM_Guid: {3}", element.GetType(), bHoMObject.GetType(), element.Id, bHoMObject.BHoM_Guid));
            }

            return(false);
        }
示例#21
0
        public static RevitSettings DefaultIfNull(this RevitSettings settings)
        {
            if (settings == null)
            {
                BH.Engine.Reflection.Compute.RecordNote("Revit settings are not set. Default settings are used.");
                settings = new RevitSettings();
                settings.ParameterSettings = Query.DefaultParameterSettings();
            }

            return(settings);
        }
示例#22
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static List <Solid> Solids(this Element element, Options options, RevitSettings settings = null)
        {
            List <GeometryObject> geometryPrimitives = element.GeometryPrimitives(options, settings);

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

            return(geometryPrimitives.Where(x => x is Solid).Cast <Solid>().ToList());
        }
示例#23
0
        public static IProfile Profile(this Autodesk.Revit.DB.Electrical.Wire wire, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            List <ICurve> edges = new List <ICurve>();

            double diameter = wire.Diameter.ToSI(UnitType.UT_WireSize);

            double thickness = 0;

            return(BH.Engine.Spatial.Create.TubeProfile(diameter, thickness));
        }
示例#24
0
        /***************************************************/
        /****               Public Methods              ****/
        /***************************************************/

        public static oM.Physical.Elements.Wall WallFromRevit(this Wall wall, RevitSettings settings = null, Dictionary <string, List <IBHoMObject> > refObjects = null)
        {
            if (wall == null)
            {
                return(null);
            }

            settings = settings.DefaultIfNull();

            oM.Physical.Elements.Wall bHoMWall = refObjects.GetValue <oM.Physical.Elements.Wall>(wall.Id);
            if (bHoMWall != null)
            {
                return(bHoMWall);
            }

            if (wall.StackedWallOwnerId != null && wall.StackedWallOwnerId != ElementId.InvalidElementId)
            {
                return(null);
            }

            if (wall.CurtainGrid != null)
            {
                bHoMWall = wall.WallFromRevit_Curtain(settings, refObjects);
            }
            else
            {
                bHoMWall = wall.WallFromRevit_Solid(settings, refObjects);
            }

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

            HostObjAttributes hostObjAttributes = wall.Document.GetElement(wall.GetTypeId()) as HostObjAttributes;
            string            materialGrade     = wall.MaterialGrade(settings);

            oM.Physical.Constructions.Construction construction = hostObjAttributes.ConstructionFromRevit(materialGrade, settings, refObjects);
            bHoMWall.Construction = construction;

            bHoMWall.Name = wall.FamilyTypeFullName();

            //Set identifiers, parameters & custom data
            bHoMWall.SetIdentifiers(wall);
            bHoMWall.CopyParameters(wall, settings.ParameterSettings);
            bHoMWall.SetProperties(wall, settings.ParameterSettings);

            refObjects.AddOrReplace(wall.Id, bHoMWall);
            return(bHoMWall);
        }
示例#25
0
        public static IProfile Profile(this Autodesk.Revit.DB.Plumbing.Pipe pipe, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();

            List <ICurve> edges = new List <ICurve>();

            double diameter = pipe.Diameter.ToSI(UnitType.UT_PipeSize);

            // Thickness
            double outsideDiameter = pipe.LookupParameterDouble(BuiltInParameter.RBS_PIPE_OUTER_DIAMETER);
            double insideDiameter  = pipe.LookupParameterDouble(BuiltInParameter.RBS_PIPE_INNER_DIAM_PARAM);
            double thickness       = (outsideDiameter - insideDiameter) / 2;

            return(BH.Engine.Spatial.Create.TubeProfile(diameter, thickness));
        }
示例#26
0
        /***************************************************/

        public static List <Face> LinkPanelFaces(this Ceiling ceiling, RevitSettings settings)
        {
            List <Face> result = new List <Face>();

            foreach (Reference reference in HostObjectUtils.GetBottomFaces(ceiling))
            {
                PlanarFace pf = ceiling.GetGeometryObjectFromReference(reference) as PlanarFace;
                if (pf != null)
                {
                    result.Add(pf);
                }
            }

            return(result);
        }
示例#27
0
        /***************************************************/

        public static List <Face> LinkPanelFaces(this Floor floor, RevitSettings settings)
        {
            List <Face> result = new List <Face>();

            foreach (Reference reference in HostObjectUtils.GetTopFaces(floor))
            {
                PlanarFace pf = floor.GetGeometryObjectFromReference(reference) as PlanarFace;
                if (pf != null)
                {
                    result.Add(pf);
                }
            }

            return(result);
        }
示例#28
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static string MaterialGrade(this Element element, RevitSettings settings)
        {
            if (element == null)
            {
                return(null);
            }

            string materialGrade = element.LookupParameterString(settings.ParameterSettings.MaterialGradeParameter);

            if (materialGrade != null)
            {
                materialGrade = materialGrade.Replace(" ", "");
            }

            return(materialGrade);
        }
示例#29
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static double OrientationAngle(this FamilyInstance familyInstance, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();
            double rotation = double.NaN;

            if (typeof(Column).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue))
            {
                rotation = familyInstance.OrientationAngleColumn(settings);
            }
            else if (typeof(IFramingElement).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue))
            {
                rotation = familyInstance.OrientationAngleFraming(settings);
            }

            return(rotation);
        }
示例#30
0
        /***************************************************/
        /****              Public methods               ****/
        /***************************************************/

        public static ICurve LocationCurve(this FamilyInstance familyInstance, RevitSettings settings = null)
        {
            settings = settings.DefaultIfNull();
            ICurve curve = null;

            if (typeof(Column).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue))
            {
                curve = familyInstance.LocationCurveColumn(settings);
            }
            else if (typeof(IFramingElement).BuiltInCategories().Contains((BuiltInCategory)familyInstance.Category.Id.IntegerValue))
            {
                curve = familyInstance.LocationCurveFraming(settings);
            }

            return(curve);
        }