import IfcDistributionPorts with assets when executing append_library_element and for type products, use the type product's collection, not the container

This commit is contained in:
falken10vdl
2026-01-09 17:11:02 +01:00
parent ed7ae0da9c
commit c41496a9c3
2 changed files with 22 additions and 6 deletions
+16 -5
View File
@@ -218,11 +218,22 @@ class System(bonsai.core.tool.System):
ifc_importer.process_context_filter()
ifc_importer.create_generic_elements(set(ports_to_create))
container = ifcopenshell.util.element.get_container(element)
if container:
collection = tool.Blender.get_object_bim_props(tool.Ifc.get_object(container)).collection
ifc_importer.collections[container.GlobalId] = collection
ifc_importer.place_objects_in_collections()
if element.is_a("IfcTypeProduct"):
target_collection = None
for collection in obj.users_collection:
target_collection = collection
break
if target_collection:
for port_obj in ifc_importer.added_data.values():
if isinstance(port_obj, bpy.types.Object):
tool.Collector.link_collection_object_safe(target_collection, port_obj)
else:
container = ifcopenshell.util.element.get_container(element)
if container:
collection = tool.Blender.get_object_bim_props(tool.Ifc.get_object(container)).collection
ifc_importer.collections[container.GlobalId] = collection
ifc_importer.place_objects_in_collections()
for port_obj in ifc_importer.added_data.values():
assert isinstance(port_obj, bpy.types.Object)
@@ -381,6 +381,7 @@ class Usecase:
def append_type_product(self):
self.whitelisted_inverse_attributes = {
"IfcObjectDefinition": ["HasAssociations"],
"IfcDistributionElementType": ["IsNestedBy"],
self.base_material_class: ["HasExternalReferences", "HasProperties", "HasRepresentation"],
"IfcRepresentationItem": ["StyledByItem", "LayerAssignment"],
"IfcRepresentation": ["LayerAssignments"],
@@ -397,6 +398,7 @@ class Usecase:
"IfcObjectDefinition": ["HasAssociations"],
"IfcObject": ["IsDefinedBy.IfcRelDefinesByProperties"],
"IfcElement": ["HasOpenings"],
"IfcDistributionElement": ["IsNestedBy"],
self.base_material_class: ["HasExternalReferences", "HasProperties", "HasRepresentation"],
"IfcRepresentationItem": [
"StyledByItem",
@@ -488,7 +490,8 @@ class Usecase:
attribute_class = None
if "." in attribute:
attribute, attribute_class = attribute.split(".")
for inverse in getattr(element, attribute, []):
inverse_values = getattr(element, attribute, [])
for inverse in inverse_values:
if attribute_class and inverse.is_a(attribute_class):
self.add_inverse_element(inverse)
elif not attribute_class:
@@ -569,6 +572,8 @@ class Usecase:
return False
elif element.is_a("IfcRoot") and self.by_guid(element.GlobalId) is not None:
return False
elif element.is_a("IfcDistributionPort"):
return False
elif element.is_a(self.target_class):
return True
elif self.target_class == "IfcProduct" and element.is_a("IfcTypeProduct"):