'create custom IfcPolygonalFaceSet wall using xbim library

I want to create polygonfaceset wall using xbim toolkit library. Please let me know what I am doing wrong. It will be great help to me if anybody can provide sample code or some approach regarding polygonfaceset wall. Below I provide scrennshot and samplecode.

static private IfcWallStandardCase CreateWall(IfcStore model, double length, double width, double height) { // //begin a transaction using (var txn = model.BeginTransaction("Create Wall")) { var wall = model.Instances.New(); wall.Name = "A Standard rectangular wall";

            //represent wall as a rectangular profile
            var rectProf = model.Instances.New<IfcRectangleProfileDef>();
            rectProf.ProfileType = IfcProfileTypeEnum.AREA;
            rectProf.XDim = width;
            rectProf.YDim = length;

            var insertPoint = model.Instances.New<IfcCartesianPoint>();
            insertPoint.SetXY(0, 400); //insert at arbitrary position
            rectProf.Position = model.Instances.New<IfcAxis2Placement2D>();
           rectProf.Position.Location = insertPoint;


            var polyfaceset = model.Instances.New<IfcPolygonalFaceSet>();
            var coordinates2 = model.Instances.New<IfcIndexedPolygonalFace>();

            //var coordinates = model.Instances.New<IfcCartesianPointList3D>(pl => {
            //    pl.CoordList.GetAt(0).AddRange(new IfcLengthMeasure[] { 0, 0, 0 });
            //    pl.CoordList.GetAt(1).AddRange(new IfcLengthMeasure[] { 1, 0, 0 });
            //    pl.CoordList.GetAt(2).AddRange(new IfcLengthMeasure[] { 0, 1, 0 });
            //    pl.CoordList.GetAt(3).AddRange(new IfcLengthMeasure[] { 0, 0, 1 });
            //});

            polyfaceset.Closed = true;


            polyfaceset.Coordinates = model.Instances.New<IfcCartesianPointList3D>(pl => {
                pl.CoordList.GetAt(0).AddRange(new IfcLengthMeasure[] { 0, 0, 1000 });
                pl.CoordList.GetAt(1).AddRange(new IfcLengthMeasure[] { 3000, 0, 1000 });
                pl.CoordList.GetAt(2).AddRange(new IfcLengthMeasure[] { 3000, 2000, 10000 });
                pl.CoordList.GetAt(3).AddRange(new IfcLengthMeasure[] { 1000, 3000, 1000 });
                pl.CoordList.GetAt(4).AddRange(new IfcLengthMeasure[] { 0, 2000, 1000 });
            });


            //model as a swept area solid
            var body = model.Instances.New<IfcExtrudedAreaSolid>();
            body.Depth = height;
            body.SweptArea = rectProf;
            body.ExtrudedDirection = model.Instances.New<IfcDirection>();
            body.ExtrudedDirection.SetXYZ(0, 0, 1);

            //parameters to insert the geometry in the model
            var origin = model.Instances.New<IfcCartesianPoint>();
            origin.SetXYZ(0, 0, 0);
            body.Position = model.Instances.New<IfcAxis2Placement3D>();
            body.Position.Location = origin;

            //Create a Definition shape to hold the geometry
            var shape = model.Instances.New<IfcShapeRepresentation>();
            var modelContext = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
            shape.ContextOfItems = modelContext;
            shape.RepresentationType = "SweptSolid";
            shape.RepresentationIdentifier = "Body";
            shape.Items.Add(body);

            //create visual style
            model.Instances.New<IfcStyledItem> (styleItem => {
                     styleItem.Item = body;
                     styleItem.Styles.Add(model.Instances.New<IfcSurfaceStyle>(style => {
                         style.Side = IfcSurfaceSide.BOTH;
                         style.Styles.Add(model.Instances.New<IfcSurfaceStyleRendering>(rendering => {
                             rendering.SurfaceColour = model.Instances.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 wall
            var rep = model.Instances.New<IfcProductDefinitionShape>();
            rep.Representations.Add(shape);
            wall.Representation = rep;

            //now place the wall into the model
            var lp = model.Instances.New<IfcLocalPlacement>();
            var ax3D = model.Instances.New<IfcAxis2Placement3D>();
            ax3D.Location = origin;
            ax3D.RefDirection = model.Instances.New<IfcDirection>();
            ax3D.RefDirection.SetXYZ(0, 1, 0);
            ax3D.Axis = model.Instances.New<IfcDirection>();
            ax3D.Axis.SetXYZ(0, 0, 1);
            lp.RelativePlacement = ax3D;
            wall.ObjectPlacement = lp;


            // Where Clause: The IfcWallStandard relies on the provision of an IfcMaterialLayerSetUsage 
            var ifcMaterialLayerSetUsage = model.Instances.New<IfcMaterialLayerSetUsage>();
            var ifcMaterialLayerSet = model.Instances.New<IfcMaterialLayerSet>();
            var ifcMaterialLayer = model.Instances.New<IfcMaterialLayer>();
            ifcMaterialLayer.LayerThickness = 10;
            ifcMaterialLayerSet.MaterialLayers.Add(ifcMaterialLayer);
            ifcMaterialLayerSetUsage.ForLayerSet = ifcMaterialLayerSet;
            ifcMaterialLayerSetUsage.LayerSetDirection = IfcLayerSetDirectionEnum.AXIS2;
            ifcMaterialLayerSetUsage.DirectionSense = IfcDirectionSenseEnum.NEGATIVE;
            ifcMaterialLayerSetUsage.OffsetFromReferenceLine = 150;

            // Add material to wall
            var material = model.Instances.New<IfcMaterial>();
            material.Name = "some material";
            var ifcRelAssociatesMaterial = model.Instances.New<IfcRelAssociatesMaterial>();
            ifcRelAssociatesMaterial.RelatingMaterial = material;
            ifcRelAssociatesMaterial.RelatedObjects.Add(wall);

            ifcRelAssociatesMaterial.RelatingMaterial = ifcMaterialLayerSetUsage;

            // IfcPresentationLayerAssignment is required for CAD presentation in IfcWall or IfcWallStandardCase
            var ifcPresentationLayerAssignment = model.Instances.New<IfcPresentationLayerAssignment>();
            ifcPresentationLayerAssignment.Name = "some ifcPresentationLayerAssignment";
            ifcPresentationLayerAssignment.AssignedItems.Add(shape);


            // linear segment as IfcPolyline with two points is required for IfcWall
            var ifcPolyline = model.Instances.New<IfcPolyline>();
            var startPoint = model.Instances.New<IfcCartesianPoint>();
            var midpoint = model.Instances.New<IfcCartesianPoint>();
            var midpoint2 = model.Instances.New<IfcCartesianPoint>();
          
            startPoint.SetXYZ(3000, 0, 1000);
            midpoint.SetXYZ(3000, 2000, 1000);
            midpoint2.SetXYZ(1000, 3000, 1000);
            
            var endPoint = model.Instances.New<IfcCartesianPoint>();
            endPoint.SetXYZ(0, 2000, 1000);
            ifcPolyline.Points.Add(startPoint);
            ifcPolyline.Points.Add(midpoint);
            ifcPolyline.Points.Add(midpoint2);
            ifcPolyline.Points.Add(endPoint);

            var shape2D = model.Instances.New<IfcShapeRepresentation>();
            shape2D.ContextOfItems = modelContext;
            shape2D.RepresentationIdentifier = "Axis";
            shape2D.RepresentationType = "Curve2D";
            shape2D.Items.Add(ifcPolyline);
            rep.Representations.Add(shape2D);
            txn.Commit();
            return wall;
        }
        
    }

This CreateWall function create Ifc wall. Please go throw it above code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source