6262 description = "The STEP Datatype keyword" )
6363
6464
65- def import_ifc (filename , use_names , process_relations ):
65+ def import_ifc (filename , use_names , process_relations , blender_booleans ):
6666 from . import ifcopenshell
67+ from .ifcopenshell import geom as ifcopenshell_geom
6768 print ("Reading %s..." % bpy .path .basename (filename ))
68- settings = ifcopenshell .IteratorSettings ()
69- iterator = ifcopenshell .Iterator (settings , filename )
69+ settings = ifcopenshell_geom .settings ()
70+ settings .set (settings .DISABLE_OPENING_SUBTRACTIONS , blender_booleans )
71+ iterator = ifcopenshell_geom .iterator (settings , filename )
7072 valid_file = iterator .findContext ()
7173 if not valid_file :
7274 return False
7375 print ("Done reading file" )
7476 id_to_object = {}
7577 id_to_parent = {}
7678 id_to_matrix = {}
79+ openings = []
7780 old_progress = - 1
7881 print ("Creating geometry..." )
7982 while True :
@@ -139,15 +142,20 @@ def add_material(mname, props):
139142 bob .ifc_id , bob .ifc_guid , bob .ifc_name , bob .ifc_type = \
140143 ob .id , ob .guid , ob .name , ob .type
141144
142- bob .hide = ob .type == 'IfcSpace' or ob .type == 'IfcOpeningElement'
143- bob .hide_render = bob .hide
145+ if ob .type == 'IfcSpace' or ob .type == 'IfcOpeningElement' :
146+ if not (ob .type == 'IfcOpeningElement' and blender_booleans ):
147+ bob .hide = bob .hide_render = True
148+ bob .draw_type = 'WIRE'
144149
145150 if ob .id not in id_to_object : id_to_object [ob .id ] = []
146151 id_to_object [ob .id ].append (bob )
147152
148153 if ob .parent_id > 0 :
149154 id_to_parent [ob .id ] = ob .parent_id
150155
156+ if blender_booleans and ob .type == 'IfcOpeningElement' :
157+ openings .append (ob .id )
158+
151159 faces = me .polygons if hasattr (me , 'polygons' ) else me .faces
152160 if len (faces ) == len (matids ):
153161 for face , matid in zip (faces , matids ):
@@ -173,11 +181,11 @@ def add_material(mname, props):
173181 if parent_id in id_to_object :
174182 bob = id_to_object [parent_id ][0 ]
175183 else :
176- parent_ob = iterator .GetObject (parent_id )
184+ parent_ob = iterator .getObject (parent_id )
177185 if parent_ob .id == - 1 :
178186 bob = None
179187 else :
180- m = parent_ob .matrix
188+ m = parent_ob .transformation . matrix . data
181189 nm = parent_ob .name if len (parent_ob .name ) and use_names \
182190 else parent_ob .guid
183191 bob = bpy .data .objects .new (nm , None )
@@ -219,7 +227,16 @@ def add_material(mname, props):
219227
220228 if process_relations :
221229 print ("Done processing relations" )
222-
230+
231+ for opening_id in openings :
232+ parent_id = id_to_parent [opening_id ]
233+ if parent_id in id_to_object :
234+ parent_ob = id_to_object [parent_id ][0 ]
235+ for opening_ob in id_to_object [opening_id ]:
236+ mod = parent_ob .modifiers .new ("opening" , "BOOLEAN" )
237+ mod .operation = "DIFFERENCE"
238+ mod .object = opening_ob
239+
223240 txt = bpy .data .texts .new ("%s.log" % bpy .path .basename (filename ))
224241 txt .from_string (iterator .getLog ())
225242
@@ -241,9 +258,13 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
241258 " relations to parenting" \
242259 " (warning: may be slow on large files)" ,
243260 default = False )
261+ blender_booleans = BoolProperty (name = "Use Blender booleans" ,
262+ description = "Use Blender boolean modifiers for opening" \
263+ " elements" ,
264+ default = False )
244265
245266 def execute (self , context ):
246- if not import_ifc (self .filepath , self .use_names , self .process_relations ):
267+ if not import_ifc (self .filepath , self .use_names , self .process_relations , self . blender_booleans ):
247268 self .report ({'ERROR' },
248269 'Unable to parse .ifc file or no geometrical entities found'
249270 )
0 commit comments