mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 06:21:40 +00:00
Hide assign/unassign library declaration button for elements that cannot be declared
E.g. IfcMaterials, IfcProfileDefs
This commit is contained in:
@@ -271,10 +271,21 @@ class ChangeLibraryElement(bpy.types.Operator):
|
|||||||
new.name = name
|
new.name = name
|
||||||
new.ifc_definition_id = ifc_definition_id
|
new.ifc_definition_id = ifc_definition_id
|
||||||
element = self.library_file.by_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
|
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
|
new.is_declared = True
|
||||||
|
|
||||||
|
# is_appended.
|
||||||
try:
|
try:
|
||||||
if element.is_a("IfcMaterial"):
|
if element.is_a("IfcMaterial"):
|
||||||
next(e for e in self.file.by_type("IfcMaterial") if e.Name == name)
|
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")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
is_declared: BoolProperty(name="Is Declared", default=False)
|
is_declared: BoolProperty(name="Is Declared", default=False)
|
||||||
is_appended: BoolProperty(name="Is Appended", 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:
|
if TYPE_CHECKING:
|
||||||
name: str
|
name: str
|
||||||
ifc_definition_id: int
|
ifc_definition_id: int
|
||||||
is_declared: bool
|
is_declared: bool
|
||||||
is_appended: bool
|
is_appended: bool
|
||||||
|
is_declarable: bool
|
||||||
|
|
||||||
|
|
||||||
class FilterCategory(PropertyGroup):
|
class FilterCategory(PropertyGroup):
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import bonsai.tool as tool
|
|||||||
from bonsai.bim.helper import prop_with_search
|
from bonsai.bim.helper import prop_with_search
|
||||||
from bpy.types import Panel, Menu, UIList
|
from bpy.types import Panel, Menu, UIList
|
||||||
from bonsai.bim.ifc import IfcStore
|
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
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
if 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 = row.operator("bim.change_library_element", text="", icon="DISCLOSURE_TRI_RIGHT", emboss=False)
|
||||||
op.element_name = item.name
|
op.element_name = item.name
|
||||||
row.label(text=item.name)
|
row.label(text=item.name)
|
||||||
if not ProjectLibraryData.is_loaded:
|
if item.ifc_definition_id and item.is_declarable:
|
||||||
ProjectLibraryData.load()
|
|
||||||
if item.ifc_definition_id and ProjectLibraryData.data["project_libraries"]:
|
|
||||||
if item.is_declared:
|
if item.is_declared:
|
||||||
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
|
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||||
op.definition = item.ifc_definition_id
|
op.definition = item.ifc_definition_id
|
||||||
|
|||||||
Reference in New Issue
Block a user