|
| 1 | +IfcOpenShell |
| 2 | +============ |
| 3 | +open source (LGPL) software library for working with the IFC file format |
| 4 | + |
| 5 | + |
| 6 | +http://IfcOpenShell.org |
| 7 | + |
| 8 | +About this repository |
| 9 | +===================== |
| 10 | + |
| 11 | +This is an initiative to expose the functionality of IfcOpenShell for parsing and writing IFC files to a Python interface. The creation of a topological representation for building elements using Open Cascade is also wrapped by returning a string serialization of the Open Cascade TopoDS_Shape. Using SWIG a wrapper is obtained for a C++ Class which evaluates its Express attribute names and indices at runtime. The functions created by the SWIG wrapper closely resemble the C++ structure. The idea is to create an additional wrapper around these function in Python that is more idiomatic to Python. |
| 12 | + |
| 13 | +The following interactive session illustrates its use: |
| 14 | + |
| 15 | + >>> import IfcImport |
| 16 | + >>> f = IfcImport.open(filename) |
| 17 | + >>> f.by_type("ifcwall") |
| 18 | + [#170=IfcWallStandardCase('0lJANQLbCEHPkU1Xq9w_bk',#13,'Wand-001',$,$,#167,#240,'2F4CA5DA-5653-0E45-9B-9E-061D09EBE96E'), |
| 19 | + #288=IfcWallStandardCase('1sFBHOg98nGQTuD1XjjAKK',#13,'Wand-002',$,$,#285,#358,'763CB458-A892-3141-A7-78-34186DB4A514')] |
| 20 | + >>> wall = _[0] |
| 21 | + >>> brep_data = IfcImport.create_shape(wall) |
| 22 | + >>> wall.get_argument_count() |
| 23 | + 8 |
| 24 | + >>> wall.get_argument('GlobalId') |
| 25 | + '0lJANQLbCEHPkU1Xq9w_bk' |
| 26 | + >>> wall.get_argument_index('Name') |
| 27 | + 2 |
| 28 | + >>> wall.set_argument(2,"John") |
| 29 | + >>> wall.get_argument('Name') |
| 30 | + 'John' |
| 31 | + >>> wall.get_argument_index("foo") |
| 32 | + Traceback (most recent call last): |
| 33 | + File "<stdin>", line 1, in <module> |
| 34 | + File "IfcImport.py", line 112, in get_argument_index |
| 35 | + def get_argument_index(self, *args): return _IfcImport.Entity_get_argument_index(self, *args) |
| 36 | + RuntimeError: Argument foo not found on IfcRoot |
| 37 | + >>> wall.set_argument(5,"Hi") |
| 38 | + Traceback (most recent call last): |
| 39 | + File "<stdin>", line 1, in <module> |
| 40 | + File "IfcImport.py", line 114, in set_argument |
| 41 | + def set_argument(self, *args): return _IfcImport.Entity_set_argument(self, *args) |
| 42 | + RuntimeError: STRING is not a valid type for 'ObjectPlacement' |
| 43 | + >>> e = IfcImport.Entity("IfcJohn") |
| 44 | + Traceback (most recent call last): |
| 45 | + File "<stdin>", line 1, in <module> |
| 46 | + File "IfcImport.py", line 105, in __init__ |
| 47 | + this = _IfcImport.new_Entity(*args) |
| 48 | + RuntimeError: Unable to find find keyword in schema |
| 49 | + >>> pnt = IfcImport.Entity("ifccartesianpoint") |
| 50 | + [60478 refs] |
| 51 | + >>> pnt.set_argument(0,IfcImport.Doubles([0,0,0])) |
| 52 | + [60486 refs] |
| 53 | + >>> pnt |
| 54 | + =IfcCartesianPoint((0,0,0)) |
| 55 | + >>> f.add(pnt) |
| 56 | + >>> f.write("out.ifc") |
| 57 | + |
| 58 | +**TODO**: By creating an additional wrapper in Python around these methods some syntactic sugar can be added so one is able to say the following instead: |
| 59 | + |
| 60 | + d = IfcDocument() |
| 61 | + my_wall = d.createIfcWallStandardCase("1$gyu8123...",Representation=my_repr) |
| 62 | + |
| 63 | +With a document specifying a 'catch-all' function that creates the ifc entity based on the method being called, perhaps like so: |
| 64 | + |
| 65 | + class IfcDocument: |
| 66 | + def create_entity(self,type,*args,**kwargs): |
| 67 | + e = new IfcEntity(type) |
| 68 | + # set all attributes in args and kwargs |
| 69 | + self.add(e) |
| 70 | + return e |
| 71 | + def __getattr__(self,attr): |
| 72 | + if attr[0:5] == 'create': return functools.partial(self.create_entity,attr[5:]) |
| 73 | + ... |
| 74 | + |
| 75 | + |
| 76 | +Compiling on Windows |
| 77 | +==================== |
| 78 | +Users are advised to use the Visual Studio .sln file in the win/ folder. |
| 79 | +For Windows users a prebuilt Open CASCADE version is available from the |
| 80 | +http://opencascade.org website. Download and install this version and |
| 81 | +provide the paths to the Open CASCADE header and library files to MS |
| 82 | +Visual Studio C++. |
| 83 | + |
| 84 | +For building the Autodesk 3ds Max plugin, the 3ds Max SDK needs to be |
| 85 | +installed as well as 3ds Max itself. Please provide the include and |
| 86 | +library paths to Visual Studio. |
| 87 | + |
| 88 | +For building the IfcPython wrapper, SWIG needs to be installed. Please |
| 89 | +download the latest swigwin version from http://www.swig.org/download.html. |
| 90 | +After extracting the .zip file, please add the extracted folder to the PATH |
| 91 | +environment variable. Python needs to be installed, please provide the |
| 92 | +include and library paths to Visual Studio. |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +Compiling on *nix |
| 97 | +==================== |
| 98 | +Users are advised to build IfcOpenShell using the cmake file provided in |
| 99 | +the cmake/ folder. There might be an Open CASCADE package in your operating |
| 100 | +system's software repository. If not, you will need to compile Open |
| 101 | +CASCADE yourself. See http://opencascade.org. |
| 102 | + |
| 103 | +For building the IfcPython wrapper, SWIG and Python development are |
| 104 | +required. |
| 105 | + |
| 106 | + To build IfcOpenShell please take the following steps: |
| 107 | + $ cd /path/to/IfcOpenShell/cmake |
| 108 | + $ mkdir build |
| 109 | + $ cd build |
| 110 | + Optionally: |
| 111 | + $ OCC_INCLUDE_PATH="/path/to/OpenCASCADE/include" |
| 112 | + $ OCC_LIBRARY_PATH="/path/to/OpenCASCADE/lib" |
| 113 | + $ export OCC_INCLUDE_PATH |
| 114 | + $ export OCC_LIBRARY_PATH |
| 115 | + $ cmake ../ |
| 116 | + $ make |
| 117 | + |
| 118 | +If all worked out correctly you can now use IfcOpenShell. For example: |
| 119 | + $ wget ftp://ftp.dds.no/pub/ifc/Munkerud/Munkerud_hus6_BE.zip |
| 120 | + $ unzip Munkerud_hus6_BE.zip |
| 121 | + $ ./IfcObj Munkerud_hus6_BE.ifc |
| 122 | + $ less Munkerud_hus6_BE.obj |
0 commit comments