static void Main(string[] args) //Example as requested at http://forums.autodesk.com/t5/revit-api/opensource-api-for-reading-ifc-files/m-p/6435644#M17340 { DirectoryInfo di = Directory.GetParent(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)); di = Directory.GetParent(di.FullName); string filename = Path.Combine(di.FullName, "IFC Model.ifc"); DatabaseIfc db = new DatabaseIfc(filename); IfcProject project = db.Project; List <IfcBuildingElement> elements = project.Extract <IfcBuildingElement>(); Dictionary <string, MyElement> dictionary = new Dictionary <string, MyElement>(); foreach (IfcBuildingElement element in elements) { string desc = (element as IfcColumn != null ? "COL" : (element as IfcBeam != null ? "BEAM" : "")); string mark = element.Tag; if (!string.IsNullOrEmpty(desc)) { if (dictionary.ContainsKey(mark)) { dictionary[mark].mQuantity++; } else { string grade = ""; double length = 0; foreach (IfcRelDefinesByProperties rdp in element.IsDefinedBy) { IfcPropertySet pset = rdp.RelatingPropertyDefinition as IfcPropertySet; if (pset == null) { continue; } foreach (var property in pset.HasProperties) { IfcPropertySingleValue psv = property as IfcPropertySingleValue; if (psv == null) { continue; } if (string.Compare("Grade", psv.Name) == 0) { grade = psv.NominalValue.Value.ToString(); } else if (string.Compare("Length", psv.Name) == 0) { IfcLengthMeasure lengthmeasure = psv.NominalValue as IfcLengthMeasure; if (lengthmeasure != null) { length = lengthmeasure.Measure; } } } } dictionary.Add(mark, new MyElement(mark, desc, element.ObjectType, grade, length)); } } } Console.WriteLine("Mark\tDescription\tSection\tGrade\tLength\tQty"); foreach (MyElement element in dictionary.ToList().ConvertAll(x => x.Value).OrderBy(x => x.mMark)) { Console.WriteLine(element.mMark + "\t" + element.mDescription + "\t" + element.mSection + "\t" + element.mGrade + "\t" + element.mLength + "\t" + element.mQuantity); } }
internal FactoryIfc(DatabaseIfc db) { mDatabase = db; }
static void Main(string[] args) { // create database var database = new DatabaseIfc(ModelView.Ifc4X3NotAssigned); // create IfcSite instance var site = new IfcSite(database, "sampleSite"); // create top-most spatial structure element IfcProject, set units and assign facility to project var project = new IfcProject(site, "myProject", IfcUnitAssignment.Length.Metre); // -- create facility representing the logical unit of road-bridge-road -- var trafficFacility = new IfcFacility(site, "TrafficWayA") { CompositionType = IfcElementCompositionEnum.COMPLEX }; // create parts/child-facilities and assign them to the traffic way var facilityPart1 = new IfcFacilityPart( trafficFacility, "myRoadPart01", new IfcFacilityPartTypeSelect( IfcRoadPartTypeEnum.ROADSEGMENT), IfcFacilityUsageEnum.LONGITUDINAL); facilityPart1.Description = "TrafficWayA -> Segment 1"; var facilityPart2 = new IfcFacility(trafficFacility, "myBridge") { Description = "TrafficWayA -> Segment 2" }; var facilityPart3 = new IfcFacilityPart( trafficFacility, "myRoadPart02", new IfcFacilityPartTypeSelect( IfcRoadPartTypeEnum.ROADSEGMENT), IfcFacilityUsageEnum.LONGITUDINAL) { Description = "TrafficWayA -> Segment 3" }; // -- river facility -- var river = new IfcFacility(site, "River") { CompositionType = IfcElementCompositionEnum.NOTDEFINED }; // add a part to the river var riverPart = new IfcFacilityPart( river, "myRiver", new IfcFacilityPartTypeSelect( IfcMarinePartTypeEnum.WATERFIELD), IfcFacilityUsageEnum.LONGITUDINAL) { Description = "River that passes under the bridge" }; // store the IFC model database.WriteFile("IFC4X3RC1_spatialDecomposition.ifc"); }