From 2b63698d7c1c72e5452ce37f916c022cec08b04d Mon Sep 17 00:00:00 2001 From: Gorgious Date: Tue, 3 Aug 2021 12:51:31 +0200 Subject: [PATCH] Use module variables as dynamic enum containers As explained in https://devtalk.blender.org/t/can-bpy-props-be-used-for-dynamic-lists/10130/11 Dynamic enums can crash Blender if container is not set using at least a module-level variable. Using global keyword is not mandatory but may help debugging --- .../blenderbim/bim/module/owner/prop.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/owner/prop.py b/src/blenderbim/blenderbim/bim/module/owner/prop.py index 359d1cc129..367aa13784 100644 --- a/src/blenderbim/blenderbim/bim/module/owner/prop.py +++ b/src/blenderbim/blenderbim/bim/module/owner/prop.py @@ -14,27 +14,37 @@ from bpy.props import ( CollectionProperty, ) +_persons_enum = [] +_organisations_enum = [] + +def purge(): + global _persons_enum + global _organisations_enum + _persons_enum.clear() + _organisations_enum.clear() def getPersons(self, context): + global _persons_enum if not Data.is_loaded: Data.load(IfcStore.get_file()) - results = [] + _persons_enum.clear() for ifc_id, person in Data.people.items(): if "Id" in person: identifier = person["Id"] or "" else: identifier = person["Identification"] or "" - results.append((str(ifc_id), identifier, "")) - return results + _persons_enum.append((str(ifc_id), identifier, "")) + return _persons_enum def getOrganisations(self, context): + global _organisations_enum if not Data.is_loaded: Data.load(IfcStore.get_file()) - results = [] + _organisations_enum.clear() for ifc_id, organisation in Data.organisations.items(): - results.append((str(ifc_id), organisation["Name"], "")) - return results + _organisations_enum.append((str(ifc_id), organisation["Name"], "")) + return _organisations_enum class Address(PropertyGroup):