public bool SerializeTest(string ifcFullName) { if (String.IsNullOrEmpty(ifcFullName)) { throw new ArgumentNullException("ifcFullName", "SerializeTest()"); return(false); } System.IO.FileInfo fileInfo = new System.IO.FileInfo(ifcFullName); if (!fileInfo.Exists) { RaiseMessageLogged(String.Format("{0} - File '{0}' not found!", "SerializeTest()", ifcFullName)); return(false); } try { string f0_Org = fileInfo.FullName; string f0 = System.IO.Path.ChangeExtension(f0_Org, ".tmp" + fileInfo.Extension); // bool validate = this.Validate(f0_Org); System.IO.File.Copy(f0_Org, f0, true); Ifc4.Document document = Ifc4.Workspace.CurrentWorkspace.OpenDocument(f0); Ifc4.IfcXML ifcXML = document.IfcXmlDocument; document.SaveAs(f0 + ".0", new SaveOptions()); //Correction(f0 + ".0"); //validate = this.Validate(f0 + ".0"); RaiseMessageLogged(String.Format("Serialized file '{0}'", f0 + ".0")); RaiseMessageLogged("End"); return(true); } catch (Exception exc) { System.Diagnostics.Debug.WriteLine(exc.Message); Exception innerException = exc.InnerException; while (innerException != null) { RaiseMessageLogged(innerException.Message); innerException = innerException.InnerException; } return(false); } }
public bool CreateTestIfc(string ifcFullName) { Ifc4.Document document = Ifc4.Workspace.CurrentWorkspace.CreateDocument(ifcFullName, true); document.MessageLogged += document_MessageLogged; if (String.IsNullOrEmpty(ifcFullName)) { throw new ArgumentNullException("ifcFullName", "CreateTestIfc()"); return(false); } try { System.IO.File.Delete(ifcFullName); } catch { } //ifcXml.express = new string[] { }; //ifcXml.configuration = new string[] { }; document.IfcXmlDocument.Id = "ifcXML4"; document.IfcXmlDocument.Header = new UosHeader() { //<time_stamp>2013-04-17T14:34:08.5257209+02:00</time_stamp> Name = System.IO.Path.GetFileNameWithoutExtension(ifcFullName), // time_stamp = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss", System.Globalization.CultureInfo.InvariantCulture), TimeStamp = DateTime.Now, Author = System.Environment.UserName, Organization = "eTASK Service-Management GmbH", PreprocessorVersion = ".NET API etask.ifc", OriginatingSystem = ".NET API etask.ifc", Authorization = "file created with .NET API etask.ifc", Documentation = "ViewDefinition [notYetAssigned]" // version }; document.Project.UnitsInContext = new IfcUnitAssignment() { Units = new IfcUnitAssignmentUnits() { Items = new List <Entity>() { new IfcSIUnit() { Id = document.GetNextSid(), Prefix = IfcSIPrefix.Milli, Name = IfcSIUnitName.Metre, NameSpecified = true, UnitType = IfcUnitEnum.Lengthunit, UnitTypeSpecified = true }, new IfcDerivedUnit() { Elements = new IfcDerivedUnitElements() { IfcDerivedUnitElement = new List <IfcDerivedUnitElement>() { new IfcDerivedUnitElement() { Id = document.GetNextSid(), Exponent = 1, Unit = new IfcSIUnit() { Name = IfcSIUnitName.Metre, NameSpecified = true, UnitType = IfcUnitEnum.Lengthunit, UnitTypeSpecified = true } }, new IfcDerivedUnitElement() { Id = document.GetNextSid(), Exponent = -1, Unit = new IfcSIUnit() { Name = IfcSIUnitName.Second, NameSpecified = true, UnitType = IfcUnitEnum.Timeunit, UnitTypeSpecified = true } } } } }, new IfcDerivedUnit() { Id = document.GetNextSid(), UnitType = IfcDerivedUnitEnum.Volumetricflowrateunit, UnitTypeSpecified = true, Elements = new IfcDerivedUnitElements() { IfcDerivedUnitElement = new List <IfcDerivedUnitElement>() { new IfcDerivedUnitElement() { Id = document.GetNextSid(), Exponent = 3, ExponentSpecified = true, Unit = new IfcSIUnit() { Name = IfcSIUnitName.Metre, NameSpecified = true, UnitType = IfcUnitEnum.Lengthunit, UnitTypeSpecified = true }, }, new IfcDerivedUnitElement() { Id = document.GetNextSid(), Exponent = -1, ExponentSpecified = true, //Name = IfcSIUnitName.second, //NameSpecified = true, //UnitType = IfcUnitEnum.timeunit, //UnitTypeSpecified = true, Unit = new IfcConversionBasedUnit() { ConversionFactor = new IfcMeasureWithUnit() { ValueComponent = new IfcMeasureWithUnitValueComponent() { Item = new IfcTimeMeasurewrapper() { Value = 3600.0 } }, UnitComponent = new IfcMeasureWithUnitUnitComponent() { Item = new IfcSIUnit() { Name = IfcSIUnitName.Second, NameSpecified = true, UnitType = IfcUnitEnum.Timeunit, UnitTypeSpecified = true } } } } } } } } } } }; Ifc4.IfcClassification ifcClassification = document.AddNew <IfcClassification>(); //ifcClassification.id = document.GetNextSid(); ifcClassification.Edition = "Version 1.06"; ifcClassification.EditionDate = "2014-08-14T09:39:57"; ifcClassification.Name = "CAFM-Connect Katalog 2014"; Ifc4.IfcRelAssociatesClassification ifcRelAssociatesClassification = document.AddNew <IfcRelAssociatesClassification>(); //ifcRelAssociatesClassification.id = document.GetNextSid(); ifcRelAssociatesClassification.GlobalId = "1XiFKGEHP6PxQPxDU2E3PA"; ifcRelAssociatesClassification.Name = "CAFM-Connect Katalog 2014 zu IfcClassification"; ifcRelAssociatesClassification.RelatedObjects = new IfcRelAssociatesRelatedObjects() { Items = new List <IfcRoot>() { new Ifc4.IfcProject() { @Ref = document.Project.Id } } }; ifcRelAssociatesClassification.RelatingClassification = new IfcRelAssociatesClassificationRelatingClassification() { Item = new IfcClassification() { @Ref = ifcClassification.Id } }; //<IfcClassification id="i120" Edition="Version 1.06" EditionDate="2014-08-14T09:39:57" Name="CAFM-Connect Katalog 2014" /> //<IfcRelAssociatesClassification id="i121" GlobalId="1XiFKGEHP6PxQPxDU2E3PA" Name="CAFM-Connect Katalog 2014 zu IfcClassification"> // <RelatedObjects> // <IfcProject ref="i100" xsi:nil="true" /> // </RelatedObjects> // <RelatingClassification> // <IfcClassification ref="i120" xsi:nil="true" /> // </RelatingClassification> //</IfcRelAssociatesClassification> try { document.Save(new SaveOptions()); document.Close(); string message; document.Open(ifcFullName, out message); document.SaveAs(ifcFullName + ".0", new SaveOptions()); RaiseMessageLogged(this, System.IO.File.ReadAllText(document.FullName)); return(true); } catch (Exception exc) { System.Diagnostics.Debug.WriteLine(exc.Message); Exception innerException = exc.InnerException; while (innerException != null) { RaiseMessageLogged(innerException.Message); innerException = innerException.InnerException; } return(false); } }