Example #1
0
        /// <summary>
        /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case wall
        /// </summary>
        static int Main()
        {
            //first create and initialise a model called Hello Wall
            Console.WriteLine("Initialising the IFC Project....");
            using (var model = CreateandInitModel("HelloWall"))
            {
                if (model != null)
                {
                    IfcBuilding         building = CreateBuilding(model, "Default Building");
                    IfcWallStandardCase wall     = CreateWall(model, 4000, 300, 2400);

                    if (wall != null)
                    {
                        AddPropertiesToWall(model, wall);
                    }
                    using (var txn = model.BeginTransaction("Add Wall"))
                    {
                        building.AddElement(wall);
                        txn.Commit();
                    }

                    if (wall != null)
                    {
                        try
                        {
                            Console.WriteLine("Standard Wall successfully created....");
                            //write the Ifc File
                            model.SaveAs("HelloWallIfc4.ifc", IfcStorageType.Ifc);
                            Console.WriteLine("HelloWallIfc4.ifc has been successfully written");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Failed to save HelloWall.ifc");
                            Console.WriteLine(e.Message);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Failed to initialise the model");
                }
            }
            Console.WriteLine("Press any key to exit to view the IFC file....");
            Console.ReadKey();
            LaunchNotepad("HelloWallIfc4.ifc");
            return(0);
        }
Example #2
0
        /// <summary>
        /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case wall
        /// </summary>
        /// <param name="args"></param>
        public void Run()
        {
            //first create and initialise a model called Hello Wall
            Console.WriteLine("Initialising the IFC Project....");
            XbimModel model = CreateandInitModel("HelloWall");

            if (model != null)
            {
                IfcBuilding building = CreateBuilding(model, "Default Building", 2000);


                IfcWallStandardCase wall = CreateWall(model, 4000, 300, 2400);
                if (wall != null)
                {
                    AddPropertiesToWall(model, wall);
                }
                using (XbimReadWriteTransaction txn = model.BeginTransaction("Add Wall"))
                {
                    building.AddElement(wall);
                    txn.Commit();
                }

                if (wall != null)
                {
                    try
                    {
                        Console.WriteLine("Standard Wall successfully created....");
                        //write the Ifc File
                        model.SaveAs("HelloWall.ifc", XbimStorageType.IFC);
                        Console.WriteLine("HelloWall.ifc has been successfully written");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to save HelloWall.ifc");
                        Console.WriteLine(e.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine("Failed to initialise the model");
            }

            Console.WriteLine("Press any key to exit....");
            Console.ReadKey();
        }
Example #3
0
        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);
                    }
                }
            }
        }
Example #4
0
        public Ifc(List <ElementGroup> elementGroups, string projectName, string buildingName, string path)
        {
            using (IfcStore model = CreateAndInitModel(projectName))
            {
                if (model != null)
                {
                    IfcBuilding building = CreateBuilding(model, buildingName);

                    foreach (var elementGroup in elementGroups)
                    {
                        switch (elementGroup.ElementType)
                        {
                        case ElementType.PadFooting:
                        case ElementType.StripFooting:
                        case ElementType.Beam:
                        case ElementType.Column:
                        {
                            List <IfcBuildingElement> currentElementGroup = elementGroup.ToBuildingElementIfc(model);
                            foreach (var buildingElement in currentElementGroup)
                            {
                                using (var transaction = model.BeginTransaction("Add element"))
                                {
                                    building.AddElement(buildingElement);
                                    transaction.Commit();
                                }
                            }

                            break;
                        }

                        case ElementType.Rebar:
                        {
                            List <IfcReinforcingElement> currentElementGroup = elementGroup.ToReinforcingElementIfc(model);
                            foreach (var buildingElement in currentElementGroup)
                            {
                                using (var transaction = model.BeginTransaction("Add element"))
                                {
                                    building.AddElement(buildingElement);
                                    transaction.Commit();
                                }
                            }

                            break;
                        }

                        default:
                            throw new ArgumentException("Unknown element type");
                        }
                    }

                    if (path.Substring(path.Length - 4) != ".ifc")
                    {
                        throw new ArgumentException("Path should end up with .ifc");
                    }

                    try
                    {
                        model.SaveAs(path, StorageType.Ifc);
                    }
                    catch (Exception e)
                    {
                        throw new ArgumentException("Couldn't save the file. " + e);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// This creates a cube and it's geometry, many geometric representations are possible. This example uses extruded rectangular profile
        /// </summary>
        /// <param name="model"></param>
        /// <param name="size">Size of the cube</param>
        /// <returns></returns>
        static private IfcFurniture CreateCubeFurniture(IModel model, double size, IfcBuilding parent)
        {
            var i    = model.Instances;
            var cube = i.New <IfcFurniture>(c => c.Name = "The Cube");

            parent.AddElement(cube);

            // represent cube as a rectangular profile
            var rectProf = i.New <IfcRectangleProfileDef>(pr => {
                pr.ProfileType = IfcProfileTypeEnum.AREA;
                pr.XDim        = size;
                pr.YDim        = size;
                //insert at arbitrary position
                pr.Position = i.New <IfcAxis2Placement2D>(a2p => a2p.Location = i.New <IfcCartesianPoint>(p => p.SetXY(0, 400)));
            });


            // model as a swept area solid
            var body = i.New <IfcExtrudedAreaSolid>(b => {
                b.Depth             = size;
                b.SweptArea         = rectProf;
                b.ExtrudedDirection = i.New <IfcDirection>();
                b.ExtrudedDirection.SetXYZ(0, 0, 1);
                //parameters to insert the geometry in the model
                b.Position = i.New <IfcAxis2Placement3D>(p => p.Location = i.New <IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0)));
            });


            // create a Definition shape to hold the geometry
            var shape = i.New <IfcShapeRepresentation>(s => {
                s.ContextOfItems           = i.OfType <IfcGeometricRepresentationContext>().First();
                s.RepresentationType       = "SweptSolid";
                s.RepresentationIdentifier = "Body";
                s.Items.Add(body);
            });

            // create visual style
            i.New <IfcStyledItem>(styleItem =>
            {
                styleItem.Item = body;
                styleItem.Styles.Add(i.New <IfcSurfaceStyle>(style =>
                {
                    style.Side = IfcSurfaceSide.BOTH;
                    style.Styles.Add(i.New <IfcSurfaceStyleRendering>(rendering =>
                    {
                        rendering.SurfaceColour = i.New <IfcColourRgb>(colour =>
                        {
                            colour.Name  = "Orange";
                            colour.Red   = 1.0;
                            colour.Green = 0.5;
                            colour.Blue  = 0.0;
                        });
                    }));
                }));
            });

            // create a Product Definition and add the model geometry to the cube
            cube.Representation = i.New <IfcProductDefinitionShape>(r => r.Representations.Add(shape));

            // now place the cube into the model
            cube.ObjectPlacement = i.New <IfcLocalPlacement>(p => p.RelativePlacement = i.New <IfcAxis2Placement3D>(a => {
                a.Location     = i.New <IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0));
                a.RefDirection = i.New <IfcDirection>();
                a.RefDirection.SetXYZ(0, 1, 0);
                a.Axis = i.New <IfcDirection>();
                a.Axis.SetXYZ(0, 0, 1);
            }));

            // IfcPresentationLayerAssignment is required for CAD presentation
            var ifcPresentationLayerAssignment = i.New <IfcPresentationLayerAssignment>(layer => {
                layer.Name = "Furnishing Elements";
                layer.AssignedItems.Add(shape);
            });

            return(cube);
        }