private IfcFooting CreateIfcFooting(IfcStore model, FootingBase cadFooting) { //cadFooting.Length *= 1000; //cadFooting.Width *= 1000; //cadFooting.CenterPt.X *= 1000; //cadFooting.CenterPt.Y *= 1000; //cadFooting.PtLengthDir.X *= 1000; //cadFooting.PtLengthDir.Y *= 1000; // double length = cadFooting.Length; double width = cadFooting.Width; //begin a transaction using (var trans = model.BeginTransaction("Create Footing")) { IfcFooting footingToCreate = model.Instances.New <IfcFooting>(); footingToCreate.Name = " Foundation - Footing:UC305x305x97: " + random.Next(1000, 10000); //represent footing as a rectangular profile IfcRectangleProfileDef rectProf = IFCHelper.RectProfileCreate(model, length, width); //Profile Insertion Point rectProf.ProfileInsertionPointSet(model, 0, 0); //model as a swept area solid IfcDirection extrusionDir = model.Instances.New <IfcDirection>(); extrusionDir.SetXYZ(0, 0, -1); IfcExtrudedAreaSolid body = IFCHelper.ProfileSweptSolidCreate(model, cadFooting.Thickness, rectProf, extrusionDir); //parameters to insert the geometry in the model body.BodyPlacementSet(model, 0, 0, 0); //Create a Definition shape to hold the geometry IfcShapeRepresentation shape = IFCHelper.ShapeRepresentationCreate(model, "SweptSolid", "Body"); 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); footingToCreate.Representation = prDefShape; //Create Local axes system and assign it to the wall IfcCartesianPoint location3D = model.Instances.New <IfcCartesianPoint>(); location3D.SetXYZ(cadFooting.CenterPt.X, cadFooting.CenterPt.Y, cadFooting.CenterPt.Z); var uvFootingLongDir = MathHelper.UnitVectorFromPt1ToPt2(cadFooting.CenterPt, cadFooting.PtLengthDir); IfcDirection localXDir = model.Instances.New <IfcDirection>(); localXDir.SetXYZ(uvFootingLongDir.X, uvFootingLongDir.Y, uvFootingLongDir.Z); IfcDirection localZDir = model.Instances.New <IfcDirection>(); localZDir.SetXYZ(0, 0, 1); IfcAxis2Placement3D ax3D = IFCHelper.LocalAxesSystemCreate(model, location3D, localXDir, localZDir); //now place the wall into the model IfcLocalPlacement lp = IFCHelper.LocalPlacemetCreate(model, ax3D); footingToCreate.ObjectPlacement = lp; trans.Commit(); return(footingToCreate); } }
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); } } } }