xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
485 stars 172 forks source link

How to create an element along a path using an arbitrary profile? #507

Open SerafinaM opened 1 year ago

SerafinaM commented 1 year ago

I attempted to generate a solid object by following a designated path while utilizing a profile of my choosing. The build completed successfully without any errors. But I am unable to open the ifc file that was created. image This is the code I used:

private static IfcFixedReferenceSweptAreaSolid CreateWindowBody1(IfcStore model, double height, double width){
         double ext_width = 50;
         double ext_thick = 30;
    var pointList_frame = model.Instances.New<IfcCartesianPointList3D>(pl =>
    {
        pl.CoordList.GetAt(0).AddRange(new IfcLengthMeasure[] { 0, 0, 0 });
        pl.CoordList.GetAt(1).AddRange(new IfcLengthMeasure[] { 0, ext_thick, 0 });
        pl.CoordList.GetAt(2).AddRange(new IfcLengthMeasure[] { ext_width, ext_thick, 0 });
        pl.CoordList.GetAt(3).AddRange(new IfcLengthMeasure[] { ext_width, 0, 0 });
    });
        var arbitraryProf = model.Instances.New<IfcArbitraryProfileDefWithVoids>();
    var frameCurve = model.Instances.New<IfcIndexedPolyCurve>();
    frameCurve.Points = pointList_frame;

    arbitraryProf.OuterCurve = frameCurve;
         // Create a new IfcFixedReferenceSweptAreaSolid instance
    var fixedReferenceSweptAreaSolid = model.Instances.New<IfcFixedReferenceSweptAreaSolid>();
         // Create the swept path (line)
    var line = model.Instances.New<IfcPolyline>();
    line.Points.Add(model.Instances.New<IfcCartesianPoint>(p => p.SetXYZ(0, 0, 0))); 
    line.Points.Add(model.Instances.New<IfcCartesianPoint>(p => p.SetXYZ(0, 0, 1500)));
    line.Points.Add(model.Instances.New<IfcCartesianPoint>(p => p.SetXYZ(0, 500, 1500)));
    line.Points.Add(model.Instances.New<IfcCartesianPoint>(p => p.SetXYZ(0, 500, 0)));
        // Set the swept area and path for the FixedReferenceSweptAreaSolid
    fixedReferenceSweptAreaSolid.Directrix = line;
    fixedReferenceSweptAreaSolid.SweptArea = rectangleProfileDef;
        return fixedReferenceSweptAreaSolid;
}

I added ifc file that was created. Thanks in advance. TestElement.txt

martin1cerny commented 1 year ago

You create IFCARBITRARYPROFILEDEFWITHVOIDS, but then you actually don't assign it anywhere. More importantly, every profile needs to be 2D. The rule is defined in the schema:

WHERE
  WR1 : OuterCurve.Dim = 2;

Just leave out the Z coordinate from the point list:

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