type selection error #3318

if you switch ifc_class then relating_type_id can become invalid and we wasn't taking it into account

Also fixed bunch of warning like `pyrna_enum_to_py: current value '17' matches no enum in 'BIMModelProperties', '', 'relating_type_id'`` when some ifc_class has N related types and then you switch to other ifc_class that has less than N related types.
This commit is contained in:
Andrej730
2023-07-05 16:44:55 +05:00
parent ca8ed87f2a
commit 74a025b81c
3 changed files with 20 additions and 2 deletions
@@ -48,15 +48,18 @@ class AuthoringData:
cls.is_loaded = True
cls.props = bpy.context.scene.BIMModelProperties
cls.data["ifc_classes"] = cls.ifc_classes()
cls.data["relating_type_id"] = cls.relating_type_id()
cls.data["relating_type_id"] = cls.relating_type_id() # only after .ifc_classes()
cls.data["type_class"] = cls.type_class()
# only after .type_class()
cls.data["type_predefined_type"] = cls.type_predefined_type()
cls.data["total_types"] = cls.total_types()
cls.data["total_pages"] = cls.total_pages()
cls.data["next_page"] = cls.next_page()
cls.data["prev_page"] = cls.prev_page()
cls.data["paginated_relating_types"] = cls.paginated_relating_types()
cls.data["type_thumbnail"] = cls.type_thumbnail()
cls.data["type_thumbnail"] = cls.type_thumbnail() # only after .relating_type_id()
cls.data["is_voidable_element"] = cls.is_voidable_element()
cls.data["has_visible_openings"] = cls.has_visible_openings()
cls.data["has_visible_boundaries"] = cls.has_visible_boundaries()
@@ -112,6 +115,8 @@ class AuthoringData:
def type_thumbnail(cls):
if not cls.data["relating_type_id"]:
return 0
if not tool.Blender.enum_property_has_valid_index(cls.props, "relating_type_id", cls.data["relating_type_id"]):
return 0
element = tool.Ifc.get().by_id(int(cls.props.relating_type_id))
return cls.type_thumbnails.get(element.id(), None) or 0
@@ -59,6 +59,8 @@ def update_ifc_class(self, context):
bpy.ops.bim.load_type_thumbnails(ifc_class=self.ifc_class)
AuthoringData.data["relating_type_id"] = AuthoringData.relating_type_id()
AuthoringData.data["type_thumbnail"] = AuthoringData.type_thumbnail()
if not tool.Blender.enum_property_has_valid_index(self, "relating_type_id", AuthoringData.data["relating_type_id"]):
self["relating_type_id"] = 0
def update_type_class(self, context):
+11
View File
@@ -329,6 +329,17 @@ class Blender:
context.view_layer.objects.active = active_object
active_object.select_set(True)
@classmethod
def enum_property_has_valid_index(cls, props, prop_name, enum_items):
"""method created for readibility and to avoid console warnings like
`pyrna_enum_to_py: current value '17' matches no enum in 'BIMModelProperties', '', 'relating_type_id'`
"""
current_value_index = props.get(prop_name, None)
# assuming the default value is fine
if current_value_index is None:
return True
return current_value_index < len(enum_items)
@classmethod
def append_data_block(cls, filepath, data_block_type, name, link=False, relative=False):
if Path(filepath) == Path(bpy.data.filepath):