Python converter from IFC SPF to JSON
- ifcopenshell (using conda or in folder ./ifcopenshell)
- Download the Conda installer for your OS setup. https://docs.conda.io/en/latest/miniconda.html
- After installing Conda, create an environment for IFC.JSON with:
conda create --name ifcjson
- Then activate the new environment:
conda activate ifcjson
- Install ifcopenshell from conda-forge:
conda install -c conda-forge ifcopenshell
Download a recent copy of ifcopenshell from: https://builds.ifcopenshell.org/
python ifc2json.py -i model.ifc -o model_-_ifcjson4.json -v 4
optional arguments:
-h, --help show this help message and exit
-i I input ifc file path
-o O output json file path
-v V IFC.JSON version, options: "4"(default), "5a"
-
The roundtrip tests and the conversion from IFC.JSON to IFC SPF require the
pandas
library. -
By default, the import of
to_ifcopenshell
is commented out infile_converters/ifcjson/__init__.py
to avoid makingpandas
a minimal dependency. -
If you need this functionality, install pandas and uncomment the relevant line in
__init__.py
:# from .to_ifcopenshell import JSON2IFC
Change to:
from .to_ifcopenshell import JSON2IFC
-
Install pandas with:
pip install pandas
This keeps the minimal install lightweight for users who only need IFC → JSON conversion.
A test converting a set of sample files is provided to verify the roundtrip conversion from IFC to JSON and back.
This test will process all .ifc
files in samples/input/
, write results to samples/output/
, and check the validity of the conversion.
To run the test, use the following command from your project root:
python -m unittest file_converters/tests/test_samples.py
- Output files will be written to
samples/output/
and can be committed to version control for reference. - The test checks for required keys and schema version in the generated JSON files.
- Make sure your input files are placed in
samples/input/
.