Import/Export IFC - compiling IfcOpenShell: Difference between revisions

From FreeCAD Documentation
(Enable IFC format import/export, very useful for Arch workbench)
(Marked this version for translation)
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:1-->
<!--T:1-->
Line 6: Line 7:
|Time=120 minutes
|Time=120 minutes
|Author=Pablo Gil
|Author=Pablo Gil
|FCVersion=
|FCVersion=0.19.x
|Files=
|Files=
}}
}}



== Introduction == <!--T:2-->
== Introduction == <!--T:2-->
It was a such a hard investigation on how to get a working copy of IfcOpenShell-python on OSX/macOS in order to import/export IFC files that I'm sharing this tutorial in case it helps more people.
It was a such a hard investigation on how to get a working copy of IfcOpenShell-python on OSX/macOS in order to import/export IFC files that I'm sharing this tutorial in case it helps more people.
My system is OSX 10.11.6, 64bits with Python 2.7.11, it might work for you if you have also OSX as they are often 64bits but may differ from mine. The procedure might be very similar if you run Linux or Windows but it probably have some differences.
My system is OSX 10.11.6, 64bits with Python 2.7.11, it might work for you if you have also OSX as they are often 64bits but may differ from mine. The procedure might be very similar if you run Linux or Windows but it probably have some differences.

== Requirements == <!--T:26-->

<!--T:27-->
* [[IfcOpenShell]]
* FreeCAD v0.19 or higher


== Steps == <!--T:3-->
== Steps == <!--T:3-->
1. Download or clone the full GitHub project at https://github.com/IfcOpenShell/IfcOpenShell (it will always be the newest version)
1. Download or clone the full GitHub project at https://github.com/IfcOpenShell/IfcOpenShell (it will always be the newest version)
: {{incode|git clone https://github.com/IfcOpenShell/IfcOpenShell}}


<!--T:6-->
2. From a terminal go to '''/nix/''' folder and launch the script. In OSX it is ran with:
2. From a terminal go to {{FileName|/nix/}} folder and launch the script. In OSX it is executed with:
{{Code|code=
{{Code|code=
cd nix/
./build-all.sh
./build-all.sh
}}
}}
It will take from 30 up to 120 minutes to compile everything. It's not the smarter way of compiling IfcOpenShell but this simple script will compile all dependencies, Python versions, etc.
It will take from 30 up to 120 minutes to compile everything. It's not the smarter way of compiling [[IfcOpenShell]] but this simple script will compile all dependencies, Python versions, etc.


<!--T:7-->
3. Once it finishes (I don't remember now but it will be printed something like "Built IfcOpenShell..." and it will return to your prompt) you will have a new folder '''/IfcOpenShell/build/''' full of files and folders. From my personal experience, two weeks ago the nix "build-all.sh" script didn't finished successfully but after trying it yesterday with the newest updates it worked fine so I guess you might experience something similar in case the development goes further...
3. Once it finishes (I don't remember now but it will be printed something like "Built IfcOpenShell..." and it will return to your prompt) you will have a new folder {{FileName|/IfcOpenShell/build/}} full of files and folders. From my personal experience, two weeks ago the nix "build-all.sh" script didn't finished successfully but after trying it yesterday with the newest updates it worked fine so I guess you might experience something similar in case the development goes further...
So now you have everything you need but you have to do some manual work in order to get it working:
So now you have everything you need but you have to do some manual work in order to get it working:

4. Open FreeCAD and open the Python console and Report view. Then write into the Python console the following:
<!--T:25-->
4. Open FreeCAD and open the [[Python console]] and [[Report view]]. Then write into the Python console the following:
{{Code|code=
{{Code|code=
import sys
import sys
print sys.path
print sys.path
}}
}}
You will get a looong line with all the paths that FreeCAD reads. You may be able to install ifcopenshell in any of them but I suggest you to place it inside one where you find a '''/site-packages/''' after a '''/Python/''' or '''/python-something/'''. In my case it was */Library/Python/2.7/site-packages*. (you will find paths inside your app directory but I suggest you to not use them because then IfcOpenShell will only be available for this app)
You will get a looooong line with all the paths that FreeCAD reads. You may be able to install IfcOpenShell in any of them but I suggest you to place it inside one where you find a {{FileName|/site-packages/}} after a {{FileName|/Python/}} or {{FileName|/python-something/}}. In my case it was {{FileName|/Library/Python/2.7/site-packages}}. (Note: you will find paths inside your app directory but I suggest you to not use them because then IfcOpenShell will only be available for this app)


<!--T:8-->
5. So, once located where you want/have to install it, go there with your file browser (Finder in OSX). That is, go inside '''/site-packages/''' folder
5. Once located where you want/have to install it, go there with your file browser (Finder in OSX). That is, go inside {{FileName|/site-packages/}} folder
: {{incode|cd site-packages/}}


<!--T:9-->
6. Open a new file browser window and navigate to your downloaded GitHub project: '''/IfcOpenShell/src/ifcopenshell-python/''' and copy the full '''/ifcopenshell/''' folder
6. Open a new file browser window and navigate to your downloaded GitHub project: '''/IfcOpenShell/src/ifcopenshell-python/''' and copy the full '''/ifcopenshell/''' folder


<!--T:10-->
7. Paste it inside '''/site-packages/''' folder. Now you should have something like:
7. Paste it inside '''/site-packages/''' folder. Now you should have something like:
{{Code|code=
{{Code|code=
Line 49: Line 65:
}}
}}


<!--T:11-->
8. Now we have to pick to files inside the /build/ folder, they are:
8. Now we have to pick to files inside the /build/ folder, they are:
{{Code|code=
{{Code|code=
Line 54: Line 71:
ifcopenshell_wrapper.py
ifcopenshell_wrapper.py
}}
}}
but as we have compiled everything you will have to pick the one that matches with your FreeCAD Python version. Check it easily reading the first line inside your FreeCAD Python console view. In my case it was Python 2.7.11.
but as we have compiled everything you will have to pick the one that matches with your FreeCAD Python version. Check it easily reading the first line inside your FreeCAD [[Python console]] view. In my case it was Python 2.7.11.


<!--T:12-->
9. Now go let's copy the files inside the place it corresponds to your Python version. In my case it was:
9. Now go let's copy the files inside the place it corresponds to your Python version. In my case it was:
{{Code|code=
{{Code|code=
Line 61: Line 79:
}}
}}


<!--T:13-->
10. Paste them inside /site-packages/ifcopenshell/
10. Paste them inside {{FileName|/site-packages/ifcopenshell/}}


<!--T:14-->
11. Check everything is in place:
11. Check everything is in place:
{{Code|code=
{{Code|code=
Line 75: Line 95:
/site-packages/ifcopenshell/guid.py (1)
/site-packages/ifcopenshell/guid.py (1)
/site-packages/ifcopenshell/ifcopenshell_wrapper.py (2)
/site-packages/ifcopenshell/ifcopenshell_wrapper.py (2)
}}


<!--T:15-->
(1) from GitHub project
(1) from GitHub project <br />
(2) from /build/ folder
(2) from /build/ folder
}}


12. Close and reopen FreeCAD and test if everything is working:


<!--T:16-->
12. Close and reopen FreeCAD

== Testing == <!--T:4-->
Now that it is installed, let's check if everything works as expected:

<!--T:17-->
12.1 in the Python console write:
12.1 in the Python console write:
{{Code|code=
{{Code|code=
Line 89: Line 116:
if it doesn't throw any error it means it may be correctly installed
if it doesn't throw any error it means it may be correctly installed


<!--T:18-->
12.2 Go to Yorik's FreeCAD manual, navigate to the lower part of the page and download the following files to test:
12.2 Go to Yorik's FreeCAD manual, navigate to the lower part of the page and download the following files to test:
{{Code|code=
{{Code|code=
Line 95: Line 123:
}}
}}


<!--T:19-->
12.3 Open '''house.FCStd''', select the root "Building" object and export it (menu File/export/) setting the File type to "Industry Foundation Classes (*.ifc)". Press "save" and if it works and it doesn't throw an error in the Report view then it's working
12.3 Open {{FileName|house.FCStd}}, select the root "Building" object and export it ({{MenuCommand|File → Export}}) setting the File type to "Industry Foundation Classes (*.ifc)". Press {{Button|Save}} and if it works and it doesn't throw an error in the [[Report view]] then it's working.


<!--T:20-->
12.4 Final test, import '''house.ifc''' into a new file so open a new file and import that file... it will take a while.
12.4 Final test, import {{FileName|house.ifc}} into a new file so open a new file and import that file... it will take a while.


<!--T:21-->
13. Enjoy BIM with FreeCAD!
13. Enjoy BIM with FreeCAD!


== Introduction == <!--T:4-->
== Final thoughts == <!--T:5-->
My opinion is that FreeCAD itself should have precompiled versions of IfcOpenShell bundled with the distribution because building it by yourself is a total pain and average user won't do it (they don't know how to compile, manage GitHub, etc), but well, maybe in the future.
My opinion is that FreeCAD itself should have precompiled versions of IfcOpenShell bundled with the distribution because building it by yourself is a total pain and average user won't do it (they don't know how to compile, manage GitHub, etc), but well, maybe in the future.


<!--T:22-->
I hope it helps you :)
I hope it helps you.

<!--T:23-->
Cheers
Cheers


==Links== <!--T:24-->

<!--T:28-->
* Related forum thread [http://forum.freecadweb.org/viewtopic.php?f=23&t=17536 discussion]
* [[IfcOpenShell]]


</translate>
</translate>
{{Userdocnavi{{#translation:}}}}
<languages/>
[[Category:BIM{{#translation:}}]]
[[Category:Formats{{#translation:}}]]
[[Category:Arch{{#translation:}}]]
[[Category:3rd Party{{#translation:}}]]

Revision as of 14:23, 10 October 2020

Tutorial
Topic
Arch Workbench
Level
Advanced
Time to complete
120 minutes
Authors
Pablo Gil
FreeCAD version
0.19.x
Example files
See also
None

Introduction

It was a such a hard investigation on how to get a working copy of IfcOpenShell-python on OSX/macOS in order to import/export IFC files that I'm sharing this tutorial in case it helps more people. My system is OSX 10.11.6, 64bits with Python 2.7.11, it might work for you if you have also OSX as they are often 64bits but may differ from mine. The procedure might be very similar if you run Linux or Windows but it probably have some differences.

Requirements

Steps

1. Download or clone the full GitHub project at https://github.com/IfcOpenShell/IfcOpenShell (it will always be the newest version)

git clone https://github.com/IfcOpenShell/IfcOpenShell

2. From a terminal go to /nix/ folder and launch the script. In OSX it is executed with:

cd nix/
./build-all.sh

It will take from 30 up to 120 minutes to compile everything. It's not the smarter way of compiling IfcOpenShell but this simple script will compile all dependencies, Python versions, etc.

3. Once it finishes (I don't remember now but it will be printed something like "Built IfcOpenShell..." and it will return to your prompt) you will have a new folder /IfcOpenShell/build/ full of files and folders. From my personal experience, two weeks ago the nix "build-all.sh" script didn't finished successfully but after trying it yesterday with the newest updates it worked fine so I guess you might experience something similar in case the development goes further... So now you have everything you need but you have to do some manual work in order to get it working:

4. Open FreeCAD and open the Python console and Report view. Then write into the Python console the following:

import sys
print sys.path

You will get a looooong line with all the paths that FreeCAD reads. You may be able to install IfcOpenShell in any of them but I suggest you to place it inside one where you find a /site-packages/ after a /Python/ or /python-something/. In my case it was /Library/Python/2.7/site-packages. (Note: you will find paths inside your app directory but I suggest you to not use them because then IfcOpenShell will only be available for this app)

5. Once located where you want/have to install it, go there with your file browser (Finder in OSX). That is, go inside /site-packages/ folder

cd site-packages/

6. Open a new file browser window and navigate to your downloaded GitHub project: /IfcOpenShell/src/ifcopenshell-python/ and copy the full /ifcopenshell/ folder

7. Paste it inside /site-packages/ folder. Now you should have something like:

/site-packages/ifcopenshell/__init__.py
/site-packages/ifcopenshell/entity_instance.py
/site-packages/ifcopenshell/file.py
/site-packages/ifcopenshell/geom/app.py
/site-packages/ifcopenshell/geom/main.py
/site-packages/ifcopenshell/geom/occ_utils.py
/site-packages/ifcopenshell/geom/__init__.py
/site-packages/ifcopenshell/guid.py

8. Now we have to pick to files inside the /build/ folder, they are:

_ifcopenshell_wrapper.so
ifcopenshell_wrapper.py

but as we have compiled everything you will have to pick the one that matches with your FreeCAD Python version. Check it easily reading the first line inside your FreeCAD Python console view. In my case it was Python 2.7.11.

9. Now go let's copy the files inside the place it corresponds to your Python version. In my case it was:

/IfcOpenShell/build/Darwin/x86_64/build/ifcopenshell/[b]python-2.7[/b].10/ifcwrap/

10. Paste them inside /site-packages/ifcopenshell/

11. Check everything is in place:

/site-packages/ifcopenshell/__init__.py                  (1)
/site-packages/ifcopenshell/entity_instance.py           (1)
/site-packages/ifcopenshell/_ifcopenshell_wrapper.so     (2)
/site-packages/ifcopenshell/file.py                      (1)
/site-packages/ifcopenshell/geom/__init__.py             (1)
/site-packages/ifcopenshell/geom/app.py                  (1)
/site-packages/ifcopenshell/geom/main.py                 (1)
/site-packages/ifcopenshell/geom/occ_utils.py            (1)
/site-packages/ifcopenshell/guid.py                      (1)
/site-packages/ifcopenshell/ifcopenshell_wrapper.py      (2)

(1) from GitHub project
(2) from /build/ folder


12. Close and reopen FreeCAD

Testing

Now that it is installed, let's check if everything works as expected:

12.1 in the Python console write:

import ifcopenshell
from ifcopenshell import geom

if it doesn't throw any error it means it may be correctly installed

12.2 Go to Yorik's FreeCAD manual, navigate to the lower part of the page and download the following files to test:

house.FCStd
house.ifc

12.3 Open house.FCStd, select the root "Building" object and export it (File → Export) setting the File type to "Industry Foundation Classes (*.ifc)". Press Save and if it works and it doesn't throw an error in the Report view then it's working.

12.4 Final test, import house.ifc into a new file so open a new file and import that file... it will take a while.

13. Enjoy BIM with FreeCAD!

Final thoughts

My opinion is that FreeCAD itself should have precompiled versions of IfcOpenShell bundled with the distribution because building it by yourself is a total pain and average user won't do it (they don't know how to compile, manage GitHub, etc), but well, maybe in the future.

I hope it helps you.

Cheers

Links