[IfcOpenShell-Python] How to calculate a volume from an ifc entity?

Hi all

I am searching for a method to calculate with IfcOpenShell-Python for an ifc enitiy like IfcWall the volume directly from its Representation (Geometry).

The problem is, my ifc modell don't have any IfcQuantitySet. So it would be nice to calculate the volume and then create an IfcQuantitySet with IfcQuantityVolume.

I didn't find anything here in the forum or in https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples.

Comments

  • If the object is in Blender, there is existing code there. Outside Blender, if you have access to PythonOCC, you can use that. In pure IfcOpenShell it's not yet available in Python https://github.com/IfcOpenShell/IfcOpenShell/issues/1040

    AceMartin156131
  • edited September 24

    So i wanted to use PythonOCC, however the last commit in that github page was 2018. So I searched for another way.

    Somehow I stumbled on the Part module in FreeCAD.

    The main data structure used in the Part module is the BRep data type from OpenCASCADE.

    The main difference to PythonOCC described here:

    PythonOCC is a project that aims at providing the entire range of OpenCASCADE Technology (OCCT) functions through the Python module OCC. This is a different approach from FreeCAD's, where only certain components of OCCT are exposed through the Part Workbench.

    PythonOCC, on the other hand, provides access to all OCCT classes and functions so it is complex but also very powerful. Therefore, when you are limited by FreeCAD's OCCT functionality, using OCC is a good alternative.

    In this article it is described how install Part module in any python environment. And this article showed me that is possible to give the geometry from an ifc file to the Part module.

    So I created this little script and it calculated the volume form my test cube from the ifc file, that is attached. 🎉

    I am not sure which unit it is, though.

    @Moult You wrote also that something is already implemented in Blender -> can you also calculate the volume from the cube from the attached ifc file with blender, so we can check if both methods come to the same result 😊

    I used the weekly build from FreeCAD with Python 3.10 -> https://github.com/FreeCAD/FreeCAD-Bundle/releases/tag/weekly-builds

    I also asked in the FreeCAD forum, if it be possible install the Part Module with conda forge -> https://forum.freecadweb.org/viewtopic.php?f=8&t=72098

  • edited September 24

    I opened the ifc file in blender and did this measurement:

    So if one side from the cube is 2m -> the volume should be 2m * 2m * 2m => 8 m3

    So the way with Part module came almost to the same result. 😁

    I also did the test with the non-free commercial ifc viewer:

  • Ah yes! Using FreeCAD is a great option I hadn't considered which simplifies PythonOCC (though I'd assume vanilla PythonOCC should also make getting volumes very easy). PythonOCC is also perhaps more lightweight than FreeCAD I assume and available on Conda. It used to come with the BlenderBIM Add-on (~100mb from memory) but I removed it.

    The native Blender approach is the bmesh bm.calc_volume() function. You can find some things written here already https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/blenderbim/blenderbim/bim/module/qto/helper.py and @vpajic has been writing a lot more https://github.com/IfcOpenShell/IfcOpenShell/pull/2405

    vpajic
  • FYI Regarding PythonOCC. For the latest version you could check out https://github.com/tpaviot/pythonocc-core. The latest pythonocc-core package (released a few weeks ago) supports occt v7.6.2 which is the same version as IfcOpenShell.

    The conda packages can be found here:
    https://anaconda.org/conda-forge/pythonocc-core

  • @krande Thanks for the info. I only saw this GitHub website https://github.com/tpaviot/pythonocc (Last commit 31 Jan 2018) and this website http://www.pythonocc.org/ was also down. So i thought this project was inactive. However through your GitHub link https://github.com/tpaviot/pythonocc-core (Last commit 16 days ago), i realized that this project is not dead.

    @Moult i also think that FreeCAD is bit heavy, so i am going to try PythonOCC. When i got something together, i will write an update here :)


  • PythonOCC is fancy :)

    I did download PythonOCC with conda:

    conda install -c conda-forge pythonocc-core=7.6.2

    I did get conda with Miniforge -> in this bundle there is python, pip and conda

    krandeMoultJohannes990
Sign In or Register to comment.