Skip to content

Commit

Permalink
Loading model elements is now half aware of existing elements and wil…
Browse files Browse the repository at this point in the history
…l reuse where possible.
  • Loading branch information
Moult committed Oct 24, 2022
1 parent 2f76434 commit a908fa6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/blenderbim/blenderbim/bim/import_ifc.py
Expand Up @@ -177,6 +177,7 @@ def __init__(self, ifc_import_settings):
self.settings_2d.set(self.settings_2d.INCLUDE_CURVES, True)
self.settings_2d.set(self.settings.STRICT_TOLERANCE, True)
self.project = None
self.has_existing_project = False
self.collections = {}
self.elements = set()
self.type_collection = None
Expand Down Expand Up @@ -893,6 +894,11 @@ def create_product(self, element, shape=None, mesh=None):
if element is None:
return

if self.has_existing_project:
obj = tool.Ifc.get_object(element)
if obj:
return obj

self.ifc_import_settings.logger.info("Creating object %s", element)

if mesh:
Expand Down Expand Up @@ -1306,7 +1312,13 @@ def set_units(self):
)

def create_project(self):
self.project = {"ifc": self.file.by_type("IfcProject")[0]}
project = self.file.by_type("IfcProject")[0]
self.project = {"ifc": project}
obj = tool.Ifc.get_object(project)
if obj:
self.project["blender"] = obj.users_collection[0]
self.has_existing_project = True
return
self.project["blender"] = bpy.data.collections.new(
"{}/{}".format(self.project["ifc"].is_a(), self.project["ifc"].Name)
)
Expand Down Expand Up @@ -1359,10 +1371,17 @@ def create_spatial_decomposition_collection(self, parent, related_objects):
for element in related_objects:
if element not in self.spatial_elements:
continue
global_id = element.GlobalId
collection = bpy.data.collections.new(self.get_name(element))
self.collections[global_id] = collection
parent.children.link(collection)
is_existing = False
if self.has_existing_project:
obj = tool.Ifc.get_object(element)
if obj:
is_existing = True
collection = obj.users_collection[0]
self.collections[element.GlobalId] = collection
if not is_existing:
collection = bpy.data.collections.new(self.get_name(element))
self.collections[element.GlobalId] = collection
parent.children.link(collection)
if element.IsDecomposedBy:
for rel_aggregate in element.IsDecomposedBy:
self.create_spatial_decomposition_collection(collection, rel_aggregate.RelatedObjects)
Expand Down
1 change: 1 addition & 0 deletions src/blenderbim/blenderbim/tool/model.py
Expand Up @@ -62,6 +62,7 @@ def load_openings(cls, element, openings):
ifc_importer.file = tool.Ifc.get()
ifc_importer.calculate_unit_scale()
ifc_importer.process_context_filter()
ifc_importer.material_creator.load_existing_materials()
openings = set(openings)
openings -= ifc_importer.create_products(openings)
for opening in openings or []:
Expand Down

0 comments on commit a908fa6

Please sign in to comment.