static void Main(string[] args) { DatabaseIfc db = new DatabaseIfc(ModelView.Ifc4X3NotAssigned); db.Factory.Options.GenerateOwnerHistory = false; IfcProject project = new IfcProject(db, "DemoProject"); IfcProjectLibrary projectLibrary = new IfcProjectLibrary(db, "ClassificationLibrary"); project.AddDeclared(projectLibrary); IfcClassification classification = new IfcClassification(db, "MyClassification"); new IfcRelAssociatesClassification(classification, projectLibrary); IfcClassificationReference buildingElements = new IfcClassificationReference(classification) { Identification = "100", Name = "BuildingElements" }; IfcClassificationReference walls = new IfcClassificationReference(buildingElements) { Identification = "100.100", Name = "Walls" }; IfcClassificationReference partionWalls = new IfcClassificationReference(walls) { Identification = "100.100.002", Name = "PartiionWalls" }; IfcSimplePropertyTemplate simplePropertyTemplate = new IfcSimplePropertyTemplate(db, "IsExternal") { GlobalId = "3Yss80qXKHuO00025QrE$V", PrimaryMeasureType = "IfcBoolean" }; IfcPropertySetTemplate psetTemplate = new IfcPropertySetTemplate("Pset_WallCommon", simplePropertyTemplate) { GlobalId = "2VWFE0qXKHuO00025QrE$V" }; IfcPropertySingleValue psv = new IfcPropertySingleValue(db, "IsExternal", new IfcBoolean(false)); IfcPropertySet pset = new IfcPropertySet("Pset_WallCommon", psv); new IfcRelDefinesByTemplate(pset, psetTemplate); new IfcRelAssociatesClassification(partionWalls, pset); DirectoryInfo di = Directory.GetParent(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); di = Directory.GetParent(di.FullName); db.WriteFile(Path.Combine(di.FullName, "TestClassification.ifc")); }
public RequirementSetView(IfcPropertySetTemplate psetTemplate) { this.PsetTemplate = psetTemplate; Requirements = psetTemplate.HasPropertyTemplates .OfType <IfcSimplePropertyTemplate>() .Select(p => new RequirementView(p, this)) .ToList(); lang = Language.Lang; Language.PropertyChanged += (_, p) => { if (p.PropertyName != nameof(Language.Lang)) { return; } lang = Language.Lang; }; }
public override void Run() { using (var txn = model.BeginTransaction("Example creation")) { IfcProject project = model.Instances.New <IfcProject>(p => p.Name = "TriluxLightingProducts"); IfcUnitAssignment ifcUnitAssignment = model.Instances.New <IfcUnitAssignment>(ua => { ua.Units.Add(model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.LENGTHUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.METRE; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.MILLI; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.MASSUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.GRAM; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.KILO; })); }); //Insert Classification system var ifcClassificationSystemOmniClass = model.Instances.New <IfcClassification>(cs => { cs.Name = "Omniclass"; cs.Edition = "1.0"; cs.EditionDate = "2018-12-27T00:00:00.0000000"; cs.Description = "The OmniClass Construction Classification System (known as OmniClass™ or OCCS) is a classification system for the construction industry. OmniClass is useful for many applications, from organizing library materials, product literature, and project information, to providing a classification structure for electronic databases. It incorporates other extant systems currently in use as the basis of many of its Tables – MasterFormat™ for work results, UniFormat for elements, and EPIC (Electronic Product Information Cooperation) for structuring products."; cs.Location = "http://www.omniclass.org/"; }); //Insertion of some sample classification references //I would be better to insert the whole classification system and reference the appropriate code var ifcClassificationReferenceOmniClass = model.Instances.New <IfcClassificationReference>(cr => { cr.Identification = "23-35-47"; cr.Name = "Electrical Lighting"; cr.Description = ""; cr.ReferencedSource = ifcClassificationSystemOmniClass; }); var ifcRelAssociatesClassificationOmniClass = model.Instances.New <IfcRelAssociatesClassification>(relc => { relc.RelatingClassification = ifcClassificationReferenceOmniClass; }); //Insert Classification system var ifcClassificationSystemUniClass = model.Instances.New <IfcClassification>(cs => { cs.Name = "Uniclass"; cs.Edition = "2015"; cs.EditionDate = "01.01.2015"; cs.Description = "Uniclass is a voluntary classification system for the construction industry that can be used for structuring project information, such as building information models (BIM)."; cs.Location = "https://www.thenbs.com/our-tools/introducing-uniclass-2015"; }); //Insertion of some sample classification references //I would be better to insert the whole classification system and reference the appropriate code var ifcClassificationReferenceUniClass = model.Instances.New <IfcClassificationReference>(cr => { cr.Identification = "CA-70-10-30"; cr.Name = "Site lighting equipment"; cr.Description = ""; cr.ReferencedSource = ifcClassificationSystemUniClass; }); var ifcRelAssociatesClassificationUniClass = model.Instances.New <IfcRelAssociatesClassification>(relc => { relc.RelatingClassification = ifcClassificationReferenceUniClass; }); //Insert a project library to store the product data templates and type products var ifcProductDataLibrary = model.Instances.New <IfcProjectLibrary>(l => { l.Name = "TriluxLightingProductsLibrary"; l.GlobalId = "1DbshdzGD71ejurQqQcxbw"; l.Description = "Library for Trilux light fixtures product data templates based on the ZVEI European core properties"; l.Phase = "Design,Build,Operate"; l.OwnerHistory = model.Instances.New <IfcOwnerHistory>(oh => { oh.CreationDate = DateTime.Now; //oh.ChangeAction = Xbim.Ifc4.Interfaces.IfcChangeActionEnum.ADDED; oh.OwningUser = model.Instances.New <IfcPersonAndOrganization>(po => { po.TheOrganization = model.Instances.New <IfcOrganization>(o => { o.Name = "TRILUX GmbH & Co. KG"; }); po.ThePerson = model.Instances.New <IfcPerson>(p => { p.GivenName = "Robert"; p.FamilyName = "Heinze"; }); }); oh.OwningApplication = model.Instances.New <IfcApplication>(app => { app.ApplicationIdentifier = "ID_OF_PIM-SYSTEM"; app.ApplicationFullName = "My Product Information System (PIM)"; app.ApplicationDeveloper = model.Instances.New <IfcOrganization>(o => { o.Name = "The software company, that developed the PIM system"; }); app.Version = "1.0"; }); }); }); Comment(ifcProductDataLibrary, @"Root element of this file. Because this doesn't define a specific instance in the building it is a library. It can be used to declare elements, properties, property templates and other library objects which can be later used in the actual design."); Comment(ifcProductDataLibrary.OwnerHistory, @"Owner history is used to define ownership of the information."); var ifcProductDataLibraryDeclarations = New <IfcRelDeclares>(rel => { rel.RelatingContext = ifcProductDataLibrary; }).RelatedDefinitions; Comment(ifcProductDataLibraryDeclarations.OwningEntity, @"This relation points to all definitions declared within the scope of the library. These can be elements, element types, properties or property templates"); //Creating an IfcPropertySetTemplate manually //This is not optimal //Instead of creating the IfcPropertySetTemplates manually, //they should be loaded from the publishing dictionary //Read templates from excel sheet var workbookTemplates = new XLWorkbook(Path.Combine(sourceFolder, sourceFile)); IXLWorksheet worksheetTemplates = workbookTemplates.Worksheet("Templates"); //IXLRange rangeTemplates = worksheetTemplates.Range("A1:Z690"); //IXLTable rawDataTemplates = rangeTemplates.AsTable(); DataTable dtTemplates = ReadDataTable(worksheetTemplates); var productDataTemplates = from DataRow dr in dtTemplates.Rows orderby dr["DataTemplate"] group dr by dr["DataTemplate"]; foreach (var productDataTemplate in productDataTemplates) { IfcPropertySetTemplate ifcPropertySetTemplate = model.Instances.New <IfcPropertySetTemplate>(pset => { pset.GlobalId = Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId.ConvertToBase64(Guid.NewGuid()); pset.Name = productDataTemplate.Key.ToString(); pset.Description = "Data Template by " + productDataTemplate.ElementAt(0)["Publisher"].ToString(); pset.ApplicableEntity = "IfcBuildingElementProxy/USERDEFINED"; pset.TemplateType = Xbim.Ifc4.Interfaces.IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENONLY; }); Comment(ifcPropertySetTemplate, @"Declaration of 'IfcPropertySetTemplate' within the library for lighting product data templates."); Comment(ifcPropertySetTemplate, @"Insert property templates; they should be loaded from the publishing dictionary"); foreach (DataRow propertyTemplate in productDataTemplate) { IfcSimplePropertyTemplate ifcSimplePropertyTemplate = model.Instances.New <IfcSimplePropertyTemplate>(spt => { spt.Name = propertyTemplate["SystemName"].ToString(); spt.Description = propertyTemplate["Definition"].ToString(); spt.Expression = ""; spt.GlobalId = GetGuid(propertyTemplate["GlobalId"].ToString()); spt.TemplateType = Xbim.Ifc4.Interfaces.IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; spt.AccessState = Xbim.Ifc4.Interfaces.IfcStateEnum.LOCKED; spt.PrimaryMeasureType = propertyTemplate["PrimaryMeasureType"].ToString(); //check if enum values exists in this template, and if, create themn in IFC string allowedValues = propertyTemplate["AllowedValues"].ToString(); if (allowedValues.Length > 0) { spt.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_ENUMERATEDVALUE; IfcPropertyEnumeration ifcPropertyEnumeration = model.Instances.New <IfcPropertyEnumeration>(pe => { pe.Name = $"Allowed values of {spt.Name}"; }); char delimiter = '|'; foreach (string allowedValue in allowedValues.Split(delimiter)) { ifcPropertyEnumeration.EnumerationValues.Add(new IfcLabel(allowedValue)); } spt.Enumerators = ifcPropertyEnumeration; } //Check the measures and units string primaryMeasureType = propertyTemplate["PrimaryMeasureType"].ToString(); if ((primaryMeasureType == "IfcDocumentInformation") || (primaryMeasureType == "IfcClassificationReference") || (primaryMeasureType == "IfcGloballyUniqueId")) { spt.PrimaryMeasureType = "IfcLabel"; } else if (primaryMeasureType == typeof(IfcLengthMeasure).Name) { spt.PrimaryUnit = model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.LENGTHUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.METRE; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.MILLI; }); } else if (primaryMeasureType == typeof(IfcMassMeasure).Name) { spt.PrimaryUnit = model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.MASSUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.GRAM; }); } else if (primaryMeasureType == typeof(IfcPlaneAngleMeasure).Name) { spt.PrimaryUnit = model.Instances.New <IfcConversionBasedUnit>(punit => { //Convert the angel measure from the unit grad to the SI Unit radian //rad=grad*(PI/180) punit.Name = "Grad"; punit.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.PLANEANGLEUNIT; punit.ConversionFactor = model.Instances.New <IfcMeasureWithUnit>(mwu => { mwu.UnitComponent = model.Instances.New <IfcSIUnit>(siUnit => { siUnit.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.PLANEANGLEUNIT; siUnit.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.RADIAN; }); mwu.ValueComponent = new IfcReal(Math.PI / 180); }); punit.Dimensions = model.Instances.New <IfcDimensionalExponents>(dim => { dim.LengthExponent = 0; dim.MassExponent = 0; dim.TimeExponent = 0; dim.ElectricCurrentExponent = 0; dim.ThermodynamicTemperatureExponent = 0; dim.AmountOfSubstanceExponent = 0; dim.LuminousIntensityExponent = 0; }); }); } }); string complexGroupName = propertyTemplate["ComplexGroupName"].ToString(); if (complexGroupName.Length == 0) { ifcPropertySetTemplate.HasPropertyTemplates.Add(ifcSimplePropertyTemplate); } else { //Find the appropriate IfcComplexPropertyTemplate, and if it does not yet exist, create it IfcComplexPropertyTemplate ifcComplexPropertyTemplate = model.Instances.OfType <IfcComplexPropertyTemplate>() .Where(cpt => cpt.Name == complexGroupName) .FirstOrDefault(); if (ifcComplexPropertyTemplate == null) { ifcComplexPropertyTemplate = model.Instances.New <IfcComplexPropertyTemplate>(cpt => { cpt.Name = complexGroupName; cpt.Description = propertyTemplate["ComplexGroupDescription"].ToString(); cpt.GlobalId = GetGuid(propertyTemplate["ComplexGroupGuid"].ToString()); }); ifcPropertySetTemplate.HasPropertyTemplates.Add(ifcComplexPropertyTemplate); } ifcComplexPropertyTemplate.HasPropertyTemplates.Add(ifcSimplePropertyTemplate); } } ifcProductDataLibraryDeclarations.Add(ifcPropertySetTemplate); } //Read source data from excel sheet var workbookData = new XLWorkbook(Path.Combine(sourceFolder, sourceFile)); IXLWorksheet worksheetData = workbookData.Worksheet("Sheets"); //IXLRange rangeData = worksheetData.Range("A1:Z690"); //IXLTable rawData = rangeData.AsTable(); DataTable dtData = ReadDataTable(worksheetData); //Loop through the products in the data sheet foreach (DataRow product in dtData.Rows) { var ifcTypeProduct = model.Instances.New <IfcTypeProduct>(); ifcTypeProduct.Name = product["Name"].ToString(); ifcTypeProduct.Description = "Description of " + ifcTypeProduct.Name; ifcTypeProduct.ApplicableOccurrence = "IfcLightFixture"; //Create the property sets, and relate them to their templates foreach (IfcPropertySetTemplate ifcPropertySetTemplate in model.Instances.OfType <IfcPropertySetTemplate>().ToList()) { IfcPropertySet ifcPropertySet = model.Instances.New <IfcPropertySet>(pset => { pset.Name = ifcPropertySetTemplate.Name; pset.Description = ifcPropertySetTemplate.Description; }); ifcTypeProduct.HasPropertySets.Add(ifcPropertySet); //Relate the property set to the definition of the property set template //Find the appropriate relation, and if it does not yet exist, create it IfcRelDefinesByTemplate ifcRelDefinesByTemplate = model.Instances.OfType <IfcRelDefinesByTemplate>() .Where(rdbt => rdbt.RelatingTemplate == ifcPropertySetTemplate) .FirstOrDefault(); if (ifcRelDefinesByTemplate == null) { ifcRelDefinesByTemplate = New <IfcRelDefinesByTemplate>(dbt => { dbt.RelatingTemplate = ifcPropertySetTemplate; }); } ifcRelDefinesByTemplate.RelatedPropertySets.Add(ifcPropertySet); } //loop through the properties of the product, based on the data template foreach (DataRow propertyTemplate in dtTemplates.Rows) { //Load the correct IfcPropertySet for this property, that was created above IfcPropertySet ifcPropertySet = (IfcPropertySet)ifcTypeProduct.HasPropertySets .Where(x => x.Name == propertyTemplate["DataTemplate"].ToString()) .FirstOrDefault(); //Check, which measure type the property is based on switch (propertyTemplate["PrimaryMeasureType"].ToString()) { case "IfcGloballyUniqueId": //Insert the unique number for the product type ifcTypeProduct.GlobalId = GetGuid(product[propertyTemplate["SystemName"].ToString()].ToString()); break; case "IfcDocumentInformation": //Insert the product information that are in documents string folderName = propertyTemplate["SystemName"].ToString(); string docName = product[propertyTemplate["SystemName"].ToString()].ToString(); if (docName.Length > 0) { string fileLocation = $"{folderName}/{docName}"; IfcDocumentInformation ifcDocumentInformation; var existingInsertedDocumentInformation = model.Instances.OfType <IfcDocumentInformation>().Where(x => x.Location == fileLocation); if (existingInsertedDocumentInformation.Count() == 0) { ifcDocumentInformation = model.Instances.New <IfcDocumentInformation>(doc => { doc.Identification = docName; doc.Name = docName; doc.Location = $@"{folderName}/{docName}"; doc.CreationTime = DateTime.Now.ToString("dd.MM.yyyy"); doc.Confidentiality = Xbim.Ifc4.Interfaces.IfcDocumentConfidentialityEnum.PUBLIC; doc.ElectronicFormat = MimeTypes.GetMimeType(docName); doc.IntendedUse = "Product information"; doc.Purpose = "Product information"; doc.ValidFrom = "01.01.2018"; doc.ValidUntil = "31.12.2021"; doc.Scope = "Europa"; doc.Revision = "1.0"; }); string test = Path.GetExtension(docName); switch (Path.GetExtension(docName)) { case ".pdf": ifcDocumentInformation.Description = "Produktdatenblatt"; break; case ".3ds": ifcDocumentInformation.Description = "3D-Visualisierung"; break; case ".jpg": ifcDocumentInformation.Description = "Produktphoto"; break; case ".ies": ifcDocumentInformation.Description = "Lichtverteilung von IES Standard"; break; } IfcRelAssociatesDocument ifcRelAssociatesDocument = model.Instances.New <IfcRelAssociatesDocument>(docref => { docref.RelatedObjects.Add(ifcTypeProduct); docref.RelatingDocument = ifcDocumentInformation; }); } else { ifcDocumentInformation = existingInsertedDocumentInformation.FirstOrDefault(); var existingDocumentInformationRelation = model.Instances.OfType <IfcRelAssociatesDocument>() .Where(x => x.RelatingDocument == ifcDocumentInformation).FirstOrDefault(); existingDocumentInformationRelation.RelatedObjects.Add(ifcTypeProduct); } } break; case "IfcClassificationReference": switch (propertyTemplate["SystemName"].ToString()) { case "Omniclass": var classificationReference = model.Instances.OfType <IfcClassificationReference>() .Where(x => x.Identification == product[propertyTemplate["SystemName"].ToString()].ToString()).FirstOrDefault(); ifcRelAssociatesClassificationOmniClass.RelatedObjects.Add(ifcTypeProduct); break; case "Uniclass": ifcRelAssociatesClassificationUniClass.RelatedObjects.Add(ifcTypeProduct); break; } break; default: IfcPropertySingleValue ifcPropertySingleValue = model.Instances.New <IfcPropertySingleValue>(p => { string propertyName = propertyTemplate["SystemName"].ToString(); var dataValue = product[propertyName]; p.Name = propertyName; p.Description = ""; string primaryMeasureType = propertyTemplate["PrimaryMeasureType"].ToString(); if (primaryMeasureType == typeof(IfcLengthMeasure).Name) { p.NominalValue = new IfcMassMeasure(Double.Parse(dataValue.ToString())); } else if (primaryMeasureType == typeof(IfcMassMeasure).Name) { p.NominalValue = new IfcMassMeasure(Double.Parse(dataValue.ToString())); } else if (primaryMeasureType == typeof(IfcPlaneAngleMeasure).Name) { p.NominalValue = new IfcPlaneAngleMeasure(Double.Parse(dataValue.ToString())); } else { p.NominalValue = new IfcLabel(dataValue.ToString()); } }); // Check, if the template of this property is part of a complex property if (propertyTemplate["ComplexGroupName"].ToString().Length > 0) { string complexPropertyName = propertyTemplate["ComplexGroupName"].ToString(); string complexPropertyDescription = propertyTemplate["ComplexGroupDescription"].ToString(); string complexPropertyGlobalId = GetGuid(propertyTemplate["ComplexGroupGuid"].ToString()); IfcComplexProperty ifcComplexProperty = model.Instances .OfType <IfcComplexProperty>() .Where(n => n.Name == complexPropertyName) .Where(u => u.UsageName == ifcTypeProduct.Name.ToString()) .FirstOrDefault(); if (ifcComplexProperty == null) { ifcComplexProperty = model.Instances.New <IfcComplexProperty>(p => { p.Name = complexPropertyName; p.Description = complexPropertyDescription; p.UsageName = ifcTypeProduct.Name.ToString(); }); ifcPropertySet.HasProperties.Add(ifcComplexProperty); } //Insert the product information into the complex property and then into the property set ifcComplexProperty.HasProperties.Add(ifcPropertySingleValue); } else { //Insert the product information directly into the property set ifcPropertySet.HasProperties.Add(ifcPropertySingleValue); } break; } } ; ifcProductDataLibraryDeclarations.Add(ifcTypeProduct); Comment(ifcTypeProduct, @"Declaration of 'IfcTypeProduct' within the library for a ligthing product."); } txn.Commit(); } string targetFileName = Path.Combine(targetFolder, targetFile); SaveAs(targetFileName, false, typeof(IfcProjectLibrary)); //DirtyFix with Schema location //https://github.com/xBimTeam/XbimEssentials/issues/288 string contentOfFile = File.ReadAllText($"{targetFileName}.ifcXML"); string oldNameSpaceLocation = @"xsi:schemaLocation=""http://www.buildingsmart-tech.org/ifcXML/IFC4/Add2 http://www.buildingsmart-tech.org/ifc/IFC4/Add2/IFC4_ADD2.xsd"""; string newNameSpaceLocation = @"xsi:schemaLocation=""http://www.buildingsmart-tech.org/ifcXML/IFC4/Add2 ../../IFC4_ADD2.xsd"""; contentOfFile = contentOfFile.Replace(oldNameSpaceLocation, newNameSpaceLocation); File.WriteAllText($"{targetFileName}.ifcXML", contentOfFile); //Create ifcZip file File.Delete(targetzipFile); ZipFile.CreateFromDirectory(sourceFolder, targetzipFile); using (ZipArchive zipArchive = ZipFile.Open(targetzipFile, ZipArchiveMode.Update)) { zipArchive.GetEntry(sourceFile).Delete(); zipArchive.CreateEntryFromFile($"{targetFolder}/{targetFile}.ifcXML", $"{targetFile}.ifcXML"); zipArchive.CreateEntryFromFile($"{targetFolder}/{targetFile}.ifc", $"{targetFile}.ifc"); } }
public override void Run() { using (var txn = model.BeginTransaction("Example creation")) { //How to fill the header with xBIM Eseentials? //model.Header.Name = "Product data file"; //model.Header.Organization = "HC Italy"; //model.Header.Author = "Ugo"; //model.Header.Authorization = "CEN-TC442-WG2-TG3"; //model.Header.TimeStamp = DateTime.Now; //model.Header.OriginatingSystem = "CEN-TC442-WG2-TG3-Writer"; //there should always be one project in the model var project = model.Instances.New <IfcProject>(p => p.Name = "Basic Creation"); //our shortcut to define basic default units project.Initialize(Xbim.Common.ProjectUnits.SIUnitsUK); //Insert a project library to store the product data templates var ifcProductDataLibrary = New <IfcProjectLibrary>(l => { l.Name = "Library for brick product data templates"; l.GlobalId = "1DbshdzGD71ejurQqQcxbw"; l.Description = ""; l.Phase = ""; }); Comment(ifcProductDataLibrary, @"Root element of this file. Because this doesn't define a specific instance in the building it is a library. It can be used to declare elements, properties, property templates and other library objects which can be later used in the actual design."); Comment(ifcProductDataLibrary.OwnerHistory, @"Owner history is used to define ownership of the information."); var ifcProductDataLibraryDeclarations = New <IfcRelDeclares>(rel => { rel.RelatingContext = ifcProductDataLibrary; }).RelatedDefinitions; Comment(ifcProductDataLibraryDeclarations.OwningEntity, @"This relation points to all definitions declared within the scope of the library. These can be elements, element types, properties or property templates"); IfcPropertySetTemplate ifcPropertySetTemplate = model.Instances.New <IfcPropertySetTemplate>(pset => { pset.GlobalId = "1DbshTzGD71ejurQqQcxbw"; pset.Name = "My IfcPropertySetTemplate"; pset.Description = "Group of properties for " + ifcProductDataLibrary.Name; pset.ApplicableEntity = "IfcWall/USERDEFINED"; pset.TemplateType = Xbim.Ifc4.Interfaces.IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENONLY; pset.HasPropertyTemplates.AddRange(new[] { model.Instances.New <IfcSimplePropertyTemplate>(pt => { pt.Name = "zone"; pt.Description = ""; pt.GlobalId = "1DbshTzGD71ejuZQqQcxba"; pt.TemplateType = Xbim.Ifc4.Interfaces.IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; pt.AccessState = Xbim.Ifc4.Interfaces.IfcStateEnum.LOCKED; pt.PrimaryMeasureType = "IfcLabel"; }), model.Instances.New <IfcSimplePropertyTemplate>(pt => { pt.Name = "height"; pt.Description = ""; pt.GlobalId = "1DbshTzGD71ejuZQqQkxad"; pt.TemplateType = Xbim.Ifc4.Interfaces.IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; pt.AccessState = Xbim.Ifc4.Interfaces.IfcStateEnum.LOCKED; pt.PrimaryMeasureType = "IfcReal"; pt.PrimaryUnit = model.Instances.New <IfcSIUnit>(u => { u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.METRE; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.MILLI; u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.LENGTHUNIT; }); }), model.Instances.New <IfcSimplePropertyTemplate>(pt => { pt.Name = "width"; pt.Description = ""; pt.GlobalId = "1DbshTzGD71ejuZQqQcxac"; pt.TemplateType = Xbim.Ifc4.Interfaces.IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; pt.AccessState = Xbim.Ifc4.Interfaces.IfcStateEnum.LOCKED; pt.PrimaryMeasureType = "IfcReal"; pt.PrimaryUnit = model.Instances.New <IfcSIUnit>(u => { u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.METRE; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.MILLI; u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.LENGTHUNIT; }); }), model.Instances.New <IfcSimplePropertyTemplate>(pt => { pt.Name = "length"; pt.Description = ""; pt.GlobalId = "1DbshTzGD71ejuZQqQcxab"; pt.TemplateType = Xbim.Ifc4.Interfaces.IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; pt.AccessState = Xbim.Ifc4.Interfaces.IfcStateEnum.LOCKED; pt.PrimaryMeasureType = "IfcReal"; pt.PrimaryUnit = project.UnitsInContext.LengthUnit; }) }); }); ifcProductDataLibraryDeclarations.Add(ifcPropertySetTemplate); Comment(ifcPropertySetTemplate, @"Declaration of 'IfcPropertySetTemplate' within the library for brick product data templates."); //Read source data from excel sheet var workbook = new XLWorkbook(Path.Combine(baseFolder, sourceFile)); IXLWorksheet worksheet; IXLRange dataRange; worksheet = workbook.Worksheet(sheetName); dataRange = worksheet.Range("A1:E4231"); IXLTable rawData = dataRange.AsTable(); DataTable dt = ReadDataTable(worksheet); var ifcRelDefinesByTemplate = New <IfcRelDefinesByTemplate>(dbt => { dbt.RelatingTemplate = ifcPropertySetTemplate; }); int n = 0; do { foreach (DataRow row in dt.Rows) { var ifcTypeProduct = model.Instances.New <IfcTypeProduct>(); ifcTypeProduct.GlobalId = "1DbshTzGD71ejurQqQcxbw"; //How to generate a fresh IFC GlobalId with XBim? ifcTypeProduct.Tag = string.Format("{0}", row["Id"].ToString()); ifcTypeProduct.Name = string.Format("Brick Product variant #{0}", row["Id"].ToString()); ifcTypeProduct.Description = "Description of " + ifcTypeProduct.Name; ifcTypeProduct.ApplicableOccurrence = "IfcWall"; IfcPropertySet ifcPropertySet = model.Instances.New <IfcPropertySet>(pset => { pset.Name = "Properties of " + ifcTypeProduct.Name; pset.HasProperties.AddRange(new[] { model.Instances.New <IfcPropertySingleValue>(p => { p.Name = "zone"; p.Description = ""; p.NominalValue = new IfcText(row["Zone"].ToString().TrimEnd()); }), model.Instances.New <IfcPropertySingleValue>(p => { p.Name = "height"; p.NominalValue = new IfcLengthMeasure(Double.Parse(row["Height"].ToString())); p.Unit = project.UnitsInContext.LengthUnit; }), model.Instances.New <IfcPropertySingleValue>(p => { p.Name = "width"; p.NominalValue = new IfcLengthMeasure(Double.Parse(row["Width"].ToString())); p.Unit = project.UnitsInContext.LengthUnit; }), model.Instances.New <IfcPropertySingleValue>(p => { p.Name = "lenght"; p.NominalValue = new IfcLengthMeasure(Double.Parse(row["Length"].ToString())); p.Unit = project.UnitsInContext.LengthUnit; }) }); }); ifcTypeProduct.HasPropertySets.Add(ifcPropertySet); ifcProductDataLibraryDeclarations.Add(ifcTypeProduct); Comment(ifcTypeProduct, @"Declaration of 'IfcTypeProduct' within the library for brick product data templates."); ifcRelDefinesByTemplate.RelatedPropertySets.Add(ifcPropertySet); } n++; }while (n < 1); // commit to confirm changes in the model txn.Commit(); } string targetFileName = Path.Combine(baseFolder, targetFile + sheetName); SaveAs(targetFileName, true, typeof(IfcProjectLibrary)); }
static void Main(string[] args) { // ifcSIUnitMap = new Dictionary <string, IfcSIUnitName> { { "AMPERE", IfcSIUnitName.AMPERE }, { "BECQUEREL", IfcSIUnitName.BECQUEREL }, { "CANDELA", IfcSIUnitName.CANDELA }, { "COULOMB", IfcSIUnitName.COULOMB }, { "CUBIC_METRE", IfcSIUnitName.CUBIC_METRE }, { "DEGREE_CELSIUS", IfcSIUnitName.DEGREE_CELSIUS }, { "FARAD", IfcSIUnitName.FARAD }, { "GRAM", IfcSIUnitName.GRAM }, { "GRAY", IfcSIUnitName.GRAY }, { "HENRY", IfcSIUnitName.HENRY }, { "HERTZ", IfcSIUnitName.HERTZ }, { "JOULE", IfcSIUnitName.JOULE }, { "KELVIN", IfcSIUnitName.KELVIN }, { "LUMEN", IfcSIUnitName.LUMEN }, { "LUX", IfcSIUnitName.LUX }, { "METRE", IfcSIUnitName.METRE }, { "MOLE", IfcSIUnitName.MOLE }, { "NEWTON", IfcSIUnitName.NEWTON }, { "OHM", IfcSIUnitName.OHM }, { "PASCAL", IfcSIUnitName.PASCAL }, { "RADIAN", IfcSIUnitName.RADIAN }, { "SECOND", IfcSIUnitName.SECOND }, { "SIEMENS", IfcSIUnitName.SIEMENS }, { "SIEVERT", IfcSIUnitName.SIEVERT }, { "SQUARE_METRE", IfcSIUnitName.SQUARE_METRE }, { "STERADIAN", IfcSIUnitName.STERADIAN }, { "TESLA", IfcSIUnitName.TESLA }, { "VOLT", IfcSIUnitName.VOLT }, { "WATT", IfcSIUnitName.WATT }, { "WEBER", IfcSIUnitName.WEBER } }; // breakedownRootMap = new Dictionary <string, BreakdownItem>(); // prazdna mapa klasifikaci, bude plnena postupne // breakedownMap = new Dictionary <int, BreakdownItem>(); // prazdna mapa trid, bude plnena postupne ifcPropertyMap = new Dictionary <int, IfcSimplePropertyTemplate>(); // prazdna mapa vlastnosti, bude plnena postupne ifcPropertySetMap = new Dictionary <int, IfcPropertySetTemplate>(); // prazdna mapa skupin vlastnosti, bude plnena postupne reasonsMap = new Dictionary <int, Reason>(); // prazdna mapa IfcRelAssignsToControl, bude plnena postupne actorMap = new Dictionary <string, Actor>(); // prazdna mapa IfcRelAssignsToActor, bude plnena postupne milestonesCache = new Dictionary <int, Milestone>(); // prazdna mapa IfcRelAssignsToProcess, bude plnena postupne //using (var reader = new StreamReader("sfdi_export.csv")) using (var reader = new StreamReader(Console.OpenStandardInput())) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { var records = new List <RecordLine>(); csv.Read(); // CSV header Line 0 - XbimEditorCredentials csv.ReadHeader(); csv.Read(); // CSV line 0 - XbimEditorCredentials var record = new RecordLine { Id = csv.GetField <int>("Id"), Pid = csv.GetField <int>("Pid"), Lvl = csv.GetField <int>("Lvl") + 2, // -2..+inf -> 0..+inf Method = csv.GetField("Method"), GlobalId = csv.GetField("GlobalId"), Par01 = csv.GetField("Par01"), Par02 = csv.GetField("Par02"), Par03 = csv.GetField("Par03"), Par04 = csv.GetField("Par04"), Par05 = csv.GetField("Par05"), Par06 = csv.GetField("Par06"), Par07 = csv.GetField("Par07"), Par08 = csv.GetField("Par08"), Par09 = csv.GetField("Par09") }; records.Add(record); //START var ifcFile = args[0]; // tempfile // "/var/www/html/tmp/DDSS.ifc"; var doValidate = "validate"; if (args.Length > 1) { doValidate = args[1]; // "novalidate" } var editor = new XbimEditorCredentials { ApplicationFullName = record.Par01, // "Databáze datového standardu stavebnictví" ApplicationDevelopersName = record.Par02, // "Michal Kopecký" ApplicationIdentifier = record.Par03, // "DDSS" ApplicationVersion = record.Par04, // "1.0" EditorsFamilyName = record.Par05, // "Žák" EditorsGivenName = record.Par06, // "Josef" EditorsOrganisationName = record.Par07, // "Česká agentura pro standardizaci" }; //IfcStore.ModelProviderFactory.UseMemoryModelProvider(); // OLD VERSION // set up logger to file and console var logFile = Path.ChangeExtension(ifcFile, ".log"); Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.File(logFile) .CreateLogger(); XbimLogging.LoggerFactory.AddSerilog(); IfcStore.ModelProviderFactory.UseMemoryModelProvider(); using (var model = Model.Create(editor)) { //var i = model.Internal.Instances; //using (var txn = model.BeginTransaction()) // OLD VERSION using (var txn = model.Internal.BeginTransaction("Model creation")) { // these will keep cache of units and enums // units have to be defined in the source of 'UnitMap' (compile time) while // enumerations are to be defined in runtime based on the values in the DB var units = new UnitMap(model); var enums = new EnumsMap(model); while (csv.Read()) { record = new RecordLine { Id = csv.GetField <int>("Id"), Pid = csv.GetField <int>("Pid"), Method = csv.GetField("Method"), GlobalId = csv.GetField("GlobalId"), Par01 = csv.GetField("Par01"), Par02 = csv.GetField("Par02"), Par03 = csv.GetField("Par03"), Par04 = csv.GetField("Par04"), Par05 = csv.GetField("Par05"), Par06 = csv.GetField("Par06"), Par07 = csv.GetField("Par07"), Par08 = csv.GetField("Par08"), Par09 = csv.GetField("Par09") }; records.Add(record); //Console.WriteLine(record.Method); if (record.Method == "IfcClassification") { var root = model.CreateBreakedownRoot(record.Par01, null); // "Klasifikace DSS, CCI:ET, CCI:CS, CCI:FS" // set name in default language root.SetName("en", record.Par01); // set name in other languages root.SetName("cs", ""); breakedownRootMap.Add(record.Par01, root); } else if (record.Method == "IfcProjectLibrary") { currentRequirementsSet = model.CreateRequirementSet(record.Par01, null); // "Level of Information Need" if (record.GlobalId != "") { currentRequirementsSet.Entity.GlobalId = record.GlobalId; } // set name in default language currentRequirementsSet.SetName("en", record.Par01); // set name in other languages currentRequirementsSet.SetName("cs", ""); } else if (record.Method == "IfcRelAssignsToControl") { // Purpose of the data requirement/exchange if (!reasonsMap.TryGetValue(record.Id, out Reason reason)) { reason = model.CreateReason(record.Par01, record.Par02); if (record.GlobalId != "") { reason.Entity.GlobalId = record.GlobalId; } reasonsMap.Add(record.Id, reason); // set name in default language reason.SetName("en", record.Par01); // set name in other languages reason.SetName("cs", record.Par02); } reason.AddToContext(currentRequirementsSet); } else if (record.Method == "IfcRelAssignsToActor") { // Actor / Role = Who is interested in the data if (!actorMap.TryGetValue(record.GlobalId, out Actor actor)) { actor = model.CreateActor(record.Par01, null); if (record.GlobalId != "") { actor.Entity.GlobalId = record.GlobalId; } actorMap.Add(record.GlobalId, actor); // set name in default language actor.SetName("en", record.Par01); // set name in other languages actor.SetName("cs", ""); } actor.AddToContext(currentRequirementsSet); } else if (record.Method == "IfcRelAssignsToProcess") { // Milestone = point in time if (!milestonesCache.TryGetValue(record.Id, out Milestone milestone)) { milestone = model.CreateMilestone(record.Par02, null); milestone.Entity.IsMilestone = record.Par03 == "true"; if (record.GlobalId != "") { milestone.Entity.GlobalId = record.GlobalId; } milestonesCache.Add(record.Id, milestone); // set name in default language milestone.SetName("en", record.Par01); // set name in other languages milestone.SetName("cs", record.Par02); } milestone.AddToContext(currentRequirementsSet); } else if (record.Method == "IfcClassificationReference") { // Class within classification // Set parent BreakdownItem parent = null; if (record.Par04 == "") { //Program.ifcCRS = Program.ifcCL; // classification for root class parent = breakedownRootMap[record.Par09]; // classification for root class } else { parent = breakedownMap[record.Pid]; // parent class othewise } // Optionally add new class if (!breakedownMap.ContainsKey(record.Id)) { var item = model.CreateBreakedownItem(record.Par02, record.Par03, null, parent); breakedownMap.Add(record.Id, item); // set name in default language item.SetName("en", record.Par01); // set name in other languages item.SetName("cs", record.Par02); } ; } else if (record.Method == "IfcRelAssociatesClassification") { breakedownMap[record.Id].AddToContext(currentRequirementsSet); } else if (record.Method == "IfcRelDeclares") { // nothing to do, handled by LOIN library } else if (record.Method == "IfcPropertySetTemplate") { if (ifcPropertySetMap.ContainsKey(record.Id)) { PropertySetReused = true; currentPropertySet = ifcPropertySetMap[record.Id]; } else { PropertySetReused = false; currentPropertySet = model.CreatePropertySetTemplate(record.Par01, null); // "Základní informace o místnostech" // set name in default language currentPropertySet.SetName("en", record.Par01); // set name in other languages currentPropertySet.SetName("cs", record.Par02); //ApplicableEntity //Description if (record.Par03 != "") { currentPropertySet.Description = record.Par03; // set name in default language currentPropertySet.SetDescription("en", record.Par03); // set name in other languages currentPropertySet.SetDescription("cs", record.Par04); } else if (record.Par04 != "") { currentPropertySet.Description = record.Par04; // set name in default language currentPropertySet.SetDescription("en", ""); // set name in other languages currentPropertySet.SetDescription("cs", record.Par04); } if (record.GlobalId != "") { currentPropertySet.GlobalId = record.GlobalId; } ifcPropertySetMap.Add(record.Id, currentPropertySet); }; currentRequirementsSet.Add(currentPropertySet); } else if (record.Method == "IfcSimplePropertyTemplate") { if (!PropertySetReused) { if (!ifcPropertyMap.TryGetValue(record.Id, out IfcSimplePropertyTemplate propertyTemplate)) { propertyTemplate = model.New <IfcSimplePropertyTemplate>(p => { p.Name = record.Par08; // "Název EN" // Set description in primary language p.SetName("en", record.Par08); // Set description in other languages p.SetName("cs", record.Par01); }); if (record.GlobalId != "") { propertyTemplate.GlobalId = record.GlobalId; } //Description if (record.Par09 != "") { propertyTemplate.Description = record.Par09; // Set description in primary language propertyTemplate.SetDescription("en", record.Par09); // Set description in other languages propertyTemplate.SetDescription("cs", record.Par02); } else if (record.Par02 != "") { propertyTemplate.Description = record.Par02; // Set description in primary language propertyTemplate.SetDescription("en", ""); // Set description in other languages propertyTemplate.SetDescription("cs", record.Par02); } if (record.Par03 != "") // dataunit { propertyTemplate.PrimaryUnit = units[record.Par03]; } if (record.Par04 != "") // nameof(X) -> "X" { propertyTemplate.PrimaryMeasureType = record.Par04; } //TemplateType switch (record.Par05) { case "P_SINGLEVALUE": propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; break; case "P_ENUMERATEDVALUE": propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_ENUMERATEDVALUE; propertyTemplate.Enumerators = enums.GetOrAdd(record.Par06, record.Par07.Split(",", StringSplitOptions.RemoveEmptyEntries)); // { "Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle"} break; case "P_REFERENCEVALUE": propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_REFERENCEVALUE; break; case "P_BOUNDEDVALUE": propertyTemplate.TemplateType = IfcSimplePropertyTemplateTypeEnum.P_BOUNDEDVALUE; break; default: Console.WriteLine("IfcSimplePropertyTemplate: UNKNOWN TEMPLATE TYPE ", record.Par05); //Program.ifcSPT.TemplateType = ... break; } ; ifcPropertyMap.Add(record.Id, propertyTemplate); } ; currentPropertySet.HasPropertyTemplates.Add(propertyTemplate); currentPropertyTemplate = propertyTemplate; } ; } else if (record.Method == "IfcSIUnit") { var unit = model.New <IfcSIUnit>(); //Name //Program.ifcISU.Name = IfcSIUnitName.SQUARE_METRE; try { unit.Name = ifcSIUnitMap[record.Par01]; } catch (KeyNotFoundException) { Console.WriteLine("IfcSIUnit: UNKNOWN NAME ", record.Par01); //ifcISU.Name = IfcSIUnitName. ... } //UnitType switch (record.Par02) { case "AREAUNIT": unit.UnitType = IfcUnitEnum.AREAUNIT; break; default: Console.WriteLine("IfcSIUnit: UNKNOWN UNIT TYPE ", record.Par02); //ifcISU.UnitType = ... break; } ; currentPropertyTemplate.PrimaryUnit = unit; } else if (record.Method == "IfcDocumentReference") { // Declared data requirements / templates model.New <IfcRelAssociatesDocument>(rd => { rd.RelatedObjects.Add(currentPropertyTemplate); rd.RelatingDocument = model.New <IfcDocumentReference>(doc => { doc.Identification = record.Par01; // "Vyhláška č. 441/2013 Sb." doc.Location = record.Par02; // "https://www.mfcr.cz/cs/legislativa/legislativni-dokumenty/2013/vyhlaska-c-441-2013-sb-16290" doc.Name = record.Par03; // "Vyhláška k provedení zákona o oceňování majetku (oceňovací vyhláška)" }); }); } ; } ; // konec while read txn.Commit(); } // validate schema and proper units var validator = new IfcValidator(); var valid = validator.Check(model.Internal); if (doValidate != "novalidate" && !valid) { throw new Exception("Invalid model shouldn't be stored and used for any purposes."); } // this is stdout if you want to use it //var stdout = Console.OpenStandardOutput(); // writing to stream (any stream) using (var stream = File.Create(ifcFile)) { if (Path.GetExtension(ifcFile) == ".ifcxml") { model.Internal.SaveAsIfcXml(stream); } else { model.Internal.SaveAsIfc(stream); }; } //model.SaveAs("DDSS.ifc"); //model.SaveAs("DDSS.ifcxml"); //model.SaveAs(ifcFile); // args[0] } //STOP }// csv }
/// <summary> /// Load user-defined Property set /// Format: /// PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','> /// Property_name Data_type Revit_Parameter /// ... /// Datatype supported: Text, Integer, Real, Boolean /// Line divider between Property Mapping and User defined property sets: /// #! UserDefinedPset /// </summary> /// <returns>List of property set definitions</returns> public static IEnumerable <IfcPropertySetTemplate> LoadUserDefinedPset() { List <IfcPropertySetTemplate> userDefinedPsets = new List <IfcPropertySetTemplate>(); try { string filename = ExporterCacheManager.ExportOptionsCache.PropertySetOptions.ExportUserDefinedPsetsFileName; if (!File.Exists(filename)) { // This allows for the original behavior of looking in the directory of the export DLL to look for the default file name. filename = GetUserDefPsetFilename(); } if (!File.Exists(filename)) { return(userDefinedPsets); } string extension = Path.GetExtension(filename); if (string.Compare(extension, ".ifcxml", true) == 0 || string.Compare(extension, ".ifcjson", true) == 0 || string.Compare(extension, ".ifc", true) == 0) { DatabaseIfc db = new DatabaseIfc(filename); IfcContext context = db.Context; if (context == null) { return(userDefinedPsets); } foreach (IfcRelDeclares relDeclares in context.Declares) { userDefinedPsets.AddRange(relDeclares.RelatedDefinitions.OfType <IfcPropertySetTemplate>()); } } else { using (StreamReader sr = new StreamReader(filename)) { string line; DatabaseIfc db = new DatabaseIfc(false, ReleaseVersion.IFC4); IfcPropertySetTemplate userDefinedPset = null; while ((line = sr.ReadLine()) != null) { line.TrimStart(' ', '\t'); if (String.IsNullOrEmpty(line)) { continue; } if (line[0] != '#') { // Format: PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','> // Property_name Data_type Revit_Parameter // ** For now it only works for simple property with single value (datatype supported: Text, Integer, Real and Boolean) string[] split = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); if (string.Compare(split[0], "PropertySet:", true) == 0) { userDefinedPset = new IfcPropertySetTemplate(db, split.Length > 2 ? split[1] : "Unknown"); if (split.Count() >= 4) // Any entry with less than 3 par is malformed { switch (split[2][0]) { case 'T': userDefinedPset.TemplateType = IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENONLY; break; case 'I': userDefinedPset.TemplateType = IfcPropertySetTemplateTypeEnum.PSET_OCCURRENCEDRIVEN; break; default: userDefinedPset.TemplateType = IfcPropertySetTemplateTypeEnum.PSET_OCCURRENCEDRIVEN; break; } userDefinedPset.ApplicableEntity = string.Join(",", split[3].Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries)); userDefinedPsets.Add(userDefinedPset); } } else { if (split.Count() >= 2) { string propertyTemplateName = split[0]; IfcSimplePropertyTemplate propertyDefUnit = userDefinedPset[propertyTemplateName] as IfcSimplePropertyTemplate; if (propertyDefUnit == null) { userDefinedPset.AddPropertyTemplate(propertyDefUnit = new IfcSimplePropertyTemplate(db, split[0])); } if (split.Count() >= 3 && !string.IsNullOrEmpty(split[2])) { new IfcRelAssociatesClassification(new IfcClassificationReference(db) { Identification = split[2] }, propertyDefUnit); } if (!string.IsNullOrEmpty(split[1])) { propertyDefUnit.PrimaryMeasureType = "Ifc" + split[1]; } } } } } } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } return(userDefinedPsets); }
public override void Run() { using (var txn = model.BeginTransaction("Example creation")) { IfcProject project = model.Instances.New <IfcProject>(p => p.Name = "TriluxLightingProducts"); IfcUnitAssignment ifcUnitAssignment = model.Instances.New <IfcUnitAssignment>(ua => { ua.Units.Add(model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.LENGTHUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.METRE; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.MILLI; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.MASSUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.GRAM; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.KILO; })); }); var ifcClassificationSystemOmniClass = model.Instances.New <IfcClassification>(); ifcClassificationSystemOmniClass.Name = "Omniclass"; ifcClassificationSystemOmniClass.Edition = "1.0"; ifcClassificationSystemOmniClass.EditionDate = "2018-12-27T00:00:00.0000000"; ifcClassificationSystemOmniClass.Description = "The OmniClass Construction Classification System (known as OmniClass™ or OCCS) is a classification system for the construction industry. OmniClass is useful for many applications, from organizing library materials, product literature, and project information, to providing a classification structure for electronic databases. It incorporates other extant systems currently in use as the basis of many of its Tables – MasterFormat™ for work results, UniFormat for elements, and EPIC (Electronic Product Information Cooperation) for structuring products."; ifcClassificationSystemOmniClass.Location = "http://www.omniclass.org/"; var ifcClassificationReferenceOmniClass = model.Instances.New <IfcClassificationReference>(); ifcClassificationReferenceOmniClass.Identification = "23-35-47"; ifcClassificationReferenceOmniClass.Name = "Electrical Lighting"; ifcClassificationReferenceOmniClass.Description = "NOT PROVIDED"; ifcClassificationReferenceOmniClass.ReferencedSource = ifcClassificationSystemOmniClass; var ifcRelAssociatesClassificationOmniClass = model.Instances.New <IfcRelAssociatesClassification>(); ifcRelAssociatesClassificationOmniClass.RelatingClassification = ifcClassificationReferenceOmniClass; var ifcClassificationSystemUniClass = model.Instances.New <IfcClassification>(); ifcClassificationSystemUniClass.Name = "Uniclass"; ifcClassificationSystemUniClass.Edition = "2015"; ifcClassificationSystemUniClass.EditionDate = ""; ifcClassificationSystemUniClass.Description = ""; ifcClassificationSystemUniClass.Location = "https://www.thenbs.com/our-tools/introducing-uniclass-2015"; var ifcClassificationReferenceUniClass = model.Instances.New <IfcClassificationReference>(); ifcClassificationReferenceUniClass.Identification = "CA-70-10-30"; ifcClassificationReferenceUniClass.Name = "Site lighting equipment"; ifcClassificationReferenceUniClass.Description = "NOT PROVIDED"; ifcClassificationReferenceUniClass.ReferencedSource = ifcClassificationSystemUniClass; var ifcRelAssociatesClassificationUniClass = model.Instances.New <IfcRelAssociatesClassification>(); ifcRelAssociatesClassificationUniClass.RelatingClassification = ifcClassificationReferenceUniClass; //Insert a project library to store the product data templates and type products IfcProjectLibrary ifcProductDataLibrary = New <IfcProjectLibrary>(l => { l.Name = "TriluxLightingProductsLibrary"; l.GlobalId = "1DbshdzGD71ejurQqQcxbw"; l.Description = "Library for Trilux light fixtures product data templates based on the ZVEI European core properties"; l.Phase = "Design,Build,Operate"; }); Comment(ifcProductDataLibrary, @"Root element of this file. Because this doesn't define a specific instance in the building it is a library. It can be used to declare elements, properties, property templates and other library objects which can be later used in the actual design."); Comment(ifcProductDataLibrary.OwnerHistory, @"Owner history is used to define ownership of the information."); var ifcProductDataLibraryDeclarations = New <IfcRelDeclares>(rel => { rel.RelatingContext = ifcProductDataLibrary; }).RelatedDefinitions; Comment(ifcProductDataLibraryDeclarations.OwningEntity, @"This relation points to all definitions declared within the scope of the library. These can be elements, element types, properties or property templates"); //Creating an IfcPropertySetTemplate manually //This is not optimal //Instead of creating the IfcPropertySetTemplates manually, //they should be loaded from the publishing dictionary //Read templates from excel sheet var workbook = new XLWorkbook(Path.Combine(sourceFolder, sourceFile)); IXLWorksheet worksheetTemplates; IXLRange rangeTemplates; worksheetTemplates = workbook.Worksheet("Templates"); rangeTemplates = worksheetTemplates.Range("A1:H27"); IXLTable rawDataTemplates = rangeTemplates.AsTable(); DataTable dtTemplates = ReadDataTable(worksheetTemplates); IfcPropertySetTemplate ifcPropertySetTemplate = model.Instances.New <IfcPropertySetTemplate>(pset => { pset.GlobalId = "1DbshTzGD71ejurQqQcxbw"; pset.Name = "IfcPropertySetTemplate"; pset.Description = "Group of properties for " + ifcProductDataLibrary.Name; pset.ApplicableEntity = "IfcLightFixture/USERDEFINED"; pset.TemplateType = Xbim.Ifc4.Interfaces.IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENONLY; }); Comment(ifcPropertySetTemplate, @"Declaration of 'IfcPropertySetTemplate' within the library for lighting product data templates."); Comment(ifcPropertySetTemplate, @"Insert property templates; they should be loaded from the publishing dictionary"); foreach (DataRow row in dtTemplates.Rows) { //Publisher SystemName GlobalId PrimaryMeasureType DataColumn ifcPropertySetTemplate.HasPropertyTemplates.AddRange(new[] { model.Instances.New <IfcSimplePropertyTemplate>(pt => { pt.Name = row["SystemName"].ToString(); pt.Description = ""; pt.GlobalId = row["GlobalId"].ToString(); pt.TemplateType = Xbim.Ifc4.Interfaces.IfcSimplePropertyTemplateTypeEnum.P_SINGLEVALUE; pt.AccessState = Xbim.Ifc4.Interfaces.IfcStateEnum.LOCKED; pt.PrimaryMeasureType = row["PrimaryMeasureType"].ToString(); string primaryMeasureType = row["PrimaryMeasureType"].ToString(); if (primaryMeasureType == typeof(IfcLengthMeasure).Name) { pt.PrimaryUnit = model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.LENGTHUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.METRE; u.Prefix = Xbim.Ifc4.Interfaces.IfcSIPrefix.MILLI; }); } else if (primaryMeasureType == typeof(IfcMassMeasure).Name) { pt.PrimaryUnit = model.Instances.New <IfcSIUnit>(u => { u.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.MASSUNIT; u.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.GRAM; }); } else if (primaryMeasureType == typeof(IfcPlaneAngleMeasure).Name) { pt.PrimaryUnit = model.Instances.New <IfcConversionBasedUnit>(punit => { //Convert the angel measure from the unit grad to the SI Unit radian //rad=grad*(PI/180) punit.Name = "Grad"; punit.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.PLANEANGLEUNIT; punit.ConversionFactor = model.Instances.New <IfcMeasureWithUnit>(mwu => { mwu.UnitComponent = model.Instances.New <IfcSIUnit>(siUnit => { siUnit.UnitType = Xbim.Ifc4.Interfaces.IfcUnitEnum.PLANEANGLEUNIT; siUnit.Name = Xbim.Ifc4.Interfaces.IfcSIUnitName.RADIAN; }); mwu.ValueComponent = new IfcReal(Math.PI / 180); }); punit.Dimensions = model.Instances.New <IfcDimensionalExponents>(dim => { dim.LengthExponent = 0; dim.MassExponent = 0; dim.TimeExponent = 0; dim.ElectricCurrentExponent = 0; dim.ThermodynamicTemperatureExponent = 0; dim.AmountOfSubstanceExponent = 0; dim.LuminousIntensityExponent = 0; }); }); } }) }); } ; ifcProductDataLibraryDeclarations.Add(ifcPropertySetTemplate); //Read source data from excel sheet var workbookData = new XLWorkbook(Path.Combine(sourceFolder, sourceFile)); IXLWorksheet worksheetData; IXLRange rangeData; worksheetData = workbookData.Worksheet("Sheets"); rangeData = worksheetData.Range("A1:Z690"); IXLTable rawData = rangeData.AsTable(); DataTable dtData = ReadDataTable(worksheetData); var ifcRelDefinesByTemplate = New <IfcRelDefinesByTemplate>(dbt => { dbt.RelatingTemplate = ifcPropertySetTemplate; }); int n = 0; do { foreach (DataRow row in dtData.Rows) { var ifcTypeProduct = model.Instances.New <IfcTypeProduct>(); ifcTypeProduct.GlobalId = "1DbshTzGD71ejurQqQcxbw"; //How to generate a fresh IFC GlobalId with XBim? ifcTypeProduct.Name = row["Name"].ToString(); ifcTypeProduct.Description = "Description of " + ifcTypeProduct.Name; ifcTypeProduct.ApplicableOccurrence = "IfcLightFixture"; ifcRelAssociatesClassificationOmniClass.RelatedObjects.Add(ifcTypeProduct); ifcRelAssociatesClassificationUniClass.RelatedObjects.Add(ifcTypeProduct); IfcPropertySet ifcPropertySet = model.Instances.New <IfcPropertySet>(pset => { pset.Name = "Properties of " + ifcTypeProduct.Name; }); foreach (DataRow template in dtTemplates.Rows) { if (template["PropertyWithDocumentLink"].ToString() == "Yes") { //Insert the product information into documents string folderName = template["SystemName"].ToString(); string docName = row[template["SystemName"].ToString()].ToString(); IfcDocumentInformation ifcDocumentInformation = model.Instances.New <IfcDocumentInformation>(doc => { doc.Identification = docName; doc.Name = docName; doc.Location = $@"{folderName}/{docName}"; doc.Confidentiality = Xbim.Ifc4.Interfaces.IfcDocumentConfidentialityEnum.PUBLIC; doc.ElectronicFormat = MimeTypes.GetMimeType(docName); doc.IntendedUse = "Product information"; doc.Purpose = "Product information"; }); IfcRelAssociatesDocument ifcRelAssociatesDocument = model.Instances.New <IfcRelAssociatesDocument>(docref => { docref.RelatedObjects.Add(ifcTypeProduct); docref.RelatingDocument = ifcDocumentInformation; }); //<IfcRelAssociatesDocument GlobalId="3vBcwkKGf1cxmQZUtNnL0g"> // < RelatedObjects > // < IfcTransportElement xsi: nil = "true" ref= "i143" /> // </ RelatedObjects > // < RelatingDocument > // < IfcDocumentInformation xsi: nil = "true" ref= "i150" /> // </ RelatingDocument > //</ IfcRelAssociatesDocument > } else { //Insert the product information into Properties ifcPropertySet.HasProperties.AddRange(new[] { model.Instances.New <IfcPropertySingleValue>(p => { string propertyName = template["SystemName"].ToString(); var dataValue = row[propertyName]; p.Name = propertyName; p.Description = ""; string primaryMeasureType = template["PrimaryMeasureType"].ToString(); if (primaryMeasureType == typeof(IfcLengthMeasure).Name) { p.NominalValue = new IfcMassMeasure(Double.Parse(dataValue.ToString())); } else if (primaryMeasureType == typeof(IfcMassMeasure).Name) { p.NominalValue = new IfcMassMeasure(Double.Parse(dataValue.ToString())); } else if (primaryMeasureType == typeof(IfcPlaneAngleMeasure).Name) { p.NominalValue = new IfcPlaneAngleMeasure(Double.Parse(dataValue.ToString())); } else { p.NominalValue = new IfcLabel(dataValue.ToString()); } }) }); } } ; ifcTypeProduct.HasPropertySets.Add(ifcPropertySet); ifcProductDataLibraryDeclarations.Add(ifcTypeProduct); Comment(ifcTypeProduct, @"Declaration of 'IfcTypeProduct' within the library for a ligthing product."); ifcRelDefinesByTemplate.RelatedPropertySets.Add(ifcPropertySet); } n++; }while (n < 1); txn.Commit(); } string targetFileName = Path.Combine(targetFolder, targetFile); SaveAs(targetFileName, true, typeof(IfcProjectLibrary)); //Create ifcZip file File.Delete(zipFile); ZipFile.CreateFromDirectory(sourceFolder, zipFile); using (ZipArchive zipArchive = ZipFile.Open(zipFile, ZipArchiveMode.Update)) { zipArchive.GetEntry(sourceFile).Delete(); zipArchive.CreateEntryFromFile($"{targetFolder}/{targetFile}.ifcXML", $"{targetFile}.ifcXML"); zipArchive.CreateEntryFromFile($"{targetFolder}/{targetFile}.ifc", $"{targetFile}.ifc"); } }