Hide assign/unassign library declaration button for elements that cannot be declared

E.g. IfcMaterials, IfcProfileDefs
This commit is contained in:
Andrej730
2025-01-29 16:33:14 +05:00
parent 909a7ad7a2
commit 8bddde49a2
3 changed files with 21 additions and 6 deletions
@@ -271,10 +271,21 @@ class ChangeLibraryElement(bpy.types.Operator):
new.name = name
new.ifc_definition_id = ifc_definition_id
element = self.library_file.by_id(ifc_definition_id)
if self.library_file.schema == "IFC2X3" or not self.library_file.by_type("IfcProjectLibrary"):
# is_declarable.
project_libraries_exist = bool(
self.library_file.schema != "IFC2X3" and self.library_file.by_type("IfcProjectLibrary")
)
is_declarable = project_libraries_exist and element.is_a("IfcObjectDefinition")
new.is_declarable = is_declarable
# is_declared.
if not is_declarable:
new.is_declared = False
elif getattr(element, "HasContext", None) and element.HasContext[0].RelatingContext.is_a("IfcProjectLibrary"):
elif (has_context := element.HasContext) and has_context[0].RelatingContext.is_a("IfcProjectLibrary"):
new.is_declared = True
# is_appended.
try:
if element.is_a("IfcMaterial"):
next(e for e in self.file.by_type("IfcMaterial") if e.Name == name)
@@ -103,12 +103,18 @@ class LibraryElement(PropertyGroup):
ifc_definition_id: IntProperty(name="IFC Definition ID")
is_declared: BoolProperty(name="Is Declared", default=False)
is_appended: BoolProperty(name="Is Appended", default=False)
is_declarable: BoolProperty(
name="Is Declarable",
description="Whether element support being declared as part of IfcProjectLibrary",
default=False,
)
if TYPE_CHECKING:
name: str
ifc_definition_id: int
is_declared: bool
is_appended: bool
is_declarable: bool
class FilterCategory(PropertyGroup):
+2 -4
View File
@@ -24,7 +24,7 @@ import bonsai.tool as tool
from bonsai.bim.helper import prop_with_search
from bpy.types import Panel, Menu, UIList
from bonsai.bim.ifc import IfcStore
from bonsai.bim.module.project.data import ProjectData, LinksData, ProjectLibraryData
from bonsai.bim.module.project.data import ProjectData, LinksData
from typing import TYPE_CHECKING
if TYPE_CHECKING:
@@ -463,9 +463,7 @@ class BIM_UL_library(UIList):
op = row.operator("bim.change_library_element", text="", icon="DISCLOSURE_TRI_RIGHT", emboss=False)
op.element_name = item.name
row.label(text=item.name)
if not ProjectLibraryData.is_loaded:
ProjectLibraryData.load()
if item.ifc_definition_id and ProjectLibraryData.data["project_libraries"]:
if item.ifc_definition_id and item.is_declarable:
if item.is_declared:
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
op.definition = item.ifc_definition_id