private IfcStair CreateIfcStair(IfcStore model, Stair stair) { //begin a transaction using (var trans = model.BeginTransaction("Create Stair")) { IfcStair stairToCreate = model.Instances.New <IfcStair>(); stairToCreate.Name = " stair - Wall:UC305x305x97:" + 1500; IfcDirection extrusionDir = model.Instances.New <IfcDirection>(); extrusionDir.SetXYZ(0, 0, -1); //Create a Definition shape to hold the geometry of the Stair 3D body IfcShapeRepresentation shape = IFCHelper.ShapeRepresentationCreate(model, "SweptSolid", "Body"); for (int i = 0; i < stair.LstStep.Count; i++) { IfcArbitraryClosedProfileDef stepProfile = IFCHelper.ArbitraryClosedProfileCreate(model, (stair.LstStep[i].Vertices /*.Select(v => v * 1000)*/).ToList()); IfcExtrudedAreaSolid body = IFCHelper.ProfileSweptSolidCreate(model, stair.Thickness, stepProfile, extrusionDir); body.BodyPlacementSet(model, 0, 0, stair.IsUp ? stair.Thickness * i : stair.Thickness * -i); shape.Items.Add(body); } //Create a Product Definition and add the model geometry to the wall IfcProductDefinitionShape prDefShape = model.Instances.New <IfcProductDefinitionShape>(); prDefShape.Representations.Add(shape); IfcStairFlight flight = model.Instances.New <IfcStairFlight>(); flight.Representation = prDefShape; IfcRelAggregates relAggregate = model.Instances.New <IfcRelAggregates>(); relAggregate.RelatingObject = stairToCreate; relAggregate.RelatedObjects.Add(flight); //Create Local axes system and assign it to the column IfcCartesianPoint location3D = model.Instances.New <IfcCartesianPoint>(); location3D.SetXYZ(0, 0, 0); //var uvColLongDir = MathHelper.UnitVectorPtFromPt1ToPt2(cadSlab.CenterPt, cadSlab.PtLengthDir); IfcDirection localXDir = model.Instances.New <IfcDirection>(); localXDir.SetXYZ(1, 0, 0); IfcDirection localZDir = model.Instances.New <IfcDirection>(); localZDir.SetXYZ(0, 0, 1); IfcAxis2Placement3D ax3D = IFCHelper.LocalAxesSystemCreate(model, location3D, localXDir, localZDir); //now place the slab into the model IfcLocalPlacement lp = IFCHelper.LocalPlacemetCreate(model, ax3D); flight.ObjectPlacement = lp; trans.Commit(); return(stairToCreate); } }
public XbimCreateBuilding(Building cadBuilding, string pathToSave) { using (var model = CreateandInitModel("Demo1")) { List <IFloor> lstSortedFloors = cadBuilding.Floors.OrderByDescending(f => f.Level).ToList(); if (model != null) { IfcBuilding building = CreateBuilding(model, "Default Building"); for (int i = 0; i < lstSortedFloors.Count; i++) { Floor floor = lstSortedFloors[i] as Floor; if (floor != null) { if (i + 1 == lstSortedFloors.Count) { break; } double lvlDifference = lstSortedFloors[i].Level - lstSortedFloors[i + 1].Level; double wallHeight = lvlDifference - floor.Slabs[0].Thickness; foreach (Wall cadWall in floor.Walls) { IfcWallStandardCase wall = CreateIfcWall(model, cadWall, wallHeight); if (wall != null) { AddPropertiesToWall(model, wall); } using (var txn = model.BeginTransaction("Add Wall")) { building.AddElement(wall); txn.Commit(); } } foreach (RectColumn cadCol in floor.Columns) { IfcColumn column = CreateIfcColumn(model, cadCol, lvlDifference); using (var txn = model.BeginTransaction("Add column")) { building.AddElement(column); txn.Commit(); } } foreach (Slab cadSlab in floor.Slabs) { slab = CreateIfcSlab(model, cadSlab); using (var trans = model.BeginTransaction("Add Slab")) { building.AddElement(slab); trans.Commit(); } } IfcOpeningElement opening = null; foreach (var cadOpening in floor.Openings) { opening = CreateIfcOpening(model, cadOpening, floor.Slabs[0].Thickness); using (var trans = model.BeginTransaction("Add Opening")) { building.AddElement(opening); //attach opening slab.AttchOpening(model, opening); trans.Commit(); } } //Create stairs foreach (Stair cadStair in floor.Stairs) { IfcStair stair = CreateIfcStair(model, cadStair); using (var txn = model.BeginTransaction("Add Stair")) { building.AddElement(stair); txn.Commit(); } } foreach (LinearPath cadLanding in floor.Landings) { IfcSlab landing = CreateIfcLanding(model, cadLanding, DefaultValues.SlabThinkess); using (var txn = model.BeginTransaction("Add Landing")) { building.AddElement(landing); txn.Commit(); } } } else { Foundation foundation = lstSortedFloors[i] as Foundation; foreach (PCRectFooting cadFooting in foundation.PCFooting) { IfcFooting footing = CreateIfcFooting(model, cadFooting); using (var txn = model.BeginTransaction("Add Footing")) { building.AddElement(footing); txn.Commit(); } } foreach (RCRectFooting cadFooting in foundation.RCFooting) { IfcFooting footing = CreateIfcFooting(model, cadFooting); using (var txn = model.BeginTransaction("Add Footing")) { building.AddElement(footing); txn.Commit(); } } foreach (SlopedSlab cadRamp in foundation.Ramps) { IfcSlab ramp = CreateIfcSlopedSlab(model, cadRamp); using (var txn = model.BeginTransaction("Add Ramp")) { building.AddElement(ramp); txn.Commit(); } } } } try { Console.WriteLine("Standard Wall successfully created...."); //write the Ifc File model.SaveAs(pathToSave + @"\Demo1.ifc", IfcStorageType.Ifc); Console.WriteLine("WallIfc4.ifc has been successfully written"); } catch (Exception e) { Console.WriteLine("Failed to save!"); Console.WriteLine(e.Message); } } } }