private static ElementId GetStairOrRampHostId(ExporterIFC exporterIFC, Railing railingElem) { ElementId returnHostId = ElementId.InvalidElementId; if (railingElem == null) { return(returnHostId); } ElementId hostId = railingElem.HostId; if (hostId == ElementId.InvalidElementId) { return(returnHostId); } if (!ExporterCacheManager.StairRampContainerInfoCache.ContainsStairRampContainerInfo(hostId)) { return(returnHostId); } Element host = railingElem.Document.GetElement(hostId); if (host == null) { return(returnHostId); } if (!(host is Stairs) && !StairsExporter.IsLegacyStairs(host) && !RampExporter.IsRamp(host)) { return(returnHostId); } returnHostId = hostId; return(returnHostId); }
/// <summary> /// Exports an element as an IFC assembly. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <returns>True if exported successfully, false otherwise.</returns> public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element, ProductWrapper productWrapper) { if (element == null) { return(false); } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { IFCAnyHandle assemblyInstanceHnd = null; string guid = GUIDUtil.CreateGUID(element); IFCAnyHandle ownerHistory = ExporterCacheManager.OwnerHistoryHandle; IFCAnyHandle localPlacement = null; PlacementSetter placementSetter = null; IFCLevelInfo levelInfo = null; bool relateToLevel = true; string ifcEnumType; IFCExportInfoPair exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType); if (exportAs.ExportInstance == IFCEntityType.IfcSystem) { string name = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element)); string description = NamingUtil.GetDescriptionOverride(element, null); string objectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element)); assemblyInstanceHnd = IFCInstanceExporter.CreateSystem(file, guid, ownerHistory, name, description, objectType); // Create classification reference when System has classification filed name assigned to it ClassificationUtil.CreateClassification(exporterIFC, file, element, assemblyInstanceHnd); HashSet <IFCAnyHandle> relatedBuildings = new HashSet <IFCAnyHandle>(); relatedBuildings.Add(ExporterCacheManager.BuildingHandle); IFCAnyHandle relServicesBuildings = IFCInstanceExporter.CreateRelServicesBuildings(file, GUIDUtil.CreateGUID(), ExporterCacheManager.OwnerHistoryHandle, null, null, assemblyInstanceHnd, relatedBuildings); relateToLevel = false; // Already related to the building via IfcRelServicesBuildings. } else { // Check for containment override IFCAnyHandle overrideContainerHnd = null; ElementId overrideContainerId = ParameterUtil.OverrideContainmentParameter(exporterIFC, element, out overrideContainerHnd); using (placementSetter = PlacementSetter.Create(exporterIFC, element, null, null, overrideContainerId, overrideContainerHnd)) { IFCAnyHandle representation = null; // We have limited support for exporting assemblies as other container types. localPlacement = placementSetter.LocalPlacement; levelInfo = placementSetter.LevelInfo; switch (exportAs.ExportInstance) { case IFCEntityType.IfcCurtainWall: //case IFCExportType.IfcCurtainWallType: //string cwPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType, "IfcCurtainWallType"); assemblyInstanceHnd = IFCInstanceExporter.CreateCurtainWall(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcEnumType); break; case IFCEntityType.IfcRamp: string rampPredefinedType = RampExporter.GetIFCRampType(ifcEnumType); //rampPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, rampPredefinedType, "IfcRampType"); assemblyInstanceHnd = IFCInstanceExporter.CreateRamp(exporterIFC, element, guid, ownerHistory, localPlacement, representation, rampPredefinedType); break; case IFCEntityType.IfcRoof: //string roofPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType, "IfcRoofType"); assemblyInstanceHnd = IFCInstanceExporter.CreateRoof(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcEnumType); break; case IFCEntityType.IfcStair: string stairPredefinedType = StairsExporter.GetIFCStairType(ifcEnumType); //stairPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, stairPredefinedType, "IfcStairType"); assemblyInstanceHnd = IFCInstanceExporter.CreateStair(exporterIFC, element, guid, ownerHistory, localPlacement, representation, stairPredefinedType); break; case IFCEntityType.IfcWall: //string wallPredefinedType = IFCValidateEntry.GetValidIFCPredefinedType(element, ifcEnumType, "IfcWallType"); assemblyInstanceHnd = IFCInstanceExporter.CreateWall(exporterIFC, element, guid, ownerHistory, localPlacement, representation, ifcEnumType); break; default: string objectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.GetFamilyAndTypeName(element)); IFCElementAssemblyType assemblyPredefinedType = GetPredefinedTypeFromObjectType(objectType); assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(exporterIFC, element, guid, ownerHistory, localPlacement, representation, IFCAssemblyPlace.NotDefined, assemblyPredefinedType); break; } } } if (assemblyInstanceHnd == null) { return(false); } // relateToLevel depends on how the AssemblyInstance is being mapped to IFC, above. productWrapper.AddElement(element, assemblyInstanceHnd, levelInfo, null, relateToLevel, exportAs); ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd); tr.Commit(); return(true); } }
/// <summary> /// Exports an element as an IFC assembly. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <returns>True if exported successfully, false otherwise.</returns> public static bool ExportAssemblyInstanceElement(ExporterIFC exporterIFC, AssemblyInstance element, ProductWrapper productWrapper) { if (element == null) { return(false); } IFCFile file = exporterIFC.GetFile(); using (IFCTransaction tr = new IFCTransaction(file)) { IFCAnyHandle assemblyInstanceHnd = null; string guid = GUIDUtil.CreateGUID(element); IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle(); string name = NamingUtil.GetNameOverride(element, NamingUtil.GetIFCName(element)); string description = NamingUtil.GetDescriptionOverride(element, null); string objectType = NamingUtil.GetObjectTypeOverride(element, exporterIFC.GetFamilyName()); IFCAnyHandle localPlacement = null; PlacementSetter placementSetter = null; IFCLevelInfo levelInfo = null; string ifcEnumType; IFCExportType exportAs = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType); if (exportAs == IFCExportType.IfcSystem) { assemblyInstanceHnd = IFCInstanceExporter.CreateSystem(file, guid, ownerHistory, name, description, objectType); // Create classification reference when System has classification filed name assigned to it ClassificationUtil.CreateClassification(exporterIFC, file, element, assemblyInstanceHnd); HashSet <IFCAnyHandle> relatedBuildings = new HashSet <IFCAnyHandle>(); relatedBuildings.Add(ExporterCacheManager.BuildingHandle); IFCAnyHandle relServicesBuildings = IFCInstanceExporter.CreateRelServicesBuildings(file, GUIDUtil.CreateGUID(), exporterIFC.GetOwnerHistoryHandle(), null, null, assemblyInstanceHnd, relatedBuildings); } else { using (placementSetter = PlacementSetter.Create(exporterIFC, element)) { string elementTag = NamingUtil.GetTagOverride(element, NamingUtil.CreateIFCElementId(element)); IFCAnyHandle representation = null; // We have limited support for exporting assemblies as other container types. localPlacement = placementSetter.LocalPlacement; levelInfo = placementSetter.LevelInfo; ifcEnumType = IFCValidateEntry.GetValidIFCType(element, ifcEnumType); switch (exportAs) { case IFCExportType.IfcCurtainWall: assemblyInstanceHnd = IFCInstanceExporter.CreateCurtainWall(file, guid, ownerHistory, name, description, objectType, localPlacement, representation, elementTag); break; case IFCExportType.IfcRamp: string rampPredefinedType = RampExporter.GetIFCRampType(ifcEnumType); assemblyInstanceHnd = IFCInstanceExporter.CreateRamp(file, guid, ownerHistory, name, description, objectType, localPlacement, representation, elementTag, rampPredefinedType); break; case IFCExportType.IfcRoof: assemblyInstanceHnd = IFCInstanceExporter.CreateRoof(file, guid, ownerHistory, name, description, objectType, localPlacement, representation, elementTag, ifcEnumType); break; case IFCExportType.IfcStair: string stairPredefinedType = StairsExporter.GetIFCStairType(ifcEnumType); assemblyInstanceHnd = IFCInstanceExporter.CreateStair(file, guid, ownerHistory, name, description, objectType, localPlacement, representation, elementTag, stairPredefinedType); break; case IFCExportType.IfcWall: assemblyInstanceHnd = IFCInstanceExporter.CreateWall(file, guid, ownerHistory, name, description, objectType, localPlacement, representation, elementTag, ifcEnumType); break; default: IFCElementAssemblyType assemblyPredefinedType = GetPredefinedTypeFromObjectType(objectType); assemblyInstanceHnd = IFCInstanceExporter.CreateElementAssembly(file, guid, ownerHistory, name, description, objectType, localPlacement, representation, elementTag, IFCAssemblyPlace.NotDefined, assemblyPredefinedType); break; } } } if (assemblyInstanceHnd == null) { return(false); } bool relateToLevel = (levelInfo != null); productWrapper.AddElement(element, assemblyInstanceHnd, levelInfo, null, relateToLevel); ExporterCacheManager.AssemblyInstanceCache.RegisterAssemblyInstance(element.Id, assemblyInstanceHnd); tr.Commit(); return(true); } }