If you're reading this, we've just migrated servers! If anything looks broken please email dion@thinkmoult.com :)

add some general method create_ifc_file()

edited April 2023 in General

In a lot of cases I need some ifcfile framework add some product with geometry add it to the spatial structure and write the ifc.

AFAIK there is not ifcfile framework ready to use. For creating nurbs ifc out of a brep I used this script https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/scripts/obj2ifc.py no changes where made to create_ifc_file() My version can be found here: https://github.com/berndhahnebach/IfcOpenShell/blob/03962eb58c3b9e561b4a21d5b7b18675b42d3e05/src/blenderbim/scripts/brep2ifc.py
This file https://github.com/berndhahnebach/IfcOpenShell/blob/brep2ifc/src/blenderbim/scripts/dxf2ifc.py has a similar method create_ifc_file() as well.

How about adding some general method create_ifc_file() which is ready to add products too? For scripting this would be very handy to import such a method from ifcopenshell.

I would even help with this, but have no idea where to put this.

cheers bernd

Comments

  • Doesn't this already exist? See ifcopenshell.template?

  • how do I use this?

  • ifcopenshell.template.create(...)

  • edited April 2023

    Has this been added recently?

    >>> 
    >>> import ifcopenshell
    >>> ifcopenshell.template
    Traceback (most recent call last):
      File "<input>", line 1, in <module>
    AttributeError: module 'ifcopenshell' has no attribute 'template'. Did you mean: 'tempfile'?
    >>> 
    

    I need to update IfcOpenShell ...

  • It's been there for a while now.

    >>> import ifcopenshell
    >>> import ifcopenshell.template
    >>> ifcopenshell.template.create(
    create( filename=None, timestring=None, organization=None, creator=None, schema_identifier=None, application_version=None, timestamp=None, application=None, project_globalid=None, project_name=None, )
    >>> ifcopenshell.template.create()
    <ifcopenshell.file.file object at 0x7f0a721329b0>
    
    cvillagrasa
  • ok my fault ... seams exactly what I need ... :-)

    import ifcopenshell
    import ifcopenshell.template
    help(ifcopenshell.template.create)
    ifcopenshell.template.create()
    
    
    >>> 
    >>> import ifcopenshell
    >>> import ifcopenshell.template
    >>> help(ifcopenshell.template.create)
    Help on function create in module ifcopenshell.template:
    
    create(filename=None, timestring=None, organization=None, creator=None, schema_identifier=None, application_version=None, timestamp=None, application=None, project_globalid=None, project_name=None)
    
    >>> ifcopenshell.template.create()
    <ifcopenshell.file.file object at 0x000001D93BE2C700>
    >>> 
    
  • edited April 2023

    This is what has worked for me. Any review, comments and suggestions will be greatly appreciated.

    import ifcopenshell
    import ifcopenshell.api
    import ifcopenshell.geom
    import ifcopenshell.template
    
    # create base ifcfile
    # help(ifcopenshell.template.create)
    ifcfile=ifcopenshell.template.create()
    
    
    # spatial structure
    project = ifcfile.by_type("IfcProject")[0]
    site = ifcopenshell.api.run("root.create_entity", ifcfile, ifc_class="IfcSite", name="My Site")
    building = ifcopenshell.api.run("root.create_entity", ifcfile, ifc_class="IfcBuilding", name="My Building")
    storey = ifcopenshell.api.run(
        "root.create_entity", ifcfile, ifc_class="IfcBuildingStorey", name="My Storey"
    )
    ifcopenshell.api.run("aggregate.assign_object", ifcfile, product=site, relating_object=project)
    ifcopenshell.api.run("aggregate.assign_object", ifcfile, product=building, relating_object=site)
    ifcopenshell.api.run("aggregate.assign_object", ifcfile, product=storey, relating_object=building)
    ifcopenshell.api.run("geometry.edit_object_placement", ifcfile, product=site)
    ifcopenshell.api.run("geometry.edit_object_placement", ifcfile, product=building)
    ifcopenshell.api.run("geometry.edit_object_placement", ifcfile, product=storey)
    
    
    # miscellaneous
    origin = ifcfile.createIfcAxis2Placement3D(
        ifcfile.createIfcCartesianPoint((0.0, 0.0, 0.0)),
        ifcfile.createIfcDirection((0.0, 0.0, 1.0)),
        ifcfile.createIfcDirection((1.0, 0.0, 0.0)),
    )
    placement = ifcfile.createIfcLocalPlacement(storey.ObjectPlacement, origin)
    history = ifcopenshell.api.run("owner.create_owner_history", ifcfile)
    
    
    # get the geometry
    abrep_file = open("C:/Users/BHA/Desktop/some_geom_scaled.brep", "r")
    brep_data = abrep_file.read()
    abrep_file.close()
    proddefshape = ifcopenshell.geom.serialise("IFC4", brep_data)
    
    
    # add product
    product = ifcfile.create_entity(
        "IfcBuildingElementProxy",
        GlobalId=ifcopenshell.guid.new(),
        Name="My Building Element",
        Representation=proddefshape,
    )
    ifcopenshell.api.run(
        "spatial.assign_container",
        ifcfile,
        product=product,
        relating_structure=ifcfile.by_type("IfcBuildingStorey")[0]
    )
    product.ObjectPlacement = placement
    
    
    # write
    ifcfile.write("C:/Users/BHA/Desktop/mycy2.ifc")
    
    Martin156131
  • edited April 2023

    How about a method to create a minimalisc spatial strucutre in a existing ifcfile object which has no spatial structure?

    Or is it like many cases for me ... there is something in IfcOS already, but I just do not know about ...

  • @bernd sure, I think it's a great idea to add that to ifcopenshell.template (not as part of the create function, but as a separate create_spatial_structure function perhaps).

  • For sure it has to be a separate method and not a template option. This is useful for exist files as well.
    where in ifcos should such method be added?

  • In the ifcopenshell.template module, I would imagine.

  • ifcopenshell.template was added before the HL API was provided. I think it maybe also make sense to better integrate them. Maybe both (empty template and basic spatial structure) should be API calls instead. But regardless of which approach, any effort towards making basic setup less tedious is very helpful.

Sign In or Register to comment.