Skip to content

Commit 109149a

Browse files
committed
Optimise owner check depending on your implementation and no longer create default users on IFC4. Can result in 50% faster script running on long scripted operations.
1 parent 4bf4622 commit 109149a

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/blenderbim/blenderbim/bim/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,15 @@ def ensureIfcExported(scene):
202202

203203

204204
def get_application(ifc):
205+
# TODO: cache this for even faster application retrieval. It honestly makes a difference on long scripts.
205206
version = get_application_version()
206207
for element in ifc.by_type("IfcApplication"):
207208
if element.ApplicationIdentifier == "BlenderBIM" and element.Version == version:
208209
return element
209210
return ifcopenshell.api.run(
210211
"owner.add_application",
211212
ifc,
212-
version=get_application_version(),
213+
version=version,
213214
application_full_name="BlenderBIM Add-on",
214215
application_identifier="BlenderBIM",
215216
)

src/blenderbim/blenderbim/bim/import_ifc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,12 +1211,12 @@ def place_object_in_decomposition_collection(self, element, obj):
12111211
elif element.is_a("IfcGridAxis"):
12121212
return
12131213
elif element.GlobalId in self.collections:
1214-
return self.collections[element.GlobalId].objects.link(obj)
1215-
elif getattr(element, "Decomposes", None):
1216-
aggregate = ifcopenshell.util.element.get_aggregate(element)
1217-
collection = self.collections[aggregate.GlobalId]
1214+
collection = self.collections[element.GlobalId]
12181215
collection.name = obj.name
12191216
return collection.objects.link(obj)
1217+
elif getattr(element, "Decomposes", None):
1218+
aggregate = ifcopenshell.util.element.get_aggregate(element)
1219+
return self.collections[aggregate.GlobalId].objects.link(obj)
12201220
else:
12211221
return self.place_object_in_spatial_decomposition_collection(element, obj)
12221222

src/blenderbim/blenderbim/bim/module/project/operator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ def _execute(self, context):
6161
)
6262
self.file = IfcStore.get_file()
6363

64-
person = blenderbim.core.owner.add_person(tool.Ifc)
65-
organisation = blenderbim.core.owner.add_organisation(tool.Ifc)
66-
user = blenderbim.core.owner.add_person_and_organisation(tool.Ifc, person=person, organisation=organisation)
67-
blenderbim.core.owner.set_user(tool.Owner, user=user)
64+
if self.file.schema == "IFC2X3":
65+
person = blenderbim.core.owner.add_person(tool.Ifc)
66+
organisation = blenderbim.core.owner.add_organisation(tool.Ifc)
67+
user = blenderbim.core.owner.add_person_and_organisation(tool.Ifc, person=person, organisation=organisation)
68+
blenderbim.core.owner.set_user(tool.Owner, user=user)
6869

6970
project = bpy.data.objects.new(self.get_name("IfcProject", "My Project"), None)
7071
site = bpy.data.objects.new(self.get_name("IfcSite", "My Site"), None)

src/ifcopenshell-python/ifcopenshell/api/owner/create_owner_history.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ def __init__(self, file, **settings):
1212

1313
def execute(self):
1414
user = ifcopenshell.api.owner.settings.get_user(self.file)
15+
if self.file.schema != "IFC2X3" and not user:
16+
return
1517
application = ifcopenshell.api.owner.settings.get_application(self.file)
16-
if self.file.schema != "IFC2X3":
17-
if not user or not application:
18-
return
18+
if self.file.schema != "IFC2X3" and not application:
19+
return
1920
return self.file.create_entity(
2021
"IfcOwnerHistory",
2122
**{

src/ifcopenshell-python/ifcopenshell/api/owner/update_owner_history.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ def execute(self):
1515
if not hasattr(self.settings["element"], "OwnerHistory"):
1616
return
1717
user = ifcopenshell.api.owner.settings.get_user(self.file)
18+
if not user:
19+
return
1820
application = ifcopenshell.api.owner.settings.get_application(self.file)
19-
if not user or not application:
21+
if not application:
2022
return
2123
if not self.settings["element"].OwnerHistory:
2224
self.settings["element"].OwnerHistory = ifcopenshell.api.run(

0 commit comments

Comments
 (0)