GeometryGym / GeometryGymIFCExamples

Examples to demonstrate use of https://github.com/jmirtsch/GeometryGymIFC classes
MIT License
60 stars 34 forks source link

Not able to write IFC4x3 elements #18

Open cesarecaoduro opened 2 years ago

cesarecaoduro commented 2 years ago

I thought I would open an issue here to seek for help. I am trying to programmatically build a bridge with all the parts, and write to a proper IFC4x3. It seems I am missing something to add the object to the db with the results that I can't see anything if I try to import the IFC back into Rhino.

I have succeeded in doing it using GH, but I can't match the same process in C#. --> Link to repo

using GeometryGym.Ifc;

var db = new DatabaseIfc(ReleaseVersion.IFC4X3_RC4);
var site = new IfcSite(db, "MySite")
{
    Description = "Just another site",
};

var facility = new IfcFacility(db, "MyFacility");

var bridge = new IfcBridge(db)
{
    Name = "MyBridge",
    Description = "Just another bridge"
};

var project = new IfcProject(site, "MyProject", IfcUnitAssignment.Length.Metre);
{
};

var foundations = new IfcFacilityPart(
    bridge,
    "Foundations",
    new IfcFacilityPartTypeSelect(IfcFacilityPartCommonTypeEnum.BELOWGROUND),
    IfcFacilityUsageEnum.NOTDEFINED
    );

var name = "Pile Cap";
var length = 1.2;
var width = 1.2;
var depth = 2.4;

IfcMaterial material = new IfcMaterial(db, "Concrete")
{
};

IfcFootingType footingType = new IfcFootingType(db, name, IfcFootingTypeEnum.PAD_FOOTING)
{
    MaterialSelect = material,
};

IfcRectangleHollowProfileDef rect = new IfcRectangleHollowProfileDef(db, name, length, width, depth);
IfcExtrudedAreaSolid extrusion = new IfcExtrudedAreaSolid(rect, new IfcAxis2Placement3D(new IfcCartesianPoint(db, 0, 0, 0)), new IfcDirection(db, 0, 0, 1), depth);

IfcProductDefinitionShape productRep = new IfcProductDefinitionShape(new IfcShapeRepresentation(extrusion));
IfcShapeRepresentation shapeRep = new(extrusion);

footingType.RepresentationMaps.Add(
    new IfcRepresentationMap(
        db.Factory.XYPlanePlacement,
        shapeRep
    )
);

IfcFooting footing = new(
    foundations,
    null,
    productRep
    )
{
    PredefinedType = IfcFootingTypeEnum.PAD_FOOTING,
    ObjectType = name
};

db.WriteFile(Path.Combine("IFC4X3RC4_testBridge.ifc"));

Any help?

jmirtsch commented 2 years ago

Thanks for the sharing the code, I made a pull request (you can ignore it). The is a spatial hiearachy to an IFC file. There an IfcProject as a root entry, and then it uses an IfcRelAggregates to the root element (usually an IfcSite or IfcFacility)

Any sub element (spatial or not) should use a constructor with it's host nominated. Then your generated IFC file works for me. 220718 import test writer

Let me know if it's not clear, I'm going to add some more overloaded constructors so you don't have use nominate null for placement or shape representation of the facility objects.