public static IfcNamedUnit GetUnitFor(this IfcUnitAssignment ua, IfcPhysicalSimpleQuantity Quantity) { if (Quantity.Unit != null) { return(Quantity.Unit); } IfcUnitEnum?requiredUnit = null; // list of possible types taken from: // http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcquantityresource/lexical/ifcphysicalsimplequantity.htm // if (Quantity is IfcQuantityLength) { requiredUnit = IfcUnitEnum.LENGTHUNIT; } else if (Quantity is IfcQuantityArea) { requiredUnit = IfcUnitEnum.AREAUNIT; } else if (Quantity is IfcQuantityVolume) { requiredUnit = IfcUnitEnum.VOLUMEUNIT; } else if (Quantity is IfcQuantityCount) // really not sure what to do here. { return(null); } else if (Quantity is IfcQuantityWeight) { requiredUnit = IfcUnitEnum.MASSUNIT; } else if (Quantity is IfcQuantityTime) { requiredUnit = IfcUnitEnum.TIMEUNIT; } if (requiredUnit == null) { return(null); } IfcNamedUnit nu = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit); if (nu == null) { nu = ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit); } return(nu); }
public static void SetOrChangeSIUnit(this IfcProject ifcProject, IfcUnitEnum unitType, IfcSIUnitName siUnitName, IfcSIPrefix?siUnitPrefix) { IModel model = ifcProject.ModelOf; if (ifcProject.UnitsInContext == null) { ifcProject.UnitsInContext = model.Instances.New <IfcUnitAssignment>(); } IfcUnitAssignment unitsAssignment = ifcProject.UnitsInContext; unitsAssignment.SetOrChangeSIUnit(unitType, siUnitName, siUnitPrefix); }
public static void SetOrChangeConversionUnit(this IfcProject ifcProject, IfcUnitEnum unitType, ConversionBasedUnit conversionUnit) { IModel model = ifcProject.ModelOf; if (ifcProject.UnitsInContext == null) { ifcProject.UnitsInContext = model.Instances.New <IfcUnitAssignment>(); } IfcUnitAssignment unitsAssignment = ifcProject.UnitsInContext; unitsAssignment.SetOrChangeConversionUnit(unitType, conversionUnit); }
/// <summary> /// Sets the Length Unit to be SIUnit and SIPrefix, returns false if the units are not SI /// </summary> /// <param name = "ua"></param> /// <param name = "siUnitName"></param> /// <param name = "siPrefix"></param> /// <returns></returns> public static bool SetSILengthUnits(this IfcUnitAssignment ua, IfcSIUnitName siUnitName, IfcSIPrefix?siPrefix) { IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == IfcUnitEnum.LENGTHUNIT); if (si != null) { si.Prefix = siPrefix; si.Name = siUnitName; return(true); } else { return(false); } }
public static void SetOrChangeConversionUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, ConversionBasedUnit unit) { IModel model = ua.ModelOf; IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType); if (si != null) { ua.Units.Remove(si); try { model.Delete(si); } catch (Exception) {} } ua.Units.Add(GetNewConversionUnit(model, unitType, unit)); }
/// <summary> /// Get Monetary Unit /// </summary> ///<param name="value">string representing the currency type</param> private void SetMonetaryUnit(string value) { string code = ""; //TODO: Convert currency to match pick list //convert to pick list hard coded for now if (!string.IsNullOrEmpty(value)) { if (value == "Dollars") { code = "USD"; } else if (value == "Euros") { code = "EUR"; } else if (value == "Pounds") { code = "GBP"; } } if (string.IsNullOrEmpty(code)) { code = CultureInfo.GetCultures(CultureTypes.SpecificCultures) .Where(c => new RegionInfo(c.LCID).CurrencyEnglishName == value) .Select(c => new RegionInfo(c.LCID).ISOCurrencySymbol) .FirstOrDefault(); } IfcCurrencyEnum enumCode; if (Enum.TryParse(code, out enumCode)) { IfcUnitAssignment ifcUnitAssignment = GetProjectUnitAssignment(); IfcMonetaryUnit mu = ifcUnitAssignment.Units.OfType <IfcMonetaryUnit>().FirstOrDefault(); if (mu != null) { mu.Currency = enumCode; } else { ifcUnitAssignment.Units.Add(Model.Instances.New <IfcMonetaryUnit>(ifcmu => { ifcmu.Currency = enumCode; })); } } }
/// <summary> /// Convert string back into IfcSIUnitName and IfcSIPrefix enumerations /// </summary> /// <param name="unitType">IfcUnitEnum unit type</param> /// <param name="value">string representing the unit type</param> private void SetUnitToProject(IfcUnitEnum unitType, string value) { IfcSIUnitName?returnUnit; IfcSIPrefix? returnPrefix; IfcUnitAssignment ifcUnitAssignment = GetProjectUnitAssignment(); if (GetUnitEnumerations(value, out returnUnit, out returnPrefix)) { if (returnUnit != null) { ifcUnitAssignment.SetOrChangeSiUnit(unitType, (IfcSIUnitName)returnUnit.Value, returnPrefix); } } else { ConversionBasedUnit conversionBasedUnit; value = value.Trim().Replace(" ", "_").ToUpper(); //see if the passed value contains a ConversionBasedUnit value, i.e INCHS would match ConversionBasedUnit.INCH string[] cBasedUnits = Enum.GetNames(typeof(ConversionBasedUnit)); if (!cBasedUnits.Contains(value)) { foreach (string str in cBasedUnits) { if (str == value) { break; } string test = str.Split('_').First(); //try both ways if ((value.Contains(test)) || (test.Contains(value)) ) { value = str; break; } } } if (Enum.TryParse(value, out conversionBasedUnit)) { ifcUnitAssignment.SetOrChangeConversionUnit(unitType, conversionBasedUnit); } } }
private void AddQuantityPSet(IfcElementQuantity pSet, IfcUnitAssignment modelUnits) { if (pSet == null) { return; } foreach (var item in pSet.Quantities.OfType <IfcPhysicalSimpleQuantity>()) // currently only handles IfcPhysicalSimpleQuantity { var v = modelUnits.GetUnitFor(item); _quantities.Add(new PropertyItem { PropertySetName = pSet.Name, Name = item.Name, Value = item + " " + v.GetName() }); } }
public void RetrieveUnit(IfcUnitAssignment ifcUnitAssignment) { IfcUnitAssignment = ifcUnitAssignment; _bbUnit = BbUnit.Imperial; foreach (var unit in IfcUnitAssignment.Units) { if (!(unit.Value is IfcSIUnit)) { continue; } var si = unit.Value as IfcSIUnit; if (si.UnitType == IfcUnitEnum.LENGTHUNIT && si.Name == IfcSIUnitName.METRE) { _bbUnit = BbUnit.Metric; } } }
private void CreateProject(IfcStore model, BaseUnits units = BaseUnits.Meters) { using (var txn = model.BeginTransaction("Initialising...")) { var project = model.Instances.New <IfcProject>(); project.Initialize(ProjectUnits.SIUnitsUK); project.Name = "Pegasus"; // By default the units are mm, m2 and m3 // Change the length unit to meters (metres) // Note xbim doesn't have imperial units so we might have to add a complete set of imperial units here, // check out IfcProjectPartial.cs switch (units) { case BaseUnits.Millimeters: model.Instances.OfType <IfcSIUnit>().Where(u => u.UnitType == IfcUnitEnum.LENGTHUNIT).ToList().ForEach(u => u.Prefix = null); break; case BaseUnits.Meters: break; case BaseUnits.Feet: { IfcUnitAssignment unitAssignment = model.Instances.New <IfcUnitAssignment>(); unitAssignment.SetOrChangeConversionUnit(IfcUnitEnum.LENGTHUNIT, ConversionBasedUnit.Foot); unitAssignment.SetOrChangeConversionUnit(IfcUnitEnum.AREAUNIT, ConversionBasedUnit.SquareFoot); unitAssignment.SetOrChangeConversionUnit(IfcUnitEnum.VOLUMEUNIT, ConversionBasedUnit.CubicFoot); } break; case BaseUnits.Inches: { IfcUnitAssignment unitAssignment = model.Instances.New <IfcUnitAssignment>(); unitAssignment.SetOrChangeConversionUnit(IfcUnitEnum.LENGTHUNIT, ConversionBasedUnit.Inch); unitAssignment.SetOrChangeConversionUnit(IfcUnitEnum.AREAUNIT, ConversionBasedUnit.SquareFoot); unitAssignment.SetOrChangeConversionUnit(IfcUnitEnum.VOLUMEUNIT, ConversionBasedUnit.CubicFoot); } break; } txn.Commit(); } }
public static IfcStore CreateandInitModel(string projectName, IfcUnitAssignment unitType) { IfcSIUnit unit = unitType.Units.FirstOrDefault(u => (u as IfcSIUnit).UnitType == IfcUnitEnum.LENGTHUNIT) as IfcSIUnit; if (unit.Name == IfcSIUnitName.METRE) { CADConfig.Units = linearUnitsType.Meters; } else { CADConfig.Units = linearUnitsType.Millimeters; } //first we need to set up some credentials for ownership of data in the new model var credentials = new XbimEditorCredentials { ApplicationDevelopersName = "Cad2Bim", ApplicationFullName = "CadTo3D Application", ApplicationIdentifier = "ThinkDev.exe", ApplicationVersion = "1.0", EditorsFamilyName = "Team", EditorsGivenName = "ThinkDev", EditorsOrganisationName = "ThinkDevTeam" }; //now we can create an IfcStore, it is in Ifc4 format and will be held in memory rather than in a database //database is normally better in performance terms if the model is large >50MB of Ifc or if robust transactions are required var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.InMemoryModel); //Begin a transaction as all changes to a model are ACID using (var txn = model.BeginTransaction("Initialise Model")) { //create a project var project = model.Instances.New <IfcProject>(); //set the units to SI (mm and metres) project.InitProject(CADConfig.Units); project.Name = projectName; //now commit the changes, else they will be rolled back at the end of the scope of the using statement txn.Commit(); } return(model); }
public static void SetOrChangeSIUnit(this IfcUnitAssignment ua, IfcUnitEnum unitType, IfcSIUnitName siUnitName, IfcSIPrefix?siUnitPrefix) { IModel model = ua.ModelOf; IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType); if (si != null) { si.Prefix = siUnitPrefix; si.Name = siUnitName; } else { ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = unitType; s.Name = siUnitName; s.Prefix = siUnitPrefix; })); } }
public static double GetPower(this IfcUnitAssignment ua, IfcUnitEnum unitType) { IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == unitType); if (si != null && si.Prefix.HasValue) { return(si.Power()); } else { IfcConversionBasedUnit cu = ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == unitType); if (cu != null) { IfcMeasureWithUnit mu = cu.ConversionFactor; IfcSIUnit uc = mu.UnitComponent as IfcSIUnit; //some BIM tools such as StruCAD write the conversion value out as a Length Measure if (uc != null) { ExpressType et = ((ExpressType)mu.ValueComponent); double cFactor = 1.0; if (et.UnderlyingSystemType == typeof(double)) { cFactor = (double)et.Value; } else if (et.UnderlyingSystemType == typeof(int)) { cFactor = (double)((int)et.Value); } else if (et.UnderlyingSystemType == typeof(long)) { cFactor = (double)((long)et.Value); } return(uc.Power() * cFactor); } } } return(1.0); }
public UnitAssignmentRelation(IfcStore model) { ifcUnitAssignment = model.Instances.New <IfcUnitAssignment>(p => { units = new List <SIUnit>() { new SIUnit(model, IfcSIUnitName.METRE, IfcSIPrefix.MILLI, IfcUnitEnum.LENGTHUNIT), new SIUnit(model, IfcSIUnitName.SQUARE_METRE, IfcUnitEnum.AREAUNIT), new SIUnit(model, IfcSIUnitName.CUBIC_METRE, IfcUnitEnum.VOLUMEUNIT), new SIUnit(model, IfcSIUnitName.GRAM, IfcSIPrefix.KILO, IfcUnitEnum.MASSUNIT), new SIUnit(model, IfcSIUnitName.SECOND, IfcUnitEnum.TIMEUNIT), new SIUnit(model, IfcSIUnitName.RADIAN, IfcUnitEnum.PLANEANGLEUNIT), new SIUnit(model, IfcSIUnitName.STERADIAN, IfcUnitEnum.SOLIDANGLEUNIT), new SIUnit(model, IfcSIUnitName.DEGREE_CELSIUS, IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT), new SIUnit(model, IfcSIUnitName.LUMEN, IfcUnitEnum.LUMINOUSFLUXUNIT) }; foreach (var item in units) { p.Units.Add(item.IfcSIUnit); } }); }
public static string GetLengthUnitName(this IfcUnitAssignment ua) { IfcSIUnit si = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == IfcUnitEnum.LENGTHUNIT); if (si != null) { if (si.Prefix.HasValue) { return(string.Format("{0}{1}", si.Prefix.Value.ToString(), si.Name.ToString())); } else { return(si.Name.ToString()); } } else { IfcConversionBasedUnit cu = ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == IfcUnitEnum.LENGTHUNIT); if (cu != null) { return(cu.Name); } else { IfcConversionBasedUnit cbu = ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault( u => u.UnitType == IfcUnitEnum.LENGTHUNIT); if (cbu != null) { return(cbu.Name); } } } return(""); }
private void FillQuantityData() { if (_quantities.Count > 0) { return; //don't fill unless empty } //now the property sets for any IfcObject ifcObj = _entity as IfcObject; // local cache for efficiency IfcUnitAssignment modelUnits = null; if (ifcObj != null) { foreach (IfcRelDefinesByProperties relDef in ifcObj.IsDefinedByProperties.Where(r => r.RelatingPropertyDefinition is IfcElementQuantity)) { IfcElementQuantity pSet = relDef.RelatingPropertyDefinition as IfcElementQuantity; if (pSet != null) { foreach (var item in pSet.Quantities.OfType <IfcPhysicalSimpleQuantity>()) //only handle simple quantities properties { if (modelUnits == null) { modelUnits = item.ModelOf.Instances.OfType <IfcUnitAssignment>().FirstOrDefault(); // not optional, should never return void in valid model } var v = modelUnits.GetUnitFor(item); _quantities.Add(new PropertyItem() { PropertySetName = pSet.Name, Name = item.Name, Value = item.ToString() + " " + v.GetName() }); } } } } }
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"); } }
/// <summary> /// /// </summary> /// <param name="bbUnitBase"></param> public void SetUnit( BbUnit bbUnitBase) { _bbUnit = bbUnitBase; IfcUnitAssignment = new IfcUnitAssignment { Units = new List <IfcUnit>() }; switch (_bbUnit) { case BbUnit.Metric: #region metric IfcUnitAssignment.Units.Add( new IfcUnit { Value = new IfcSIUnit( IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.MILLI, IfcSIUnitName.METRE) }); IfcUnitAssignment.Units.Add( new IfcUnit { Value = new IfcSIUnit( IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE) }); IfcUnitAssignment.Units.Add( new IfcUnit { Value = new IfcSIUnit( IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE) }); #endregion break; case BbUnit.Imperial: #region imperial var leng = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 1, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.LENGTHUNIT, Name = "FOOT", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcRatioMeasure { Value = 0.3048 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE) } } }; var length = new IfcUnit { Value = leng }; IfcUnitAssignment.Units.Add(length); var area = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 2, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.AREAUNIT, Name = "SQUARE FOOT", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcRatioMeasure { Value = 0.09290304 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE) } } }; var areaUnit = new IfcUnit { Value = area }; IfcUnitAssignment.Units.Add(areaUnit); var volume = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 3, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.VOLUMEUNIT, Name = "CUBIC FOOT", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcRatioMeasure { Value = 0.02831685 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE) } } }; var volumeUnit = new IfcUnit { Value = volume }; IfcUnitAssignment.Units.Add(volumeUnit); #endregion break; } var degree = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 0, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.PLANEANGLEUNIT, Name = "DEGREE", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcPlaneAngleMeasure { Value = 0.01745329 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.PLANEANGLEUNIT, IfcSIUnitName.RADIAN) } } }; var angle = new IfcUnit { Value = degree }; IfcUnitAssignment.Units.Add(angle); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.SOLIDANGLEUNIT, IfcSIUnitName.STERADIAN) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.TIMEUNIT, IfcSIUnitName.SECOND) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIUnitName.DEGREE_CELSIUS) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIUnitName.LUMEN) }); }
public static IfcNamedUnit GetUnitFor(this IfcUnitAssignment ua, IfcPropertySingleValue Property) { if (Property.Unit != null) { return((IfcNamedUnit)Property.Unit); } // nominal value can be of types with subtypes: // IfcMeasureValue, IfcSimpleValue, IfcDerivedMeasureValue IfcUnitEnum?requiredUnit = null; // types from http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcmeasureresource/lexical/ifcmeasurevalue.htm if (Property.NominalValue is IfcVolumeMeasure) { requiredUnit = IfcUnitEnum.VOLUMEUNIT; } else if (Property.NominalValue is IfcAreaMeasure) { requiredUnit = IfcUnitEnum.AREAUNIT; } else if (Property.NominalValue is IfcLengthMeasure) { requiredUnit = IfcUnitEnum.LENGTHUNIT; } else if (Property.NominalValue is IfcPositiveLengthMeasure) { requiredUnit = IfcUnitEnum.LENGTHUNIT; } else if (Property.NominalValue is IfcAmountOfSubstanceMeasure) { requiredUnit = IfcUnitEnum.AMOUNTOFSUBSTANCEUNIT; } else if (Property.NominalValue is IfcContextDependentMeasure) { requiredUnit = null; // todo: not sure what to do here } else if (Property.NominalValue is IfcCountMeasure) { requiredUnit = null; // todo: not sure what to do here } else if (Property.NominalValue is IfcDescriptiveMeasure) { requiredUnit = null; // todo: not sure what to do here } else if (Property.NominalValue is IfcElectricCurrentMeasure) { requiredUnit = IfcUnitEnum.ELECTRICCURRENTUNIT; } else if (Property.NominalValue is IfcLuminousIntensityMeasure) { requiredUnit = IfcUnitEnum.LUMINOUSINTENSITYUNIT; } else if (Property.NominalValue is IfcMassMeasure) { requiredUnit = IfcUnitEnum.MASSUNIT; } else if (Property.NominalValue is IfcNormalisedRatioMeasure) { requiredUnit = null; // todo: not sure what to do here } else if (Property.NominalValue is IfcNumericMeasure) { requiredUnit = null; // todo: not sure what to do here. } else if (Property.NominalValue is IfcParameterValue) { requiredUnit = null; // todo: not sure what to do here. } else if (Property.NominalValue is IfcPlaneAngleMeasure) { requiredUnit = IfcUnitEnum.PLANEANGLEUNIT; } else if (Property.NominalValue is IfcPositiveRatioMeasure) { requiredUnit = null; // todo: not sure what to do here. } else if (Property.NominalValue is IfcPositivePlaneAngleMeasure) { requiredUnit = IfcUnitEnum.PLANEANGLEUNIT; } else if (Property.NominalValue is IfcRatioMeasure) { requiredUnit = null; // todo: not sure what to do here. } else if (Property.NominalValue is IfcSolidAngleMeasure) { requiredUnit = IfcUnitEnum.SOLIDANGLEUNIT; } else if (Property.NominalValue is IfcThermodynamicTemperatureMeasure) { requiredUnit = IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT; } else if (Property.NominalValue is IfcTimeMeasure) { requiredUnit = IfcUnitEnum.TIMEUNIT; } else if (Property.NominalValue is IfcComplexNumber) { requiredUnit = null; // todo: not sure what to do here. } // types from IfcSimpleValue else if (Property.NominalValue is IfcSimpleValue) { requiredUnit = null; } // more measures types to be taken from http://www.buildingsmart-tech.org/ifc/IFC2x3/TC1/html/ifcmeasureresource/lexical/ifcderivedmeasurevalue.htm if (requiredUnit == null) { return(null); } IfcNamedUnit nu = ua.Units.OfType <IfcSIUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit); if (nu == null) { nu = ua.Units.OfType <IfcConversionBasedUnit>().FirstOrDefault(u => u.UnitType == (IfcUnitEnum)requiredUnit); } return(nu); }
public void RetrieveUnit(IfcUnitAssignment ifcUnitAssignment) { IfcUnitAssignment = ifcUnitAssignment; _bbUnit = BbUnit.Imperial; foreach (var unit in IfcUnitAssignment.Units) { if (!(unit.Value is IfcSIUnit)) continue; var si = unit.Value as IfcSIUnit; if (si.UnitType == IfcUnitEnum.LENGTHUNIT && si.Name == IfcSIUnitName.METRE) _bbUnit = BbUnit.Metric; } }
/// <summary> /// /// </summary> /// <param name="bbUnitBase"></param> public void SetUnit( BbUnit bbUnitBase) { _bbUnit = bbUnitBase; IfcUnitAssignment = new IfcUnitAssignment { Units = new List<IfcUnit>() }; switch (_bbUnit) { case BbUnit.Metric: #region metric IfcUnitAssignment.Units.Add( new IfcUnit { Value = new IfcSIUnit( IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.MILLI, IfcSIUnitName.METRE) }); IfcUnitAssignment.Units.Add( new IfcUnit { Value = new IfcSIUnit( IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE) }); IfcUnitAssignment.Units.Add( new IfcUnit { Value = new IfcSIUnit( IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE) }); #endregion break; case BbUnit.Imperial: #region imperial var leng = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 1, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.LENGTHUNIT, Name = "FOOT", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcRatioMeasure { Value = 0.3048 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE) } } }; var length = new IfcUnit { Value = leng }; IfcUnitAssignment.Units.Add(length); var area = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 2, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.AREAUNIT, Name = "SQUARE FOOT", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcRatioMeasure { Value = 0.09290304 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE) } } }; var areaUnit = new IfcUnit { Value = area }; IfcUnitAssignment.Units.Add(areaUnit); var volume = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 3, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.VOLUMEUNIT, Name = "CUBIC FOOT", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcRatioMeasure { Value = 0.02831685 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE) } } }; var volumeUnit = new IfcUnit { Value = volume }; IfcUnitAssignment.Units.Add(volumeUnit); #endregion break; } var degree = new IfcConversionBasedUnit { Dimensions = new IfcDimensionalExponents { LengthExponent = 0, MassExponent = 0, TimeExponent = 0, ElectricCurrentExponent = 0, ThermodynamicTemperatureExponent = 0, AmountOfSubstanceExponent = 0, LuminousIntensityExponent = 0, }, UnitType = IfcUnitEnum.PLANEANGLEUNIT, Name = "DEGREE", ConversionFactor = new IfcMeasureWithUnit { ValueComponent = new IfcValue { Value = new IfcPlaneAngleMeasure { Value = 0.01745329 } }, UnitComponent = new IfcUnit { Value = new IfcSIUnit(IfcUnitEnum.PLANEANGLEUNIT, IfcSIUnitName.RADIAN) } } }; var angle = new IfcUnit { Value = degree }; IfcUnitAssignment.Units.Add(angle); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.SOLIDANGLEUNIT, IfcSIUnitName.STERADIAN) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.TIMEUNIT, IfcSIUnitName.SECOND) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIUnitName.DEGREE_CELSIUS) }); IfcUnitAssignment.Units.Add( new IfcUnit() { Value = new IfcSIUnit(IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIUnitName.LUMEN) }); }
public IfcProject(IfcGloballyUniqueId __GlobalId, IfcOwnerHistory __OwnerHistory, IfcLabel?__Name, IfcText?__Description, IfcLabel?__ObjectType, IfcLabel?__LongName, IfcLabel?__Phase, IfcRepresentationContext[] __RepresentationContexts, IfcUnitAssignment __UnitsInContext) : base(__GlobalId, __OwnerHistory, __Name, __Description, __ObjectType, __LongName, __Phase, __RepresentationContexts, __UnitsInContext) { }
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 IfcProject(IfcGloballyUniqueId __GlobalId, IfcOwnerHistory __OwnerHistory, IfcLabel?__Name, IfcText?__Description, IfcLabel?__ObjectType, IfcLabel?__LongName, IfcLabel?__Phase, IfcRepresentationContext[] __RepresentationContexts, IfcUnitAssignment __UnitsInContext) : base(__GlobalId, __OwnerHistory, __Name, __Description, __ObjectType) { this._LongName = __LongName; this._Phase = __Phase; this._RepresentationContexts = new HashSet <IfcRepresentationContext>(__RepresentationContexts); this._UnitsInContext = __UnitsInContext; }
protected IfcContext(IfcGloballyUniqueId __GlobalId, IfcOwnerHistory __OwnerHistory, IfcLabel?__Name, IfcText?__Description, IfcLabel?__ObjectType, IfcLabel?__LongName, IfcLabel?__Phase, IfcRepresentationContext[] __RepresentationContexts, IfcUnitAssignment __UnitsInContext) : base(__GlobalId, __OwnerHistory, __Name, __Description) { this.ObjectType = __ObjectType; this.LongName = __LongName; this.Phase = __Phase; this.RepresentationContexts = new HashSet <IfcRepresentationContext>(__RepresentationContexts); this.UnitsInContext = __UnitsInContext; this.IsDefinedBy = new HashSet <IfcRelDefinesByProperties>(); this.Declares = new HashSet <IfcRelDeclares>(); }
public Model(IDictionary <Guid, BaseIfc> storage, string name, string description, IfcAddress address, IfcPerson user, IfcOrganization owner) { this.storage = storage; this.storage.Add(address.Id, address); this.storage.Add(user.Id, user); this.storage.Add(owner.Id, owner); // Create an organization for app creation. var appOrg = new IfcOrganization(APPNAME); this.storage.Add(appOrg.Id, appOrg); // Create an authoring application. var v = owner.GetType().Assembly.GetName().Version.ToString(); var app = new IfcApplication(appOrg, v, APPNAME, APPNAME); this.storage.Add(app.Id, app); // Create an person and history for the owner history. var personAndOrg = new IfcPersonAndOrganization(user, owner); this.storage.Add(personAndOrg.Id, personAndOrg); // Create an owner history for the project. var history = new IfcOwnerHistory(personAndOrg, app, UnixNow()); this.storage.Add(history.Id, history); var lu = new IfcSIUnit(null, IfcUnitEnum.LENGTHUNIT, IfcSIUnitName.METRE); this.storage.Add(lu.Id, lu); var lengthUnit = new IfcUnit(lu); var au = new IfcSIUnit(null, IfcUnitEnum.AREAUNIT, IfcSIUnitName.SQUARE_METRE); this.storage.Add(au.Id, au); var areaUnit = new IfcUnit(au); var vu = new IfcSIUnit(null, IfcUnitEnum.VOLUMEUNIT, IfcSIUnitName.CUBIC_METRE); this.storage.Add(vu.Id, vu); var volumeUnit = new IfcUnit(vu); var sau = new IfcSIUnit(null, IfcUnitEnum.SOLIDANGLEUNIT, IfcSIUnitName.STERADIAN); this.storage.Add(sau.Id, sau); var solidAngleUnit = new IfcUnit(sau); var mu = new IfcSIUnit(null, IfcUnitEnum.MASSUNIT, IfcSIUnitName.GRAM); this.storage.Add(mu.Id, mu); var massUnit = new IfcUnit(mu); var tu = new IfcSIUnit(null, IfcUnitEnum.TIMEUNIT, IfcSIUnitName.SECOND); this.storage.Add(tu.Id, tu); var timeUnit = new IfcUnit(tu); var thu = new IfcSIUnit(null, IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIUnitName.DEGREE_CELSIUS); this.storage.Add(thu.Id, thu); var thermUnit = new IfcUnit(thu); var lmu = new IfcSIUnit(null, IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIUnitName.LUMEN); this.storage.Add(lmu.Id, lmu); var lumUnit = new IfcUnit(lmu); var pau = new IfcSIUnit(null, IfcUnitEnum.PLANEANGLEUNIT, IfcSIUnitName.RADIAN); this.storage.Add(pau.Id, pau); var planeAngleUnit = new IfcUnit(pau); var measure = new IfcMeasureWithUnit(new IfcValue(new IfcMeasureValue(new IfcPlaneAngleMeasure(1.745e-2))), planeAngleUnit); this.storage.Add(measure.Id, measure); var dimExp = new IfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0); this.storage.Add(dimExp.Id, dimExp); var du = new IfcConversionBasedUnit(dimExp, IfcUnitEnum.PLANEANGLEUNIT, "DEGREE", measure); this.storage.Add(du.Id, du); var degree = new IfcUnit(du); var units = new List <IfcUnit> { lengthUnit, areaUnit, volumeUnit, solidAngleUnit, massUnit, timeUnit, thermUnit, lumUnit, planeAngleUnit, degree }; var unitAss = new IfcUnitAssignment(units); this.storage.Add(unitAss.Id, unitAss); // Create the project. var proj = new IfcProject(IfcGuid.ToIfcGuid(Guid.NewGuid()), history, name, description, null, null, null, null, unitAss); this.storage.Add(proj.Id, proj); }
/// <summary> /// Sets up the default units as SI /// Creates the GeometricRepresentationContext for a Model view, required by Ifc compliance /// </summary> /// <param name = "ifcProject"></param> public static void Initialize(this IfcProject ifcProject, ProjectUnits units) { IModel model = ifcProject.ModelOf; if (units == ProjectUnits.SIUnitsUK) { IfcUnitAssignment ua = model.Instances.New <IfcUnitAssignment>(); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.LENGTHUNIT; s.Name = IfcSIUnitName.METRE; s.Prefix = IfcSIPrefix.MILLI; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.AREAUNIT; s.Name = IfcSIUnitName.SQUARE_METRE; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.VOLUMEUNIT; s.Name = IfcSIUnitName.CUBIC_METRE; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.SOLIDANGLEUNIT; s.Name = IfcSIUnitName.STERADIAN; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.PLANEANGLEUNIT; s.Name = IfcSIUnitName.RADIAN; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.MASSUNIT; s.Name = IfcSIUnitName.GRAM; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.TIMEUNIT; s.Name = IfcSIUnitName.SECOND; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT; s.Name = IfcSIUnitName.DEGREE_CELSIUS; })); ua.Units.Add(model.Instances.New <IfcSIUnit>(s => { s.UnitType = IfcUnitEnum.LUMINOUSINTENSITYUNIT; s.Name = IfcSIUnitName.LUMEN; })); ifcProject.UnitsInContext = ua; } //Create the Mandatory Model View if (ModelContext(ifcProject) == null) { IfcCartesianPoint origin = model.Instances.New <IfcCartesianPoint>(p => p.SetXYZ(0, 0, 0)); IfcAxis2Placement3D axis3D = model.Instances.New <IfcAxis2Placement3D>(a => a.Location = origin); IfcGeometricRepresentationContext gc = model.Instances.New <IfcGeometricRepresentationContext>(c => { c. ContextType = "Model"; c. ContextIdentifier = "Building Model"; c. CoordinateSpaceDimension = 3; c.Precision = 0.00001; c. WorldCoordinateSystem = axis3D; } ); ifcProject.RepresentationContexts.Add(gc); IfcCartesianPoint origin2D = model.Instances.New <IfcCartesianPoint>(p => p.SetXY(0, 0)); IfcAxis2Placement2D axis2D = model.Instances.New <IfcAxis2Placement2D>(a => a.Location = origin2D); IfcGeometricRepresentationContext pc = model.Instances.New <IfcGeometricRepresentationContext>(c => { c. ContextType = "Plan"; c. ContextIdentifier = "Building Plan View"; c. CoordinateSpaceDimension = 2; c.Precision = 0.00001; c. WorldCoordinateSystem = axis2D; } ); ifcProject.RepresentationContexts.Add(pc); } }