/// <summary> /// Exports an element as building element proxy. /// </summary> /// <remarks> /// This function is called from the Export function, but can also be called directly if you do not /// want CreateInternalPropertySets to be called. /// </remarks> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <returns>The handle if created, null otherwise.</returns> public static IFCAnyHandle ExportSimpleGenericElement(ExporterIFC exporterIFC, Element element, GeometryElement geometryElement, ProductWrapper productWrapper, IFCExportInfoPair exportType) { if (element == null || geometryElement == null) { return(null); } // Check the intended IFC entity or type name is in the exclude list specified in the UI if (exportType.ExportInstance == IFCEntityType.UnKnown) { exportType.SetValueWithPair(IFCEntityType.IfcBuildingElementProxy, exportType.ValidatedPredefinedType); } if (ExporterCacheManager.ExportOptionsCache.IsElementInExcludeList(exportType.ExportInstance)) { return(null); } // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); IFCFile file = exporterIFC.GetFile(); IFCAnyHandle instanceHandle = null; using (IFCTransaction tr = new IFCTransaction(file)) { using (PlacementSetter placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { using (IFCExtrusionCreationData ecData = new IFCExtrusionCreationData()) { ecData.SetLocalPlacement(placementSetter.LocalPlacement); ElementId categoryId = CategoryUtil.GetSafeCategoryId(element); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true, ExportOptionsCache.ExportTessellationLevel.ExtraLow); IFCAnyHandle representation = RepresentationUtil.CreateAppropriateProductDefinitionShape(exporterIFC, element, categoryId, geometryElement, bodyExporterOptions, null, ecData, true); if (IFCAnyHandleUtil.IsNullOrHasNoValue(representation)) { ecData.ClearOpenings(); return(null); } string guid = GUIDUtil.CreateGUID(element); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle localPlacement = ecData.GetLocalPlacement(); IFCAnyHandle styleHandle = null; instanceHandle = FamilyExporterUtil.ExportGenericInstance(exportType, exporterIFC, element, productWrapper, placementSetter, ecData, guid, ownerHistory, representation, null); if (exportType.ExportType != IFCEntityType.UnKnown) { FamilySymbol familySymbol = (element as FamilyInstance)?.Symbol; if (familySymbol != null) { HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>(); IList <IFCAnyHandle> repMapListOpt = new List <IFCAnyHandle>(); string typeGuid = FamilyExporterUtil.GetGUIDForFamilySymbol(element as FamilyInstance, familySymbol); styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, exportType.ValidatedPredefinedType, propertySetsOpt, repMapListOpt, element, familySymbol, typeGuid); productWrapper.RegisterHandleWithElementType(familySymbol, exportType, styleHandle, propertySetsOpt); } if (IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { styleHandle = ExporterUtil.CreateGenericTypeFromElement(element, exportType, file, ownerHistory, exportType.ValidatedPredefinedType, productWrapper); } } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { if (exportType.ExportInstance == IFCEntityType.IfcSpace) { productWrapper.AddSpace(element, instanceHandle, placementSetter.LevelInfo, ecData, true, exportType); } else { productWrapper.AddElement(element, instanceHandle, placementSetter.LevelInfo, ecData, true, exportType); } if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle); } } } tr.Commit(); } } return(instanceHandle); }
private static void ExportAsMappedItem(ExporterIFC exporterIFC, Element element, IFCExportInfoPair 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; ElementId matId = ElementId.InvalidElementId; Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); bool hasMaterialAssociatedToType = false; if (type != null) { FamilyTypeInfo currentTypeInfo = ExporterCacheManager.FamilySymbolToTypeInfoCache.Find(typeId, false, exportType); if (!currentTypeInfo.IsValid()) { string typeObjectType = NamingUtil.CreateIFCObjectName(exporterIFC, type); HashSet <IFCAnyHandle> propertySetsOpt = new HashSet <IFCAnyHandle>(); IList <IFCAnyHandle> repMapListOpt = new List <IFCAnyHandle>(); string typeGuid = FamilyExporterUtil.GetGUIDForFamilySymbol(element as FamilyInstance, type); styleHandle = FamilyExporterUtil.ExportGenericType(exporterIFC, exportType, ifcEnumType, propertySetsOpt, repMapListOpt, element, type, typeGuid); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { productWrapper.RegisterHandleWithElementType(type, exportType, styleHandle, null); currentTypeInfo.Style = styleHandle; ExporterCacheManager.FamilySymbolToTypeInfoCache.Register(typeId, false, exportType, currentTypeInfo); Element elementType = element.Document.GetElement(element.GetTypeId()); matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(element.get_Geometry(geomOptions), elementType, element); if (matId != ElementId.InvalidElementId) { currentTypeInfo.MaterialIdList = new List <ElementId>() { matId }; hasMaterialAssociatedToType = true; CategoryUtil.CreateMaterialAssociation(exporterIFC, styleHandle, matId); } } } else { styleHandle = currentTypeInfo.Style; if (currentTypeInfo.MaterialIdList != null && currentTypeInfo.MaterialIdList.Count > 0) { hasMaterialAssociatedToType = true; } } } 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(exportType, exporterIFC, element, instanceGUID, ownerHistory, localPlacementToUse, productRepresentation); //} if (IFCAnyHandleUtil.IsNullOrHasNoValue(instanceHandle)) { return; } if (matId == ElementId.InvalidElementId && !hasMaterialAssociatedToType) { matId = BodyExporter.GetBestMaterialIdFromGeometryOrParameter(element.get_Geometry(geomOptions), element); if (matId != ElementId.InvalidElementId) { CategoryUtil.CreateMaterialAssociation(exporterIFC, instanceHandle, matId); } } if (roomId != ElementId.InvalidElementId) { //exporterIFC.RelateSpatialElement(roomId, instanceHandle); ExporterCacheManager.SpaceInfoCache.RelateToSpace(roomId, instanceHandle); productWrapper.AddElement(element, instanceHandle, setter, extraParams, false, exportType); } else { productWrapper.AddElement(element, instanceHandle, setter, extraParams, true, exportType); } OpeningUtil.CreateOpeningsIfNecessary(instanceHandle, element, extraParams, null, exporterIFC, localPlacementToUse, setter, productWrapper); if (!IFCAnyHandleUtil.IsNullOrHasNoValue(styleHandle)) { ExporterCacheManager.TypeRelationsCache.Add(styleHandle, instanceHandle); } ExporterCacheManager.MEPCache.Register(element, instanceHandle); // add to system export cache // SystemExporter.ExportSystem(exporterIFC, element, instanceHandle); }