Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 3810255

Browse files
committed
Fix bug where syncing was not maintained across file saves and collection names were not synced
1 parent d3ca647 commit 3810255

3 files changed

Lines changed: 13 additions & 31 deletions

File tree

src/blenderbim/blenderbim/bim/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def register():
173173
bpy.app.handlers.load_post.append(handler.setDefaultProperties)
174174
bpy.app.handlers.load_post.append(handler.loadIfcStore)
175175
bpy.app.handlers.save_pre.append(handler.ensureIfcExported)
176-
bpy.app.handlers.save_pre.append(handler.storeIdMap)
177176
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
178177
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
179178
bpy.types.Scene.BIMProperties = bpy.props.PointerProperty(type=prop.BIMProperties)
@@ -200,7 +199,6 @@ def unregister():
200199
bpy.utils.unregister_class(cls)
201200
bpy.app.handlers.load_post.remove(handler.setDefaultProperties)
202201
bpy.app.handlers.load_post.remove(handler.loadIfcStore)
203-
bpy.app.handlers.save_pre.remove(handler.storeIdMap)
204202
bpy.app.handlers.save_pre.remove(handler.ensureIfcExported)
205203
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
206204
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)

src/blenderbim/blenderbim/bim/handler.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def name_callback(obj, data):
3030
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
3131
if not element.is_a("IfcRoot"):
3232
return
33+
if element.is_a("IfcSpatialStructureElement") or (hasattr(element, "IsDecomposedBy") and element.IsDecomposedBy):
34+
collection = obj.users_collection[0]
35+
collection.name = obj.name
3336
element.Name = "/".join(obj.name.split("/")[1:])
3437
AttributeData.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
3538

@@ -69,13 +72,13 @@ def purge_module_data():
6972
def loadIfcStore(scene):
7073
IfcStore.file = None
7174
IfcStore.schema = None
72-
props = bpy.context.scene.BIMProperties
73-
IfcStore.id_map = (
74-
{int(k): bpy.data.objects.get(v) for k, v in json.loads(props.id_map).items()} if props.id_map else {}
75-
)
76-
IfcStore.guid_map = (
77-
{k: bpy.data.objects.get(v) for k, v in json.loads(props.guid_map).items()} if props.id_map else {}
78-
)
75+
ifc_file = IfcStore.get_file()
76+
IfcStore.get_schema()
77+
[
78+
IfcStore.link_element(ifc_file.by_id(o.BIMObjectProperties.ifc_definition_id), o)
79+
for o in bpy.data.objects
80+
if o.BIMObjectProperties.ifc_definition_id
81+
]
7982
purge_module_data()
8083

8184

@@ -85,25 +88,6 @@ def ensureIfcExported(scene):
8588
bpy.ops.export_ifc.bim("INVOKE_DEFAULT")
8689

8790

88-
@persistent
89-
def storeIdMap(scene):
90-
try:
91-
bpy.context.scene.BIMProperties.id_map = json.dumps({k: v.name for k, v in IfcStore.id_map.items()})
92-
bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()})
93-
except:
94-
# Regenerate maps. Is there a better solution for this? It seems fragile.
95-
file = IfcStore.get_file()
96-
IfcStore.id_map = {
97-
o.ifc_definition_id: o.name for o in bpy.data.objects if o.BIMObjectProperties.ifc_definition_id
98-
}
99-
IfcStore.guid_map = {
100-
file.by_id(i).GlobalId: n for i, n in IfcStore.id_map.items() if file.by_id(i).is_a("IfcRoot")
101-
}
102-
# Then attempt to store it again
103-
bpy.context.scene.BIMProperties.id_map = json.dumps({k: v.name for k, v in IfcStore.id_map.items()})
104-
bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()})
105-
106-
10791
def get_application(ifc):
10892
version = get_application_version()
10993
for element in ifc.by_type("IfcApplication"):
@@ -176,12 +160,12 @@ def create_application_organisation(ifc):
176160
@persistent
177161
def setDefaultProperties(scene):
178162
ifcopenshell.api.owner.settings.get_person = (
179-
lambda ifc : ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_person))
163+
lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_person))
180164
if bpy.context.scene.BIMOwnerProperties.user_person
181165
else None
182166
)
183167
ifcopenshell.api.owner.settings.get_organisation = (
184-
lambda ifc : ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation))
168+
lambda ifc: ifc.by_id(int(bpy.context.scene.BIMOwnerProperties.user_organisation))
185169
if bpy.context.scene.BIMOwnerProperties.user_organisation
186170
else None
187171
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def execute(self, context):
112112
def create_new_cost_item_li(self, related_object_id, level_index):
113113
cost_item = Data.cost_items[related_object_id]
114114
new = self.props.cost_items.add()
115-
new.name = cost_item["Name"] or "Unnamed"
116115
new.ifc_definition_id = related_object_id
116+
new.name = cost_item["Name"] or "Unnamed"
117117
new.is_expanded = related_object_id not in self.contracted_cost_items
118118
new.level_index = level_index
119119
if cost_item["RelatedObjects"]:

0 commit comments

Comments
 (0)