Fix missing IFC descriptions for already added pset props

Example - https://files.catbox.moe/dg1mzk.png
This commit is contained in:
Andrej730
2025-09-02 16:44:25 +05:00
parent ed37ac3066
commit df4f565176
3 changed files with 31 additions and 5 deletions
+7 -1
View File
@@ -296,7 +296,13 @@ def add_attribute_enum_items_descriptions(
new_enum_description.name = description
def add_attribute_description(attribute_blender: bonsai.bim.prop.Attribute, attribute_ifc=None):
def add_attribute_description(
attribute_blender: bonsai.bim.prop.Attribute,
attribute_ifc: Union[ifcopenshell.entity_instance, None] = None,
) -> None:
"""
:param attribute_ifc: IFC Entity to use as a fallback source of description (using "Description" attribute).
"""
if not attribute_blender.name:
return
version = tool.Ifc.get_schema()
+1 -1
View File
@@ -87,7 +87,7 @@ def enable_pset_editing(
has_template = False
if pset:
pset_tool.import_pset_from_existing(pset, props)
pset_tool.import_pset_from_existing(pset, props, pset_template)
pset_tool.set_active_pset(props, pset, has_template)
else:
pset_tool.enable_proposed_pset(props, pset_name, pset_type, has_template)
+23 -3
View File
@@ -30,6 +30,7 @@ from typing import Union, Literal, Any, TYPE_CHECKING, assert_never
if TYPE_CHECKING:
from bonsai.bim.prop import Attribute
from bonsai.bim.module.pset.prop import (
PsetProperties,
GlobalPsetProperties,
@@ -171,8 +172,16 @@ class Pset(bonsai.core.tool.Pset):
return special_type
@classmethod
def import_pset_from_existing(cls, pset: ifcopenshell.entity_instance, props: PsetProperties) -> None:
pset_props = []
def import_pset_from_existing(
cls,
pset: ifcopenshell.entity_instance,
props: PsetProperties,
pset_template: Union[ifcopenshell.entity_instance, None],
) -> None:
"""
:param pset_template: Pset Template to use as a source for descriptions.
"""
pset_props: tuple[ifcopenshell.entity_instance, ...] = ()
if pset.is_a("IfcElementQuantity"):
pset_props = pset.Quantities
elif pset.is_a("IfcPropertySet"):
@@ -180,6 +189,16 @@ class Pset(bonsai.core.tool.Pset):
elif pset.is_a("IfcMaterialProperties") or pset.is_a("IfcProfileProperties"):
pset_props = pset.Properties
prop_templates: dict[str, ifcopenshell.entity_instance] = {}
if pset_template:
prop_templates = {prop.Name: prop for prop in pset_template.HasPropertyTemplates}
def process_prop_description(metadata: Attribute) -> None:
prop_name = metadata.name
if prop_name not in prop_templates:
return
bonsai.bim.helper.add_attribute_description(metadata, prop_templates[prop_name])
for prop in sorted(pset_props, key=lambda p: p.Name):
if props.properties.get(prop.Name):
continue # This property has already been added from a template
@@ -230,6 +249,7 @@ class Pset(bonsai.core.tool.Pset):
metadata.is_optional = True
metadata.special_type = cls.get_special_type_for_prop(prop)
metadata.set_value(metadata.get_value_default() if metadata.is_null else value)
process_prop_description(metadata)
@classmethod
def get_prop_template_primitive_type(cls, prop_template: ifcopenshell.entity_instance) -> str:
@@ -333,7 +353,7 @@ class Pset(bonsai.core.tool.Pset):
# For every prop we first ensure that existing prop value type matches the template value type
# to prevent data loss and error casting data.
# Property will be added later by import_pset_from_existing.
# Existing property will be added later by import_pset_from_existing.
for prop_template in sorted(pset_template.HasPropertyTemplates, key=lambda p: p.Name):
if (
not prop_template.is_a("IfcSimplePropertyTemplate")