IFC Export from FreeCAD

This forum section is only for IFC-related issues
Post Reply
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

IFC Export from FreeCAD

Post by bernd »

EDIT:
Find a blog entry here: http://yorik.uncreated.net/guestblog.php?2014=40
Find the testhouse2.ifc here: https://dl.dropboxusercontent.com/u/754 ... house2.ifc
Find the testhouse2.fcstd here: https://dl.dropboxusercontent.com/u/754 ... use2.fcstd

-----------------------------------------------------------------------------------------------------------------------------------


Ifc export from freecad was disscussed here (viewtopic.php?f=23&t=5101&start=20#p40272)

@Yorik, just to get it done the right way from start. Could you prove the following steps?

- Get ifcWriter.py (https://gist.github.com/yorikvanhavre/6040612) --> copy the file to ArchModlule folder of FreeCAD.
- Get the ifcopenshell development version from https://github.com/aothms/IfcOpenShell --> compile it, do not install it
- in ifcWriter.py --> set the path to ifcwrap folder of the preety new compiled ifcopenshell build
- in freecad --> export your model to ifc

Will there be an icon in freecad or do I need to use the python console?

Bernd
Last edited by bernd on Mon May 19, 2014 4:34 pm, edited 2 times in total.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: IFC Export from FreeCAD

Post by yorik »

The last part doesn't exist yet. Right now you can just use the ifcWriter.py to test writing ifc files from python (look at the examples at the end of the file, the test2 still doesn't work because the facetedBrep stuff causes an error in ifcopenshell )

I made it in 2 parts, so we have this ifcwriter module that is totally freecad-independent, and can export ifc files from (I hope very simple :) ) python scripts. But it's the biggest part, make a freecad exporter that uses that interface will be easy.

Once you get the ifcWriter script and compiled the dev version of ifcopenshell, you need to place an empty __init__.py file inside the compiled-ifcopenshell/ifcwrap folder (that contains IfcImport.py)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC Export from FreeCAD

Post by bernd »

Ahh, I see. Thanks Yorik, for given me the informations. I knew I would need some more hints :) I'll give it a try, soon. Bernd
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC Export from FreeCAD

Post by bernd »

Mhh, I still mess things up ...

- I got ifcopenshell dev version and compiled it
- I got ifcWriter.py copied to ArchModul and change the path in the file

Code: Select all

sys.path.append("/home/hugo/Documents/projekte--ifc/ifcopenshell/ifcopenshell_030master/IfcOpenShell-master/cmake/build/ifcwrap/")
If I put in that directory a pythonfile hello.py containing print "hello" and make import hello in FreeCAD it prints hello so sys.path should be fine
- I put in that directory a empty file __init__.py
- but in FreeCAD

Code: Select all

>>> import ifcWriter
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/local/Mod/Arch/ifcWriter.py", line 38, in <module>
    from ifcwrap import IfcImport as IfcExport
ImportError: No module named ifcwrap
>>> 
ifcWriter calls

Code: Select all

from ifcwrap import IfcImport as IfcExport
But there is no ifcwrap.py at all in that directory

EDIT: Found it myself

Code: Select all

sys.path.append("/home/hugo/Documents/projekte--ifc/ifcopenshell/ifcopenshell_030master/IfcOpenShell-master/cmake/build")
Last edited by bernd on Wed Dec 11, 2013 9:31 pm, edited 1 time in total.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: IFC Export from FreeCAD

Post by yorik »

You need to use:

Code: Select all

sys.path.append("/home/hugo/Documents/projekte--ifc/ifcopenshell/ifcopenshell_030master/IfcOpenShell-master/cmake/build/")
(remove ifcwrap/ )
that is because by putting an empty __init__.py file inside a directory, you turn it into a module, in the eyes of python. So now we have an ifcwrap python module, with an IfcImport submodule :)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC Export from FreeCAD

Post by bernd »

:lol: :lol: seams we press the submitt button at once
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: IFC Export from FreeCAD

Post by yorik »

actually there is no need (at the moment) to have ifcWriter.py inside the freecad dir, it's independent... But soon we'll need it!
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: IFC Export from FreeCAD

Post by yorik »

and, besides, freecad has a superior python console :geek:
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: IFC Export from FreeCAD

Post by bernd »

got it, I'm just playing with new python class ifc and ifcopenshell. The method new() has a problem. I'm not able to use a testmethod twice.

Code: Select all

def test4():
    
    "creation of a new file using manual, step-by-step procedure"
    
    f = new()
    own = makeOwner(f,"Bernd")
 

Code: Select all

hugo@weide:~/Documents/projekte--ifc/ifcopenshell$ python
Python 2.7.3 (default, Jan  2 2013, 13:56:14)                                                                                                                                
[GCC 4.7.2] on linux2                                                                                                                                                        
Type "help", "copyright", "credits" or "license" for more information.                                                                                                       
>>> import myifcWriter                                                                                                                                                       
>>> myifcWriter.test4()                                                                                                                                                      
>>> myifcWriter.test4()                                                                                                                                                      
*** glibc detected *** python: double free or corruption (!prev): 0x00000000024088b0 ***                                                                                     
======= Backtrace: =========                                                                                                                                                 
/lib/x86_64-linux-gnu/libc.so.6(+0x76d76)[0x7f89e52abd76]                                                                                                                    
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x6c)[0x7f89e52b0aac]                                                                                                                  
/home/hugo/Documents/projekte--ifc/ifcopenshell/ifcopenshell_030master/IfcOpenShell-master/cmake/build/ifcwrap/_IfcImport.so(+0x20c549)[0x7f89e36a1549]                      
python(PyObject_CallFunctionObjArgs+0x15b)[0x46098b]                                                                                                                         
/home/hugo/Documents/projekte--ifc/ifcopenshell/ifcopenshell_030master/IfcOpenShell-master/cmake/build/ifcwrap/_IfcImport.so(+0x20f5fd)[0x7f89e36a45fd]                      
python[0x46f73d]                                                                                                                                                             
python[0x4877ee]                                                                                                                                                             
python[0x46f441]                                                                                                                                                             
python[0x46f73d]                                                                                                                                                             
python[0x48648e]                                                                                                                                                             
python[0x477df6]                                                                                                                                                             
python(PyDict_SetItem+0x98)[0x464cc8]                                                                                                                                        
python(PyEval_EvalFrameEx+0x1ff1)[0x4ae2e1]                                                                                                                                  
python(PyEval_EvalFrameEx+0xaf0)[0x4acde0]                                                                                                                                   
======= Memory map: ========                                                                                                                                                 
00400000-00658000 r-xp 00000000 08:02 3670                               /usr/bin/python2.7                                                                                  
00857000-00858000 r--p 00257000 08:02 3670                               /usr/bin/python2.7                                                                                  
00858000-008c1000 rw-p 00258000 08:02 3670                               /usr/bin/python2.7                                                                                  
008c1000-008d3000 rw-p 00000000 00:00 0                                                                                                                                      
02036000-0241f000 rw-p 00000000 00:00 0                                  [heap]                                                                                              
60000000-603e8000 rw-p 00000000 00:05 1031                               /dev/zero                                                                                           
7f89d8000000-7f89d8021000 rw-p 00000000 00:00 0                                                                                                                              
7f89d8021000-7f89dc000000 ---p 00000000 00:00 0                                                                                                                              
7f89dda02000-7f89deb71000 r-xp 00000000 08:02 267745                     /usr/lib/x86_64-linux-gnu/libicudata.so.48.1.1                                                      
7f89deb71000-7f89ded70000 ---p 0116f000 08:02 267745                     /usr/lib/x86_64-linux-gnu/libicudata.so.48.1.1                                                      
7f89ded70000-7f89ded71000 r--p 0116e000 08:02 267745                     /usr/lib/x86_64-linux-gnu/libicudata.so.48.1.1                                                      
7f89ded71000-7f89ded72000 rw-p 0116f000 08:02 267745                     /usr/lib/x86_64-linux-gnu/libicudata.so.48.1.1                                                      
7f89ded72000-7f89ded79000 r-xp 00000000 08:02 265078                     /lib/x86_64-linux-gnu/librt-2.13.so                                                                 
7f89ded79000-7f89def78000 ---p 00007000 08:02 265078                     /lib/x86_64-linux-gnu/librt-2.13.so                                                                 
7f89def78000-7f89def79000 r--p 00006000 08:02 265078                     /lib/x86_64-linux-gnu/librt-2.13.so                                                                 
7f89def79000-7f89def7a000 rw-p 00007000 08:02 265078                     /lib/x86_64-linux-gnu/librt-2.13.so                                                                 
7f89def7a000-7f89df062000 r-xp 00000000 08:02 264976                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17                                                       
7f89df062000-7f89df262000 ---p 000e8000 08:02 264976                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17                                                       
7f89df262000-7f89df26a000 r--p 000e8000 08:02 264976                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17                                                       
7f89df26a000-7f89df26c000 rw-p 000f0000 08:02 264976                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.17                                                       
7f89df26c000-7f89df281000 rw-p 00000000 00:00 0                                                                                                                              
7f89df281000-7f89df3db000 r-xp 00000000 08:02 268983                     /usr/lib/x86_64-linux-gnu/libicuuc.so.48.1.1                                                        
7f89df3db000-7f89df5da000 ---p 0015a000 08:02 268983                     /usr/lib/x86_64-linux-gnu/libicuuc.so.48.1.1                                                        
7f89df5da000-7f89df5eb000 r--p 00159000 08:02 268983                     /usr/lib/x86_64-linux-gnu/libicuuc.so.48.1.1                                                        
7f89df5eb000-7f89df5ec000 rw-p 0016a000 08:02 268983                     /usr/lib/x86_64-linux-gnu/libicuuc.so.48.1.1                                                        
7f89df5ec000-7f89df5f0000 rw-p 00000000 00:00 0                                                                                                                              
7f89df5f0000-7f89df879000 r-xp 00000000 08:02 7061                       /usr/lib/libTKFillet.so.2.0.0                                                                       
7f89df879000-7f89dfa79000 ---p 00289000 08:02 7061                       /usr/lib/libTKFillet.so.2.0.0                                                                       
7f89dfa79000-7f89dfa7e000 r--p 00289000 08:02 7061                       /usr/lib/libTKFillet.so.2.0.0                                                                       
7f89dfa7e000-7f89dfa83000 rw-p 0028e000 08:02 7061                       /usr/lib/libTKFillet.so.2.0.0                                                                       
7f89dfa83000-7f89dfa84000 rw-p 00000000 00:00 0                                                                                                                              
7f89dfa84000-7f89dfc6d000 r-xp 00000000 08:02 6354                       /usr/lib/libTKBO.so.2.0.0                                                                           
7f89dfc6d000-7f89dfe6c000 ---p 001e9000 08:02 6354                       /usr/lib/libTKBO.so.2.0.0                                                                           
7f89dfe6c000-7f89dfe71000 r--p 001e8000 08:02 6354                       /usr/lib/libTKBO.so.2.0.0                                                                           
7f89dfe71000-7f89dfe77000 rw-p 001ed000 08:02 6354                       /usr/lib/libTKBO.so.2.0.0                                                                           
7f89dfe77000-7f89dfe78000 rw-p 00000000 00:00 0                                                                                                                              
7f89dfe78000-7f89e0214000 r-xp 00000000 08:02 6162                       /usr/lib/libTKBool.so.2.0.0                                                                         
7f89e0214000-7f89e0414000 ---p 0039c000 08:02 6162                       /usr/lib/libTKBool.so.2.0.0                                                                         
7f89e0414000-7f89e041a000 r--p 0039c000 08:02 6162                       /usr/lib/libTKBool.so.2.0.0                                                                         
7f89e041a000-7f89e0424000 rw-p 003a2000 08:02 6162                       /usr/lib/libTKBool.so.2.0.0                                                                         
7f89e0424000-7f89e0426000 rw-p 00000000 00:00 0                                                                                                                              
7f89e0426000-7f89e0481000 r-xp 00000000 08:02 6626                       /usr/lib/libTKPrim.so.2.0.0                                                                         
7f89e0481000-7f89e0680000 ---p 0005b000 08:02 6626                       /usr/lib/libTKPrim.so.2.0.0                                                                         
7f89e0680000-7f89e0682000 r--p 0005a000 08:02 6626                       /usr/lib/libTKPrim.so.2.0.0                                                                         
7f89e0682000-7f89e0683000 rw-p 0005c000 08:02 6626                       /usr/lib/libTKPrim.so.2.0.0                                                                         
7f89e0683000-7f89e0684000 rw-p 00000000 00:00 0                                                                                                                              
7f89e0684000-7f89e071a000 r-xp 00000000 08:02 6432                       /usr/lib/libTKMesh.so.2.0.0                                                                         
7f89e071a000-7f89e0919000 ---p 00096000 08:02 6432                       /usr/lib/libTKMesh.so.2.0.0                                                                         
7f89e0919000-7f89e091c000 r--p 00095000 08:02 6432                       /usr/lib/libTKMesh.so.2.0.0                                                                         
7f89e091c000-7f89e091e000 rw-p 00098000 08:02 6432                       /usr/lib/libTKMesh.so.2.0.0                                                                         
7f89e091e000-7f89e091f000 rw-p 00000000 00:00 0                                                                                                                              
7f89e091f000-7f89e0b5f000 r-xp 00000000 08:02 5776                       /usr/lib/libTKTopAlgo.so.2.0.0
7f89e0b5f000-7f89e0d5e000 ---p 00240000 08:02 5776                       /usr/lib/libTKTopAlgo.so.2.0.0
7f89e0d5e000-7f89e0d63000 r--p 0023f000 08:02 5776                       /usr/lib/libTKTopAlgo.so.2.0.0
7f89e0d63000-7f89e0d69000 rw-p 00244000 08:02 5776                       /usr/lib/libTKTopAlgo.so.2.0.0
7f89e0d69000-7f89e0d6b000 rw-p 00000000 00:00 0 
7f89e0d6b000-7f89e0f93000 r-xp 00000000 08:02 6245                       /usr/lib/libTKShHealing.so.2.0.0
7f89e0f93000-7f89e1193000 ---p 00228000 08:02 6245                       /usr/lib/libTKShHealing.so.2.0.0
7f89e1193000-7f89e1198000 r--p 00228000 08:02 6245                       /usr/lib/libTKShHealing.so.2.0.0
7f89e1198000-7f89e119d000 rw-p 0022d000 08:02 6245                       /usr/lib/libTKShHealing.so.2.0.0Abgebrochen
hugo@weide:~/Documents/projekte--ifc/ifcopenshell$ 
Ahh, found something on my desktop ...
Attachments
screen.jpg
screen.jpg (67.97 KiB) Viewed 7580 times
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: IFC Export from FreeCAD

Post by yorik »

hehe great :)

there is a whole thing with that version of ifcopenshell, is that every ifc entity you create in a file, must stay alive in the memory up to the end, when the file is written. In more advanced python interfaces such as pivy this is done automatically, but here since this is all very new, the author of ifcopenshell hasn't done it yet. So I created that "holder" mechanism, which is an object that keeps a reference alive of every created object, otherwise ifcopenshell crashes immediately. But it is a quick hack, probably it is the cause of your crash... I'll have a look at it.
Post Reply