Ejemplo n.º 1
0
        private static void ExportAsMappedItem(ExporterIFC exporterIFC, Element element, IFCFile file, IFCExportType exportType, string ifcEnumType, IFCExtrusionCreationData extraParams,
                                               PlacementSetter setter, IFCAnyHandle localPlacementToUse, IFCAnyHandle productRepresentation, ProductWrapper productWrapper)
        {
            IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
            ElementId    typeId       = element.GetTypeId();
            ElementType  type         = element.Document.GetElement(typeId) as ElementType;
            IFCAnyHandle styleHandle  = null;

            if (type != null)
            {
                FamilyTypeInfo currentTypeInfo = ExporterCacheManager.TypeObjectsCache.Find(typeId, false, exportType);

                bool found = currentTypeInfo.IsValid();
                if (!found)
                {
                    string typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, type);

                    HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>();
                    IList <IFCAnyHandle>   repMapListOpt   = new List <IFCAnyHandle>();

                    styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, propertySetsOpt, repMapListOpt, element, type);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                    {
                        propertySetsOpt = ExporterUtil.ExtractElementTypeProperties(exporterIFC, type, styleHandle);
                        productWrapper.RegisterHandleWithElementType(type, styleHandle, propertySetsOpt);
                        string applicableOccurrence = NamingUtil.GetObjectTypeOverride(type, typeObjectType);
                        if (!string.IsNullOrEmpty(applicableOccurrence))
                        {
                            IFCAnyHandleUtil.SetAttribute(styleHandle, "ApplicableOccurrence", applicableOccurrence);
                        }
                        currentTypeInfo.Style = styleHandle;
                        ExporterCacheManager.TypeObjectsCache.Register(typeId, false, exportType, currentTypeInfo);
                    }
                }
                else
                {
                    styleHandle = currentTypeInfo.Style;
                }
            }

            string instanceGUID = GUIDUtil.CreateGUID(element);


            bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

            ElementId roomId = ElementId.InvalidElementId;

            if (roomRelated)
            {
                roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
            }

            IFCAnyHandle instanceHandle = null;

            // For MEP objects
            string exportEntityStr = exportType.ToString();

            Common.Enums.IFCEntityType exportEntity;

            if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
            {
                exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
            }
            if (Enum.TryParse(exportEntityStr, out exportEntity))
            {
                // For MEP object creation
                instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, exporterIFC, element, instanceGUID, ownerHistory,
                                                                            localPlacementToUse, productRepresentation);
            }

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                return;
            }

            if (roomId != ElementId.InvalidElementId)
            {
                //exporterIFC.RelateSpatialElement(roomId, instanceHandle);
                ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);
                productWrapper.AddElement(element, instanceHandle, setter, extraParams, false);
            }
            else
            {
                productWrapper.AddElement(element, instanceHandle, setter, extraParams, true);
            }

            OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, element, extraParams, null, exporterIFC, localPlacementToUse, setter, productWrapper);

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
            {
                ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle);
            }

            PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper.GetAllObjects());

            ExporterCacheManager.MEPCache.Register(element, instanceHandle);

            // add to system export cache
            // SystemExporter.ExportSystem(exporterIFC, element, instanceHandle);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Export the individual part (IfcBuildingElementPart).
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="partElement">The part element to export.</param>
        /// <param name="geometryElement">The geometry of part.</param>
        /// <param name="productWrapper">The ProductWrapper object.</param>
        public static void ExportPart(ExporterIFC exporterIFC, Element partElement, ProductWrapper productWrapper,
                                      PlacementSetter placementSetter, IFCAnyHandle originalPlacement, IFCRange range, IFCExtrusionAxes ifcExtrusionAxes,
                                      Element hostElement, ElementId overrideLevelId, bool asBuildingElement)
        {
            if (!ElementFilteringUtil.IsElementVisible(partElement))
            {
                return;
            }

            Part part = partElement as Part;

            if (part == null)
            {
                return;
            }

            if (!asBuildingElement)
            {
                // Check the intended IFC entity or type name is in the exclude list specified in the UI
                Common.Enums.IFCEntityType elementClassTypeEnum;
                if (Enum.TryParse <Common.Enums.IFCEntityType>("IfcBuildingElementPart", out elementClassTypeEnum))
                {
                    if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                    {
                        return;
                    }
                }
            }
            else
            {
                string        ifcEnumType = null;
                IFCExportType exportType  = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

                // Check the intended IFC entity or type name is in the exclude list specified in the UI
                Common.Enums.IFCEntityType elementClassTypeEnum;
                if (Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ToString(), out elementClassTypeEnum))
                {
                    if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                    {
                        return;
                    }
                }
            }

            PlacementSetter standalonePlacementSetter = null;
            bool            standaloneExport          = hostElement == null && !asBuildingElement;

            ElementId partExportLevel = null;

            if (standaloneExport || asBuildingElement)
            {
                partExportLevel = partElement.LevelId;
            }
            else
            {
                if (part.OriginalCategoryId != hostElement.Category.Id)
                {
                    return;
                }
                partExportLevel = hostElement.LevelId;
            }
            if (overrideLevelId != null)
            {
                partExportLevel = overrideLevelId;
            }

            if (ExporterCacheManager.PartExportedCache.HasExported(partElement.Id, partExportLevel))
            {
                return;
            }

            Options options   = GeometryUtil.GetIFCExportGeometryOptions();
            View    ownerView = partElement.Document.GetElement(partElement.OwnerViewId) as View;

            if (ownerView != null)
            {
                options.View = ownerView;
            }

            GeometryElement geometryElement = partElement.get_Geometry(options);

            if (geometryElement == null)
            {
                return;
            }

            try
            {
                IFCFile file = exporterIFC.GetFile();
                using (IFCTransaction transaction = new IFCTransaction(file))
                {
                    IFCAnyHandle partPlacement = null;
                    if (standaloneExport || asBuildingElement)
                    {
                        Transform orientationTrf = Transform.Identity;
                        standalonePlacementSetter = PlacementSetter.Create(exporterIFC, partElement, null, orientationTrf, partExportLevel);
                        partPlacement             = standalonePlacementSetter.LocalPlacement;
                    }
                    else
                    {
                        partPlacement = ExporterUtil.CreateLocalPlacement(file, originalPlacement, null);
                    }

                    bool validRange = (range != null && !MathUtil.IsAlmostZero(range.Start - range.End));

                    SolidMeshGeometryInfo solidMeshInfo;
                    if (validRange)
                    {
                        solidMeshInfo = GeometryUtil.GetSplitClippedSolidMeshGeometry(geometryElement, range);
                        if (solidMeshInfo.GetSolids().Count == 0 && solidMeshInfo.GetMeshes().Count == 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                    }

                    using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData())
                    {
                        extrusionCreationData.SetLocalPlacement(partPlacement);
                        extrusionCreationData.ReuseLocalPlacement   = false;
                        extrusionCreationData.PossibleExtrusionAxes = ifcExtrusionAxes;

                        IList <Solid> solids = solidMeshInfo.GetSolids();
                        IList <Mesh>  meshes = solidMeshInfo.GetMeshes();

                        ElementId catId     = CategoryUtil.GetSafeCategoryId(partElement);
                        ElementId hostCatId = CategoryUtil.GetSafeCategoryId(hostElement);

                        BodyData            bodyData            = null;
                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow);
                        if (solids.Count > 0 || meshes.Count > 0)
                        {
                            bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, solids, meshes,
                                                               bodyExporterOptions, extrusionCreationData);
                        }
                        else
                        {
                            IList <GeometryObject> geomlist = new List <GeometryObject>();
                            geomlist.Add(geometryElement);
                            bodyData = BodyExporter.ExportBody(exporterIFC, partElement, catId, ElementId.InvalidElementId, geomlist,
                                                               bodyExporterOptions, extrusionCreationData);
                        }

                        IFCAnyHandle bodyRep = bodyData.RepresentationHnd;
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(bodyRep))
                        {
                            extrusionCreationData.ClearOpenings();
                            return;
                        }

                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                        representations.Add(bodyRep);

                        IFCAnyHandle boundingBoxRep = BoundingBoxExporter.ExportBoundingBox(exporterIFC, geometryElement, Transform.Identity);
                        if (boundingBoxRep != null)
                        {
                            representations.Add(boundingBoxRep);
                        }

                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);

                        IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;

                        string partGUID        = GUIDUtil.CreateGUID(partElement);
                        string partName        = NamingUtil.GetNameOverride(partElement, NamingUtil.GetIFCName(partElement));
                        string partDescription = NamingUtil.GetDescriptionOverride(partElement, null);
                        string partObjectType  = NamingUtil.GetObjectTypeOverride(partElement, NamingUtil.CreateIFCObjectName(exporterIFC, partElement));
                        string partTag         = NamingUtil.GetTagOverride(partElement, NamingUtil.CreateIFCElementId(partElement));

                        IFCAnyHandle ifcPart = null;
                        if (!asBuildingElement)
                        {
                            ifcPart = IFCInstanceExporter.CreateBuildingElementPart(file, partGUID, ownerHistory, partName, partDescription,
                                                                                    partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partTag);
                        }
                        else
                        {
                            string        ifcEnumType = null;
                            IFCExportType exportType  = ExporterUtil.GetExportType(exporterIFC, hostElement, out ifcEnumType);

                            string defaultValue = null;
                            // This replicates old functionality before IFC4 addition, where the default for slab was "FLOOR".
                            // Really the export layer table should be fixed for this case.
                            if (string.IsNullOrWhiteSpace(ifcEnumType) && hostCatId == new ElementId(BuiltInCategory.OST_Floors))
                            {
                                ifcEnumType = "FLOOR";
                            }
                            ifcEnumType = IFCValidateEntry.GetValidIFCType(hostElement, ifcEnumType, defaultValue);

                            switch (exportType)
                            {
                            case IFCExportType.IfcColumnType:
                                ifcPart = IFCInstanceExporter.CreateColumn(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                           extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcCovering:
                                ifcPart = IFCInstanceExporter.CreateCovering(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                             extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcFooting:
                                ifcPart = IFCInstanceExporter.CreateFooting(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                            extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcPile:
                                ifcPart = IFCInstanceExporter.CreatePile(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType, null);
                                break;

                            case IFCExportType.IfcRoof:
                                ifcPart = IFCInstanceExporter.CreateRoof(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcSlab:
                                ifcPart = IFCInstanceExporter.CreateSlab(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            case IFCExportType.IfcWall:
                                ifcPart = IFCInstanceExporter.CreateWall(file, partGUID, ownerHistory, partName, partDescription, partObjectType,
                                                                         extrusionCreationData.GetLocalPlacement(), prodRep, partTag, ifcEnumType);
                                break;

                            default:
                                ifcPart = IFCInstanceExporter.CreateBuildingElementProxy(file, partGUID, ownerHistory, partName, partDescription,
                                                                                         partObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, partTag, null);
                                break;
                            }
                        }

                        bool            containedInLevel     = (standaloneExport || asBuildingElement);
                        PlacementSetter whichPlacementSetter = containedInLevel ? standalonePlacementSetter : placementSetter;
                        productWrapper.AddElement(partElement, ifcPart, whichPlacementSetter, extrusionCreationData, containedInLevel);

                        OpeningUtil.CreateOpeningsIfNecessary(ifcPart, partElement, extrusionCreationData, bodyData.OffsetTransform, exporterIFC,
                                                              extrusionCreationData.GetLocalPlacement(), whichPlacementSetter, productWrapper);

                        //Add the exported part to exported cache.
                        TraceExportedParts(partElement, partExportLevel, standaloneExport || asBuildingElement ? ElementId.InvalidElementId : hostElement.Id);

                        CategoryUtil.CreateMaterialAssociation(exporterIFC, ifcPart, bodyData.MaterialIds);

                        transaction.Commit();
                    }
                }
            }
            finally
            {
                if (standalonePlacementSetter != null)
                {
                    standalonePlacementSetter.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Exports a MEP family instance.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="exportType">The export type of the element.
        /// <param name="ifcEnumType">The sub-type of the element.</param></param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if an entity was created, false otherwise.</returns>
        public static bool Export(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, 
            IFCExportType exportType, string ifcEnumType, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();
            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle localPlacementToUse = setter.LocalPlacement;
                    using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                    {
                        extraParams.SetLocalPlacement(localPlacementToUse);

                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true);
                        BodyData bodyData = null;
                        IFCAnyHandle productRepresentation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                            element, catId, geometryElement, bodyExporterOptions, null, extraParams, out bodyData);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(productRepresentation))
                        {
                            extraParams.ClearOpenings();
                            return false;
                        }

                        IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle();
                        ElementId typeId = element.GetTypeId();
                        ElementType type = element.Document.GetElement(typeId) as ElementType;
                        FamilyTypeInfo currentTypeInfo = ExporterCacheManager.TypeObjectsCache.Find(typeId, false);

                        bool found = currentTypeInfo.IsValid();
                        if (!found)
                        {
                            string typeGUID = GUIDUtil.CreateGUID(type);
                            string typeName = NamingUtil.GetNameOverride(type, NamingUtil.GetIFCName(type));
                            string typeObjectType = NamingUtil.GetObjectTypeOverride(type, NamingUtil.CreateIFCObjectName(exporterIFC, type));
                            string applicableOccurence = NamingUtil.GetOverrideStringValue(type, "IfcApplicableOccurrence", typeObjectType);
                            string typeDescription = NamingUtil.GetDescriptionOverride(type, null);
                            string typeTag = NamingUtil.GetTagOverride(type, NamingUtil.CreateIFCElementId(type));
                            string typeElementType = NamingUtil.GetOverrideStringValue(type, "IfcElementType", typeName);

                            IList<IFCAnyHandle> repMapListOpt = new List<IFCAnyHandle>();

                            IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, typeGUID, typeName,
                               typeDescription, applicableOccurence, null, repMapListOpt, typeTag, typeElementType, element, type);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                            {
                                productWrapper.RegisterHandleWithElementType(type, styleHandle, null);

                                currentTypeInfo.Style = styleHandle;
                                ExporterCacheManager.TypeObjectsCache.Register(typeId, false, currentTypeInfo);
                            }
                        }
                        string instanceGUID = GUIDUtil.CreateGUID(element);
                        string instanceName = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                        string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceTag = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

                        bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

                        ElementId roomId = ElementId.InvalidElementId;
                        if (roomRelated)
                        {
                            roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
                        }

                        IFCAnyHandle instanceHandle = null;

                        // For MEP objects
                        string exportEntityStr = exportType.ToString();
                        Common.Enums.IFCEntityType exportEntity;

                        if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
                            exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
                        if (Enum.TryParse(exportEntityStr, out exportEntity))
                        {
                            // For MEP object creation
                            instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
                               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }


                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
                            return false;

                        bool relatedToSpace = (roomId != ElementId.InvalidElementId);
                        productWrapper.AddElement(element, instanceHandle, setter, extraParams, !relatedToSpace);
                        if (relatedToSpace)
                            ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);

                        OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, element, extraParams, null,
                            exporterIFC, localPlacementToUse, setter, productWrapper);

                        if (currentTypeInfo.IsValid())
                            ExporterCacheManager.TypeRelationsCache.Add(currentTypeInfo.Style, instanceHandle);

                        if (bodyData != null && bodyData.MaterialIds.Count != 0)
                            CategoryUtil.CreateMaterialAssociations(exporterIFC, instanceHandle, bodyData.MaterialIds);

                        ExporterCacheManager.MEPCache.Register(element, instanceHandle);

                        tr.Commit();
                    }
                }
            }
            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Exports a MEP family instance.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="element">The element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="exportType">The export type of the element.
        /// <param name="ifcEnumType">The sub-type of the element.</param></param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        /// <returns>True if an entity was created, false otherwise.</returns>
        public static bool Export(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement,
                                  IFCExportType exportType, string ifcEnumType, ProductWrapper productWrapper)
        {
            IFCFile file = exporterIFC.GetFile();

            using (IFCTransaction tr = new IFCTransaction(file))
            {
                using (PlacementSetter setter = PlacementSetter.Create(exporterIFC, element))
                {
                    IFCAnyHandle localPlacementToUse = setter.LocalPlacement;
                    using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData())
                    {
                        extraParams.SetLocalPlacement(localPlacementToUse);

                        ElementId catId = CategoryUtil.GetSafeCategoryId(element);

                        BodyExporterOptions bodyExporterOptions   = new BodyExporterOptions(true);
                        BodyData            bodyData              = null;
                        IFCAnyHandle        productRepresentation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                               element, catId, geometryElement, bodyExporterOptions, null, extraParams, out bodyData);
                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(productRepresentation))
                        {
                            extraParams.ClearOpenings();
                            return(false);
                        }

                        IFCAnyHandle   ownerHistory    = exporterIFC.GetOwnerHistoryHandle();
                        ElementId      typeId          = element.GetTypeId();
                        ElementType    type            = element.Document.GetElement(typeId) as ElementType;
                        FamilyTypeInfo currentTypeInfo = ExporterCacheManager.TypeObjectsCache.Find(typeId, false);

                        bool found = currentTypeInfo.IsValid();
                        if (!found)
                        {
                            string typeGUID            = GUIDUtil.CreateGUID(type);
                            string typeName            = NamingUtil.GetNameOverride(type, NamingUtil.GetIFCName(type));
                            string typeObjectType      = NamingUtil.GetObjectTypeOverride(type, NamingUtil.CreateIFCObjectName(exporterIFC, type));
                            string applicableOccurence = NamingUtil.GetOverrideStringValue(type, "IfcApplicableOccurrence", typeObjectType);
                            string typeDescription     = NamingUtil.GetDescriptionOverride(type, null);
                            string typeTag             = NamingUtil.GetTagOverride(type, NamingUtil.CreateIFCElementId(type));
                            string typeElementType     = NamingUtil.GetOverrideStringValue(type, "IfcElementType", typeName);

                            IList <IFCAnyHandle> repMapListOpt = new List <IFCAnyHandle>();

                            IFCAnyHandle styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, typeGUID, typeName,
                                                                                            typeDescription, applicableOccurence, null, repMapListOpt, typeTag, typeElementType, element, type);
                            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
                            {
                                productWrapper.RegisterHandleWithElementType(type, styleHandle, null);

                                currentTypeInfo.Style = styleHandle;
                                ExporterCacheManager.TypeObjectsCache.Register(typeId, false, currentTypeInfo);
                            }
                        }
                        string instanceGUID        = GUIDUtil.CreateGUID(element);
                        string instanceName        = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element));
                        string instanceObjectType  = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element));
                        string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
                        string instanceTag         = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

                        bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

                        ElementId roomId = ElementId.InvalidElementId;
                        if (roomRelated)
                        {
                            roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
                        }

                        IFCAnyHandle instanceHandle = null;

                        // For MEP objects
                        string exportEntityStr = exportType.ToString();
                        Common.Enums.IFCEntityType exportEntity;

                        if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
                        {
                            exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
                        }
                        if (Enum.TryParse(exportEntityStr, out exportEntity))
                        {
                            // For MEP object creation
                            instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
                                                                                        instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                        }


                        if (IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
                        {
                            return(false);
                        }

                        bool relatedToSpace = (roomId != ElementId.InvalidElementId);
                        productWrapper.AddElement(element, instanceHandle, setter, extraParams, !relatedToSpace);
                        if (relatedToSpace)
                        {
                            ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);
                        }

                        OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, element, extraParams, null,
                                                              exporterIFC, localPlacementToUse, setter, productWrapper);

                        if (currentTypeInfo.IsValid())
                        {
                            ExporterCacheManager.TypeRelationsCache.Add(currentTypeInfo.Style, instanceHandle);
                        }

                        if (bodyData != null && bodyData.MaterialIds.Count != 0)
                        {
                            CategoryUtil.CreateMaterialAssociations(exporterIFC, instanceHandle, bodyData.MaterialIds);
                        }

                        ExporterCacheManager.MEPCache.Register(element, instanceHandle);

                        tr.Commit();
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Exports IFC type.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="type">The export type.</param>
        /// <param name="ifcEnumType">The string value represents the IFC type.</param>
        /// <param name="guid">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="applicableOccurrence">The optional data type of the entity.</param>
        /// <param name="propertySets">The property sets.</param>
        /// <param name="representationMapList">List of representations.</param>
        /// <param name="elementTag">The element tag.</param>
        /// <param name="typeName">The type name.</param>
        /// <param name="instance">The family instance.</param>
        /// <param name="symbol">The element type.</param>
        /// <returns>The handle.</returns>
        private static IFCAnyHandle ExportGenericTypeBase(IFCFile file,
                                                          IFCExportType originalType,
                                                          string ifcEnumType,
                                                          string guid,
                                                          IFCAnyHandle ownerHistory,
                                                          string name,
                                                          string description,
                                                          string applicableOccurrence,
                                                          HashSet <IFCAnyHandle> propertySets,
                                                          IList <IFCAnyHandle> representationMapList,
                                                          string elementTag,
                                                          string typeName,
                                                          Element instance,
                                                          ElementType symbol)
        {
            // TODO: This routine needs to be simplified.  The long list of IFC2x3 and IFC4 calls to CreateGenericIFCType make it too easy to miss an entry.

            Revit.IFC.Common.Enums.IFCEntityType IFCTypeEntity;
            string typeAsString = originalType.ToString();

            // We'll accept the IFCExportType with or without "Type", but we'll append "Type" if we don't find it.
            if (string.Compare(typeAsString.Substring(typeAsString.Length - 4), "Type", true) != 0)
            {
                typeAsString += "Type";
            }

            if (!Enum.TryParse(typeAsString, out IFCTypeEntity))
            {
                return(null); // The export type is unknown IFC type entity
            }
            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcGasTerminalType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcBurnerType;
                    typeAsString  = IFCExportType.IfcBurnerType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcElectricHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcSpaceHeaterType;
                    typeAsString  = IFCExportType.IfcSpaceHeaterType.ToString();
                    break;
                }
            }
            else
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcBurnerType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcGasTerminalType;
                    typeAsString  = IFCExportType.IfcGasTerminalType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcSpaceHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcElectricHeaterType;
                    typeAsString  = IFCExportType.IfcElectricHeaterType.ToString();
                    break;
                }
            }

            string[] typeStr             = typeAsString.Split('.');
            string   desireTypeBase      = "Revit.IFC.Export.Toolkit.";
            string   desireTypeBaseExtra = ExporterCacheManager.ExportOptionsCache.ExportAs4 ? ".IFC4" : string.Empty;
            string   desireType          = desireTypeBase + desireTypeBaseExtra + typeStr[typeStr.Length - 1];

            object enumValue = null;

            {
                Type theEnumType = null;
                try
                {
                    // Not all entity types have enum values before IFC4.
                    theEnumType = Type.GetType(desireType, true, true);
                }
                catch
                {
                    theEnumType = null;
                }

                if (theEnumType != null)
                {
                    try
                    {
                        // Not all entity types have "NotDefined" as an option.
                        enumValue = Enum.Parse(theEnumType, "NotDefined", true);
                    }
                    catch
                    {
                        enumValue = null;
                    }
                }

                try
                {
                    string value = null;
                    if ((ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcExportType", out value) == null) &&
                        (ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcType", out value) == null))
                    {
                        value = ifcEnumType;
                    }

                    if (theEnumType != null && !string.IsNullOrEmpty(value))
                    {
                        object enumValuePar = Enum.Parse(theEnumType, value, true);
                        enumValue = enumValuePar;
                    }
                }
                catch
                {
                    enumValue = null;
                }
            }

            string enumValueAsString = (enumValue == null) ? null : enumValue.ToString();

            return(IFCInstanceExporter.CreateGenericIFCType(IFCTypeEntity, file, guid, ownerHistory, name,
                                                            description, applicableOccurrence, propertySets, representationMapList, elementTag,
                                                            typeName, enumValueAsString));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Exports a generic family instance as IFC instance.
        /// </summary>
        /// <param name="type">The export type.</param>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="familyInstance">The element.</param>
        /// <param name="wrapper">The ProductWrapper.</param>
        /// <param name="setter">The PlacementSetter.</param>
        /// <param name="extraParams">The extrusion creation data.</param>
        /// <param name="instanceGUID">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="instanceName">The name.</param>
        /// <param name="instanceDescription">The description.</param>
        /// <param name="instanceObjectType">The object type.</param>
        /// <param name="productRepresentation">The representation handle.</param>
        /// <param name="instanceTag">The tag for the entity, usually based on the element id.</param>
        /// <param name="ifcEnumType">The predefined type/shape type, if any, for the object.</param>
        /// <param name="overrideLocalPlacement">The local placement to use instead of the one in the placement setter, if appropriate.</param>
        /// <returns>The handle.</returns>
        public static IFCAnyHandle ExportGenericInstance(IFCExportType type,
                                                         ExporterIFC exporterIFC, Element familyInstance,
                                                         ProductWrapper wrapper, PlacementSetter setter, IFCExtrusionCreationData extraParams,
                                                         string instanceGUID, IFCAnyHandle ownerHistory,
                                                         string instanceName, string instanceDescription, string instanceObjectType,
                                                         IFCAnyHandle productRepresentation,
                                                         string instanceTag, string ifcEnumType, IFCAnyHandle overrideLocalPlacement)
        {
            IFCFile  file = exporterIFC.GetFile();
            Document doc  = familyInstance.Document;

            bool isRoomRelated      = IsRoomRelated(type);
            bool isChildInContainer = familyInstance.AssemblyInstanceId != ElementId.InvalidElementId;

            IFCAnyHandle localPlacementToUse = setter.LocalPlacement;
            ElementId    roomId = ElementId.InvalidElementId;

            if (isRoomRelated)
            {
                roomId = setter.UpdateRoomRelativeCoordinates(familyInstance, out localPlacementToUse);
            }

            //should remove the create method where there is no use of this handle for API methods
            //some places uses the return value of ExportGenericInstance as input parameter for API methods
            IFCAnyHandle instanceHandle = null;

            switch (type)
            {
            case IFCExportType.IfcBeam:
            case IFCExportType.IfcBeamType:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "BEAM" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateBeam(file, instanceGUID, ownerHistory,
                                                                instanceName, instanceDescription, instanceObjectType, localPlacementToUse,
                                                                productRepresentation, instanceTag, preDefinedType);
                break;
            }

            case IFCExportType.IfcColumn:
            case IFCExportType.IfcColumnType:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "COLUMN" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateColumn(file, instanceGUID, ownerHistory,
                                                                  instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag, preDefinedType);
                break;
            }

            case IFCExportType.IfcCurtainWall:
            case IFCExportType.IfcCurtainWallType:
            {
                instanceHandle = IFCInstanceExporter.CreateCurtainWall(file, instanceGUID, ownerHistory,
                                                                       instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcMember:
            case IFCExportType.IfcMemberType:
            {
                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "BRACE" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreateMember(file, instanceGUID, ownerHistory,
                                                                  instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag, preDefinedType);

                // Register the members's IFC handle for later use by truss export.
                ExporterCacheManager.ElementToHandleCache.Register(familyInstance.Id, instanceHandle);
                break;
            }

            case IFCExportType.IfcPlate:
            case IFCExportType.IfcPlateType:
            {
                IFCAnyHandle localPlacement = localPlacementToUse;
                if (overrideLocalPlacement != null)
                {
                    isChildInContainer = true;
                    localPlacement     = overrideLocalPlacement;
                }

                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "NOTDEFINED" : ifcEnumType;
                instanceHandle = IFCInstanceExporter.CreatePlate(file, instanceGUID, ownerHistory,
                                                                 instanceName, instanceDescription, instanceObjectType, localPlacement, productRepresentation, instanceTag, preDefinedType);
                break;
            }

            case IFCExportType.IfcDiscreteAccessoryType:
            {
                instanceHandle = IFCInstanceExporter.CreateDiscreteAccessory(file, instanceGUID, ownerHistory,
                                                                             instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcDistributionControlElement:
            {
                instanceHandle = IFCInstanceExporter.CreateDistributionControlElement(file, instanceGUID, ownerHistory,
                                                                                      instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                                      null);
                break;
            }

            case IFCExportType.IfcDistributionFlowElement:
            {
                instanceHandle = IFCInstanceExporter.CreateDistributionFlowElement(file, instanceGUID, ownerHistory,
                                                                                   instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcDistributionChamberElement:
            case IFCExportType.IfcDistributionChamberElementType:
            {
                instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(Common.Enums.IFCEntityType.IfcDistributionChamberElement, file, instanceGUID, ownerHistory,
                                                                            instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcFastenerType:
            {
                instanceHandle = IFCInstanceExporter.CreateFastener(file, instanceGUID, ownerHistory,
                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                break;
            }

            case IFCExportType.IfcMechanicalFastenerType:
            {
                double?nominalDiameter = null;
                double?nominalLength   = null;

                double nominalDiameterVal, nominalLengthVal;
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalDiameter", out nominalDiameterVal) != null)
                {
                    nominalDiameter = UnitUtil.ScaleLength(nominalDiameterVal);
                }
                if (ParameterUtil.GetDoubleValueFromElementOrSymbol(familyInstance, "NominalLength", out nominalLengthVal) != null)
                {
                    nominalLength = UnitUtil.ScaleLength(nominalLengthVal);
                }

                string preDefinedType = string.IsNullOrWhiteSpace(ifcEnumType) ? "NOTDEFINED" : ifcEnumType;

                instanceHandle = IFCInstanceExporter.CreateMechanicalFastener(file, instanceGUID, ownerHistory,
                                                                              instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                              nominalDiameter, nominalLength, preDefinedType);
                break;
            }

            case IFCExportType.IfcRailingType:
            {
                string        strEnumType;
                IFCExportType exportAs = ExporterUtil.GetExportType(exporterIFC, familyInstance, out strEnumType);
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                {
                    instanceHandle = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                                                       instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                       GetPreDefinedType <Toolkit.IFC4.IFCRailingType>(familyInstance, strEnumType).ToString());
                }
                else
                {
                    instanceHandle = IFCInstanceExporter.CreateRailing(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                                                       instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                                                                       GetPreDefinedType <Toolkit.IFCRailingType>(familyInstance, strEnumType).ToString());
                }
                break;
            }

            case IFCExportType.IfcSpace:
            {
                string instanceLongName = NamingUtil.GetLongNameOverride(familyInstance, NamingUtil.GetLongNameOverride(familyInstance, instanceName));
                IFCInternalOrExternal internalOrExternal = CategoryUtil.IsElementExternal(familyInstance) ? IFCInternalOrExternal.External : IFCInternalOrExternal.Internal;

                instanceHandle = IFCInstanceExporter.CreateSpace(file, instanceGUID, ownerHistory, instanceName, instanceDescription,
                                                                 instanceObjectType, localPlacementToUse, productRepresentation, instanceLongName, IFCElementComposition.Element,
                                                                 internalOrExternal, null);
                break;
            }

            default:
            {
                if (ExporterCacheManager.ExportOptionsCache.ExportAs4 &&
                    (type == IFCExportType.IfcDistributionElement ||
                     type == IFCExportType.IfcEnergyConversionDevice ||
                     type == IFCExportType.IfcFlowController ||
                     type == IFCExportType.IfcFlowFitting ||
                     type == IFCExportType.IfcFlowMovingDevice ||
                     type == IFCExportType.IfcFlowSegment ||
                     type == IFCExportType.IfcFlowStorageDevice ||
                     type == IFCExportType.IfcFlowTerminal ||
                     type == IFCExportType.IfcFlowTreatmentDevice))
                {
                    // for IFC4, there are several entities that are valid in IFC2x3 but now have been made abstract or deprecated, so cannot be created. Create proxy instead.
                    //instanceHandle = IFCInstanceExporter.CreateBuildingElementProxy(file, instanceGUID, ownerHistory,
                    //    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag,
                    //    Toolkit.IFC4.IFCBuildingElementProxyType.USERDEFINED.ToString());
                    Common.Enums.IFCEntityType exportEntity = Common.Enums.IFCEntityType.UnKnown;
                    if (Enum.TryParse(type.ToString(), out exportEntity))
                    {
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                    }
                }
                else if ((type == IFCExportType.IfcPile) ||
                         (type == IFCExportType.IfcFurnishingElement) || IsFurnishingElementSubType(type) ||
                         (type == IFCExportType.IfcEnergyConversionDevice) || IsEnergyConversionDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowFitting) || IsFlowFittingSubType(type) ||
                         (type == IFCExportType.IfcFlowMovingDevice) || IsFlowMovingDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowSegment) || IsFlowSegmentSubType(type) ||
                         (type == IFCExportType.IfcFlowStorageDevice) || IsFlowStorageDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowTerminal) || IsFlowTerminalSubType(type) ||
                         (type == IFCExportType.IfcFlowTreatmentDevice) || IsFlowTreatmentDeviceSubType(type) ||
                         (type == IFCExportType.IfcFlowController) || IsFlowControllerSubType(type) ||
                         (type == IFCExportType.IfcDistributionFlowElement) || IsDistributionFlowElementSubType(type) ||
                         (type == IFCExportType.IfcDistributionControlElement) || IsDistributionControlElementSubType(type) ||
                         (type == IFCExportType.IfcBuildingElementProxy) || (type == IFCExportType.IfcBuildingElementProxyType))
                {
                    string exportEntityStr = type.ToString();
                    Common.Enums.IFCEntityType exportEntity = Common.Enums.IFCEntityType.UnKnown;

                    if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
                    {
                        exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
                    }
                    if (!Enum.TryParse(exportEntityStr, out exportEntity))
                    {
                        // This is a special case.   IFC2x3 has IfcFlowElement for the instance, and both IfcElectricHeaterType and IfcSpaceHeaterType.
                        // IFC4 has IfcSpaceHeater and IfcSpaceHeaterType.
                        // Since IfcElectricHeater doesn't exist in IFC4, TryParse will fail.  For the instance only, we will map it to IfcSpaceHeater,
                        // which will in turn be redirected to IfcFlowElement for IFC2x3, if necessary.
                        if (type == IFCExportType.IfcElectricHeaterType)
                        {
                            exportEntity = Common.Enums.IFCEntityType.IfcSpaceHeater;
                        }
                        else
                        {
                            exportEntity = Common.Enums.IFCEntityType.UnKnown;
                        }
                    }

                    if (exportEntity != Common.Enums.IFCEntityType.UnKnown)
                    {
                        instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
                                                                                    instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
                    }
                }
                break;
            }
            }

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            {
                bool containedInSpace = (roomId != ElementId.InvalidElementId);
                bool associateToLevel = containedInSpace ? false : !isChildInContainer;
                wrapper.AddElement(familyInstance, instanceHandle, setter, extraParams, associateToLevel);
                if (containedInSpace)
                {
                    ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);
                }
            }
            return(instanceHandle);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Exports a CeilingAndFloor element to IFC.
        /// </summary>
        /// <param name="exporterIFC">The ExporterIFC object.</param>
        /// <param name="floor">The floor element.</param>
        /// <param name="geometryElement">The geometry element.</param>
        /// <param name="productWrapper">The ProductWrapper.</param>
        public static void ExportCeilingAndFloorElement(ExporterIFC exporterIFC, CeilingAndFloor floorElement, GeometryElement geometryElement,
                                                        ProductWrapper productWrapper)
        {
            if (geometryElement == null)
            {
                return;
            }

            // export parts or not
            bool exportParts = PartExporter.CanExportParts(floorElement);

            if (exportParts && !PartExporter.CanExportElementInPartExport(floorElement, floorElement.LevelId, false))
            {
                return;
            }

            IFCFile file = exporterIFC.GetFile();

            string        ifcEnumType;
            IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, floorElement, out ifcEnumType);

            // Check the intended IFC entity or type name is in the exclude list specified in the UI
            Common.Enums.IFCEntityType elementClassTypeEnum;
            if (Enum.TryParse <Common.Enums.IFCEntityType>(exportType.ToString(), out elementClassTypeEnum))
            {
                if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(elementClassTypeEnum))
                {
                    return;
                }
            }


            using (IFCTransaction tr = new IFCTransaction(file))
            {
                bool canExportAsContainerOrWithExtrusionAnalyzer = (!exportParts && (floorElement is Floor));

                if (canExportAsContainerOrWithExtrusionAnalyzer)
                {
                    // Try to export the Floor slab as a container.  If that succeeds, we are done.
                    // If we do export the floor as a container, it will take care of the local placement and transform there, so we need to leave
                    // this out of the IFCTransformSetter and PlacementSetter scopes below, or else we'll get double transforms.
                    IFCAnyHandle floorHnd = RoofExporter.ExportRoofOrFloorAsContainer(exporterIFC, ifcEnumType, floorElement, geometryElement, productWrapper);
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(floorHnd))
                    {
                        tr.Commit();
                        return;
                    }
                }

                IList <IFCAnyHandle> slabHnds        = new List <IFCAnyHandle>();
                IList <IFCAnyHandle> brepSlabHnds    = new List <IFCAnyHandle>();
                IList <IFCAnyHandle> nonBrepSlabHnds = new List <IFCAnyHandle>();

                using (IFCTransformSetter transformSetter = IFCTransformSetter.Create())
                {
                    using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, floorElement))
                    {
                        IFCAnyHandle localPlacement = placementSetter.LocalPlacement;
                        IFCAnyHandle ownerHistory   = ExporterCacheManager.OwnerHistoryHandle;

                        // The routine ExportExtrudedSlabOpenings is called if exportedAsInternalExtrusion is true, and it requires having a valid level association.
                        // Disable calling ExportSlabAsExtrusion if we can't handle potential openings.
                        bool canExportAsInternalExtrusion = placementSetter.LevelInfo != null;
                        bool exportedAsInternalExtrusion  = false;

                        ElementId catId = CategoryUtil.GetSafeCategoryId(floorElement);

                        IList <IFCAnyHandle>             prodReps        = new List <IFCAnyHandle>();
                        IList <ShapeRepresentationType>  repTypes        = new List <ShapeRepresentationType>();
                        IList <IList <CurveLoop> >       extrusionLoops  = new List <IList <CurveLoop> >();
                        IList <IFCExtrusionCreationData> loopExtraParams = new List <IFCExtrusionCreationData>();
                        Plane floorPlane = GeometryUtil.CreateDefaultPlane();

                        IList <IFCAnyHandle> localPlacements = new List <IFCAnyHandle>();

                        if (canExportAsContainerOrWithExtrusionAnalyzer)
                        {
                            Floor floor = floorElement as Floor;

                            // Next, try to use the ExtrusionAnalyzer for the limited cases it handles - 1 solid, no openings, end clippings only.
                            // Also limited to cases with line and arc boundaries.
                            //
                            SolidMeshGeometryInfo solidMeshInfo = GeometryUtil.GetSplitSolidMeshGeometry(geometryElement);
                            IList <Solid>         solids        = solidMeshInfo.GetSolids();
                            IList <Mesh>          meshes        = solidMeshInfo.GetMeshes();

                            if (solids.Count == 1 && meshes.Count == 0)
                            {
                                bool completelyClipped;
                                // floorExtrusionDirection is set to (0, 0, -1) because extrusionAnalyzerFloorPlane is computed from the top face of the floor
                                XYZ floorExtrusionDirection = new XYZ(0, 0, -1);
                                XYZ modelOrigin             = XYZ.Zero;

                                XYZ floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                if (floorOrigin == null)
                                {
                                    // GetVerticalProjectionPoint may return null if FloorFace.Top is an edited face that doesn't
                                    // go through the Revit model origin.  We'll try the midpoint of the bounding box instead.
                                    BoundingBoxXYZ boundingBox = floorElement.get_BoundingBox(null);
                                    modelOrigin = (boundingBox.Min + boundingBox.Max) / 2.0;
                                    floorOrigin = floor.GetVerticalProjectionPoint(modelOrigin, FloorFace.Top);
                                }

                                if (floorOrigin != null)
                                {
                                    XYZ   floorDir = floor.GetNormalAtVerticalProjectionPoint(floorOrigin, FloorFace.Top);
                                    Plane extrusionAnalyzerFloorBasePlane = GeometryUtil.CreatePlaneByNormalAtOrigin(floorDir);

                                    GenerateAdditionalInfo additionalInfo     = ExporterCacheManager.ExportOptionsCache.ExportAs4 ? GenerateAdditionalInfo.GenerateFootprint : GenerateAdditionalInfo.None;
                                    HandleAndData          floorAndProperties =
                                        ExtrusionExporter.CreateExtrusionWithClippingAndProperties(exporterIFC, floorElement,
                                                                                                   catId, solids[0], extrusionAnalyzerFloorBasePlane, floorOrigin, floorExtrusionDirection, null, out completelyClipped,
                                                                                                   addInfo: additionalInfo);
                                    if (completelyClipped)
                                    {
                                        return;
                                    }
                                    if (floorAndProperties.Handle != null)
                                    {
                                        IList <IFCAnyHandle> representations = new List <IFCAnyHandle>();
                                        representations.Add(floorAndProperties.Handle);

                                        // Footprint representation will only be exported in export to IFC4
                                        if (((additionalInfo & GenerateAdditionalInfo.GenerateFootprint) != 0) && (floorAndProperties.FootprintInfo != null))
                                        {
                                            if (!(IFCAnyHandleUtil.IsNullOrHasNoValue(floorAndProperties.FootprintInfo.FootPrintHandle)))
                                            {
                                                representations.Add(floorAndProperties.FootprintInfo.FootPrintHandle);
                                            }
                                        }

                                        IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                        prodReps.Add(prodRep);
                                        repTypes.Add(ShapeRepresentationType.SweptSolid);

                                        if (floorAndProperties.Data != null)
                                        {
                                            loopExtraParams.Add(floorAndProperties.Data);
                                        }
                                    }
                                }
                            }
                        }

                        // Use internal routine as backup that handles openings.
                        if (prodReps.Count == 0 && canExportAsInternalExtrusion)
                        {
                            //IList<IFCAnyHandle> prodRepsTmp = new List<IFCAnyHandle>();
                            exportedAsInternalExtrusion = ExporterIFCUtils.ExportSlabAsExtrusion(exporterIFC, floorElement,
                                                                                                 geometryElement, transformSetter, localPlacement, out localPlacements, out prodReps,
                                                                                                 out extrusionLoops, out loopExtraParams, floorPlane);
                            for (int ii = 0; ii < prodReps.Count; ii++)
                            {
                                // all are extrusions
                                repTypes.Add(ShapeRepresentationType.SweptSolid);

                                // Footprint representation will only be exported in export to IFC4
                                if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                                {
                                    // Get back the representations, we need to add the Footprint to it
                                    //IList<IFCAnyHandle> representations = IFCAnyHandleUtil.GetRepresentations(prodRepsTmp[ii]);

                                    if (extrusionLoops.Count > ii)
                                    {
                                        if (extrusionLoops[ii].Count > 0)
                                        {
                                            // Get the extrusion footprint using the first Curveloop. Transform needs to be obtained from the returned local placement
                                            Transform    lcs = ExporterIFCUtils.GetUnscaledTransform(exporterIFC, localPlacements[ii]);
                                            IFCAnyHandle footprintGeomRepItem = GeometryUtil.CreateIFCCurveFromCurveLoop(exporterIFC, extrusionLoops[ii][0], lcs, floorPlane.Normal);

                                            IFCAnyHandle        contextOfItemsFootprint = exporterIFC.Get3DContextHandle("FootPrint");
                                            ISet <IFCAnyHandle> repItem = new HashSet <IFCAnyHandle>();
                                            repItem.Add(footprintGeomRepItem);
                                            IFCAnyHandle footprintShapeRepresentation = RepresentationUtil.CreateBaseShapeRepresentation(exporterIFC, contextOfItemsFootprint, "FootPrint", "Curve2D", repItem);
                                            //representations.Add(footprintShapeRepresentation);
                                            IList <IFCAnyHandle> reps = new List <IFCAnyHandle>();
                                            reps.Add(footprintShapeRepresentation);
                                            IFCAnyHandleUtil.AddRepresentations(prodReps[ii], reps);
                                        }
                                    }
                                    //IFCAnyHandle prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, representations);
                                    //prodReps.Add(prodRep);
                                }
                                else
                                {
                                    //prodReps.Add(prodRepsTmp[ii]);
                                }

                                // We do not need the prodRepsTmp anymore, delete the handle:
                                //prodRepsTmp[ii].Delete();
                            }
                        }

                        if (prodReps.Count == 0)
                        {
                            using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData())
                            {
                                // Brep representation using tesellation after ExportSlabAsExtrusion does not return prodReps
                                BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.Medium);
                                BodyData            bodyData;
                                IFCAnyHandle        prodDefHnd = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC,
                                                                                                                            floorElement, catId, geometryElement, bodyExporterOptions, null, ecData, out bodyData);
                                if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodDefHnd))
                                {
                                    ecData.ClearOpenings();
                                    return;
                                }

                                prodReps.Add(prodDefHnd);
                                repTypes.Add(bodyData.ShapeRepresentationType);
                            }
                        }

                        // Create the slab from either the extrusion or the BRep information.
                        string ifcGUID = GUIDUtil.CreateGUID(floorElement);

                        int numReps = exportParts ? 1 : prodReps.Count;

                        string entityType = null;

                        switch (exportType)
                        {
                        case IFCExportType.IfcFooting:
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <Revit.IFC.Export.Toolkit.IFC4.IFCFootingType>(floorElement, ifcEnumType, null);
                            }
                            else
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <IFCFootingType>(floorElement, ifcEnumType, null);
                            }
                            break;

                        case IFCExportType.IfcCovering:
                            entityType = IFCValidateEntry.GetValidIFCType <IFCCoveringType>(floorElement, ifcEnumType, "FLOORING");
                            break;

                        case IFCExportType.IfcRamp:
                            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <Revit.IFC.Export.Toolkit.IFC4.IFCRampType>(floorElement, ifcEnumType, null);
                            }
                            else
                            {
                                entityType = IFCValidateEntry.GetValidIFCType <IFCRampType>(floorElement, ifcEnumType, null);
                            }
                            break;

                        default:
                            bool            isBaseSlab      = false;
                            AnalyticalModel analyticalModel = floorElement.GetAnalyticalModel();
                            if (analyticalModel != null)
                            {
                                AnalyzeAs slabFoundationType = analyticalModel.GetAnalyzeAs();
                                isBaseSlab = (slabFoundationType == AnalyzeAs.SlabOnGrade) || (slabFoundationType == AnalyzeAs.Mat);
                            }
                            entityType = IFCValidateEntry.GetValidIFCType <IFCSlabType>(floorElement, ifcEnumType, isBaseSlab ? "BASESLAB" : "FLOOR");
                            break;
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            string ifcName        = NamingUtil.GetNameOverride(floorElement, NamingUtil.GetIFCNamePlusIndex(floorElement, ii == 0 ? -1 : ii + 1));
                            string ifcDescription = NamingUtil.GetDescriptionOverride(floorElement, null);
                            string ifcObjectType  = NamingUtil.GetObjectTypeOverride(floorElement, exporterIFC.GetFamilyName());
                            string ifcTag         = NamingUtil.GetTagOverride(floorElement, NamingUtil.CreateIFCElementId(floorElement));

                            string       currentGUID       = (ii == 0) ? ifcGUID : GUIDUtil.CreateGUID();
                            IFCAnyHandle localPlacementHnd = exportedAsInternalExtrusion ? localPlacements[ii] : localPlacement;

                            IFCAnyHandle slabHnd = null;

                            // TODO: replace with CreateGenericBuildingElement.
                            switch (exportType)
                            {
                            case IFCExportType.IfcFooting:
                                slabHnd = IFCInstanceExporter.CreateFooting(file, currentGUID, ownerHistory, ifcName,
                                                                            ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                            ifcTag, entityType);
                                break;

                            case IFCExportType.IfcCovering:
                                slabHnd = IFCInstanceExporter.CreateCovering(file, currentGUID, ownerHistory, ifcName,
                                                                             ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                             ifcTag, entityType);
                                break;

                            case IFCExportType.IfcRamp:
                                slabHnd = IFCInstanceExporter.CreateRamp(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, entityType);
                                break;

                            default:
                                //if ((canExportAsInternalExtrusion || exportedAsInternalExtrusion) && ExporterCacheManager.ExportOptionsCache.ExportAs4)
                                //{
                                //    slabHnd = IFCInstanceExporter.CreateSlabStandardCase(file, currentGUID, ownerHistory, ifcName,
                                //        ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                //        ifcTag, entityType);
                                //}
                                //else
                                slabHnd = IFCInstanceExporter.CreateSlab(file, currentGUID, ownerHistory, ifcName,
                                                                         ifcDescription, ifcObjectType, localPlacementHnd, exportParts ? null : prodReps[ii],
                                                                         ifcTag, entityType);
                                break;
                            }

                            if (IFCAnyHandleUtil.IsNullOrHasNoValue(slabHnd))
                            {
                                return;
                            }

                            if (exportParts)
                            {
                                PartExporter.ExportHostPart(exporterIFC, floorElement, slabHnd, productWrapper, placementSetter, localPlacementHnd, null);
                            }

                            slabHnds.Add(slabHnd);

                            if (!exportParts)
                            {
                                if (repTypes[ii] == ShapeRepresentationType.Brep)
                                {
                                    brepSlabHnds.Add(slabHnd);
                                }
                                else
                                {
                                    nonBrepSlabHnds.Add(slabHnd);
                                }
                            }
                        }

                        for (int ii = 0; ii < numReps; ii++)
                        {
                            IFCExtrusionCreationData loopExtraParam = ii < loopExtraParams.Count ? loopExtraParams[ii] : null;
                            productWrapper.AddElement(floorElement, slabHnds[ii], placementSetter, loopExtraParam, true);
                        }

                        // This call to the native function appears to create Brep opening also when appropriate. But the creation of the IFC instances is not
                        //   controllable from the managed code. Therefore in some cases BRep geometry for Opening will still be exported even in the Reference View
                        if (exportedAsInternalExtrusion)
                        {
                            ExporterIFCUtils.ExportExtrudedSlabOpenings(exporterIFC, floorElement, placementSetter.LevelInfo,
                                                                        localPlacements[0], slabHnds, extrusionLoops, floorPlane, productWrapper.ToNative());
                        }
                        //// For now we have to be content without IfcOpeningStandardCase from the openings created by this native call because it is too much to
                        ////    "reverse engineer" the IFChandle
                        //foreach (IFCAnyHandle slabHandle in slabHnds)
                        //{
                        //    updateOpeningProfileRep(exporterIFC, slabHandle);
                        //}
                    }

                    if (!exportParts)
                    {
                        if (nonBrepSlabHnds.Count > 0)
                        {
                            HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, nonBrepSlabHnds,
                                                                         geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, false);
                        }
                        if (brepSlabHnds.Count > 0)
                        {
                            HostObjectExporter.ExportHostObjectMaterials(exporterIFC, floorElement, brepSlabHnds,
                                                                         geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis3, true);
                        }
                    }
                }
                tr.Commit();

                return;
            }
        }
      private static void ExportAsMappedItem(ExporterIFC exporterIFC, Element element, IFCFile file, IFCExportType exportType, string ifcEnumType, IFCExtrusionCreationData extraParams,
          PlacementSetter setter, IFCAnyHandle localPlacementToUse, IFCAnyHandle productRepresentation, ProductWrapper productWrapper)
      {
         IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle;
         ElementId typeId = element.GetTypeId();
         ElementType type = element.Document.GetElement(typeId) as ElementType;
         IFCAnyHandle styleHandle = null;

         if (type != null)
         {
            FamilyTypeInfo currentTypeInfo = ExporterCacheManager.TypeObjectsCache.Find(typeId, false, exportType);

            bool found = currentTypeInfo.IsValid();
            if (!found)
            {
               string typeGUID = GUIDUtil.CreateGUID(type);
               string typeName = NamingUtil.GetIFCName(type);
               string typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, type);
               string applicableOccurance = NamingUtil.GetObjectTypeOverride(type, typeObjectType);
               string typeDescription = NamingUtil.GetDescriptionOverride(type, null);
               string typeElemId = NamingUtil.CreateIFCElementId(type);

               HashSet<IFCAnyHandle> propertySetsOpt = new HashSet<IFCAnyHandle>();
               IList<IFCAnyHandle> repMapListOpt = new List<IFCAnyHandle>();

               styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, typeGUID, typeName,
                   typeDescription, applicableOccurance, propertySetsOpt, repMapListOpt, typeElemId, typeName, element, type);
               if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
               {
                  currentTypeInfo.Style = styleHandle;
                  ExporterCacheManager.TypeObjectsCache.Register(typeId, false, exportType, currentTypeInfo);
               }
            }
            else
            {
               styleHandle = currentTypeInfo.Style;
            }
         }

         string instanceGUID = GUIDUtil.CreateGUID(element);
         string instanceName = NamingUtil.GetIFCName(element);
         string objectType = NamingUtil.CreateIFCObjectName(exporterIFC, element);
         string instanceObjectType = NamingUtil.GetObjectTypeOverride(element, objectType);
         string instanceDescription = NamingUtil.GetDescriptionOverride(element, null);
         string instanceElemId = NamingUtil.CreateIFCElementId(element);
         string instanceTag = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element));

         bool roomRelated = !FamilyExporterUtil.IsDistributionFlowElementSubType(exportType);

         ElementId roomId = ElementId.InvalidElementId;
         if (roomRelated)
         {
            roomId = setter.UpdateRoomRelativeCoordinates(element, out localPlacementToUse);
         }

         IFCAnyHandle instanceHandle = null;

         // For MEP objects
         string exportEntityStr = exportType.ToString();
         Common.Enums.IFCEntityType exportEntity;

         if (String.Compare(exportEntityStr.Substring(exportEntityStr.Length - 4), "Type", true) == 0)
            exportEntityStr = exportEntityStr.Substring(0, (exportEntityStr.Length - 4));
         if (Enum.TryParse(exportEntityStr, out exportEntity))
         {
            // For MEP object creation
            instanceHandle = IFCInstanceExporter.CreateGenericIFCEntity(exportEntity, file, instanceGUID, ownerHistory,
               instanceName, instanceDescription, instanceObjectType, localPlacementToUse, productRepresentation, instanceTag);
         }

         if (IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle))
            return;

         if (roomId != ElementId.InvalidElementId)
         {
            //exporterIFC.RelateSpatialElement(roomId, instanceHandle);
            ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle);
            productWrapper.AddElement(element, instanceHandle, setter, extraParams, false);
         }
         else
         {
            productWrapper.AddElement(element, instanceHandle, setter, extraParams, true);
         }

         OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, element, extraParams, null, exporterIFC, localPlacementToUse, setter, productWrapper);

         if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle))
            ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle);

         PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper.GetAllObjects());

         ExporterCacheManager.MEPCache.Register(element, instanceHandle);

         // add to system export cache
         // SystemExporter.ExportSystem(exporterIFC, element, instanceHandle);
      }
Ejemplo n.º 9
0
        /// <summary>
        /// Exports IFC type.
        /// </summary>
        /// <param name="file">The IFC file.</param>
        /// <param name="type">The export type.</param>
        /// <param name="ifcEnumType">The string value represents the IFC type.</param>
        /// <param name="guid">The guid.</param>
        /// <param name="ownerHistory">The owner history handle.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        /// <param name="applicableOccurrence">The optional data type of the entity.</param>
        /// <param name="propertySets">The property sets.</param>
        /// <param name="representationMapList">List of representations.</param>
        /// <param name="elementTag">The element tag.</param>
        /// <param name="typeName">The type name.</param>
        /// <param name="instance">The family instance.</param>
        /// <param name="symbol">The element type.</param>
        /// <returns>The handle.</returns>
        private static IFCAnyHandle ExportGenericTypeBase(IFCFile file,
                                                          IFCExportType originalType,
                                                          string ifcEnumType,
                                                          HashSet <IFCAnyHandle> propertySets,
                                                          IList <IFCAnyHandle> representationMapList,
                                                          Element instance,
                                                          ElementType symbol)
        {
            Revit.IFC.Common.Enums.IFCEntityType IFCTypeEntity;
            string typeAsString = originalType.ToString();

            // We'll accept the IFCExportType with or without "Type", but we'll append "Type" if we don't find it.
            if (string.Compare(typeAsString.Substring(typeAsString.Length - 4), "Type", true) != 0)
            {
                typeAsString += "Type";
            }

            if (!Enum.TryParse(typeAsString, out IFCTypeEntity))
            {
                return(null); // The export type is unknown IFC type entity
            }
            if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcGasTerminalType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcBurnerType;
                    typeAsString  = IFCExportType.IfcBurnerType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcElectricHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcSpaceHeaterType;
                    typeAsString  = IFCExportType.IfcSpaceHeaterType.ToString();
                    break;
                }
            }
            else
            {
                // TODO: Create a routine that does this mapping automatically.
                switch (IFCTypeEntity)
                {
                case Common.Enums.IFCEntityType.IfcBurnerType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcGasTerminalType;
                    typeAsString  = IFCExportType.IfcGasTerminalType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcSpaceHeaterType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcElectricHeaterType;
                    typeAsString  = IFCExportType.IfcElectricHeaterType.ToString();
                    break;

                case Common.Enums.IFCEntityType.IfcDoorType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcDoorStyle;
                    break;

                case Common.Enums.IFCEntityType.IfcWindowType:
                    IFCTypeEntity = Common.Enums.IFCEntityType.IfcWindowStyle;
                    break;
                }
            }
            switch (IFCTypeEntity) //Use SuperType if Abstract, not all listed yet.
            {
            case Common.Enums.IFCEntityType.IfcEnergyConversionDeviceType:
            case Common.Enums.IFCEntityType.IfcFlowControllerType:
            case Common.Enums.IFCEntityType.IfcFlowFittingType:
            case Common.Enums.IFCEntityType.IfcFlowMovingDeviceType:
            case Common.Enums.IFCEntityType.IfcFlowSegmentType:
            case Common.Enums.IFCEntityType.IfcFlowStorageDeviceType:
            case Common.Enums.IFCEntityType.IfcFlowTerminalType:
            case Common.Enums.IFCEntityType.IfcFlowTreatmentDeviceType:
                IFCTypeEntity = Common.Enums.IFCEntityType.IfcDistributionElementType;
                typeAsString  = "IfcDistributionElementType";
                break;
            }
            string[] typeStr              = typeAsString.Split('.');
            string   desiredTypeBase      = "Revit.IFC.Export.Toolkit.";
            string   desiredTypeBaseExtra = ExporterCacheManager.ExportOptionsCache.ExportAs4 ? "IFC4." : string.Empty;
            string   desiredType          = desiredTypeBase + desiredTypeBaseExtra + typeStr[typeStr.Length - 1];

            object enumValue = null;

            {
                Type theEnumType = null;
                try
                {
                    // Not all entity types have enum values before IFC4.
                    theEnumType = Type.GetType(desiredType, true, true);
                }
                catch
                {
                    theEnumType = null;
                }

                if (theEnumType != null)
                {
                    try
                    {
                        // Not all entity types have "NotDefined" as an option.
                        enumValue = Enum.Parse(theEnumType, "NotDefined", true);
                    }
                    catch
                    {
                        enumValue = null;
                    }
                }

                try
                {
                    string value = null;
                    if ((ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcExportType", out value) == null) &&
                        (ParameterUtil.GetStringValueFromElementOrSymbol(instance, "IfcType", out value) == null))
                    {
                        value = ifcEnumType;
                    }

                    if (theEnumType != null && !string.IsNullOrEmpty(value))
                    {
                        object enumValuePar = Enum.Parse(theEnumType, value, true);
                        enumValue = enumValuePar;
                    }
                }
                catch
                {
                    enumValue = null;
                }
            }

            string enumValueAsString = (enumValue == null) ? null : enumValue.ToString();

            return(IFCInstanceExporter.CreateGenericIFCType(IFCTypeEntity, symbol, file, propertySets, representationMapList, enumValueAsString));
        }