mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-05 20:06:25 +00:00
Object metadata to double check element belongs to the current project
Just to be safe if it got from other Blender session and there is an IFC element with the same id in the current project. I guess we can't check it anywhere but information in "Object metadata" should very accurate as here user might decide to unlink it.
This commit is contained in:
@@ -23,6 +23,7 @@ import ifcopenshell.util.schema
|
|||||||
from ifcopenshell.util.doc import get_entity_doc, get_predefined_type_doc, get_class_suggestions
|
from ifcopenshell.util.doc import get_entity_doc, get_predefined_type_doc, get_class_suggestions
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -30,6 +31,7 @@ def refresh():
|
|||||||
|
|
||||||
|
|
||||||
class IfcClassData:
|
class IfcClassData:
|
||||||
|
element: Union[ifcopenshell.entity_instance, None] = None
|
||||||
data = {}
|
data = {}
|
||||||
is_loaded = False
|
is_loaded = False
|
||||||
|
|
||||||
@@ -41,6 +43,7 @@ class IfcClassData:
|
|||||||
cls.data["ifc_classes"] = cls.ifc_classes()
|
cls.data["ifc_classes"] = cls.ifc_classes()
|
||||||
cls.data["ifc_classes_suggestions"] = cls.ifc_classes_suggestions() # Call AFTER cls.ifc_classes()
|
cls.data["ifc_classes_suggestions"] = cls.ifc_classes_suggestions() # Call AFTER cls.ifc_classes()
|
||||||
cls.data["contexts"] = cls.contexts()
|
cls.data["contexts"] = cls.contexts()
|
||||||
|
|
||||||
cls.data["has_entity"] = cls.has_entity()
|
cls.data["has_entity"] = cls.has_entity()
|
||||||
cls.data["name"] = cls.name()
|
cls.data["name"] = cls.name()
|
||||||
cls.data["has_inherited_predefined_type"] = cls.has_inherited_predefined_type()
|
cls.data["has_inherited_predefined_type"] = cls.has_inherited_predefined_type()
|
||||||
@@ -147,15 +150,27 @@ class IfcClassData:
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def has_entity(cls):
|
def has_entity(cls) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
try:
|
obj = bpy.context.active_object
|
||||||
return tool.Ifc.get_entity(bpy.context.active_object)
|
cls.element = None
|
||||||
except:
|
if not obj:
|
||||||
pass
|
return
|
||||||
|
|
||||||
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
if not element:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Double check
|
||||||
|
linked_obj = tool.Ifc.get_object(element)
|
||||||
|
if linked_obj != obj:
|
||||||
|
return
|
||||||
|
|
||||||
|
cls.element = element
|
||||||
|
return cls.element
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def name(cls):
|
def name(cls) -> Union[str, None]:
|
||||||
element = tool.Ifc.get_entity(bpy.context.view_layer.objects.active)
|
element = cls.element
|
||||||
if not element:
|
if not element:
|
||||||
return
|
return
|
||||||
name = element.is_a()
|
name = element.is_a()
|
||||||
@@ -165,24 +180,24 @@ class IfcClassData:
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def has_inherited_predefined_type(cls):
|
def has_inherited_predefined_type(cls) -> bool:
|
||||||
element = tool.Ifc.get_entity(bpy.context.view_layer.objects.active)
|
element = cls.element
|
||||||
if not element:
|
if not element:
|
||||||
return
|
return False
|
||||||
if element_type := ifcopenshell.util.element.get_type(element):
|
if element_type := ifcopenshell.util.element.get_type(element):
|
||||||
# Allow for None due to https://github.com/buildingSMART/IFC4.3.x-development/issues/818
|
# Allow for None due to https://github.com/buildingSMART/IFC4.3.x-development/issues/818
|
||||||
return ifcopenshell.util.element.get_predefined_type(element_type) not in ("NOTDEFINED", None)
|
return ifcopenshell.util.element.get_predefined_type(element_type) not in ("NOTDEFINED", None)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ifc_class(cls):
|
def ifc_class(cls) -> Union[str, None]:
|
||||||
element = tool.Ifc.get_entity(bpy.context.view_layer.objects.active)
|
element = cls.element
|
||||||
if element:
|
if element:
|
||||||
return element.is_a()
|
return element.is_a()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_reassign_class(cls):
|
def can_reassign_class(cls) -> bool:
|
||||||
element = tool.Ifc.get_entity(bpy.context.view_layer.objects.active)
|
element = cls.element
|
||||||
if element:
|
if element:
|
||||||
if element.is_a("IfcOpeningElement") or element.is_a("IfcOpeningStandardCase"):
|
if element.is_a("IfcOpeningElement") or element.is_a("IfcOpeningStandardCase"):
|
||||||
return False
|
return False
|
||||||
@@ -191,3 +206,4 @@ class IfcClassData:
|
|||||||
for product in cls.ifc_products():
|
for product in cls.ifc_products():
|
||||||
if element.is_a(product[0]):
|
if element.is_a(product[0]):
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user