diff --git a/src/bonsai/bonsai/tool/system.py b/src/bonsai/bonsai/tool/system.py index 519136a1f8..38a93a3649 100644 --- a/src/bonsai/bonsai/tool/system.py +++ b/src/bonsai/bonsai/tool/system.py @@ -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) diff --git a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py index 893b32cc02..0b703b6064 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py +++ b/src/ifcopenshell-python/ifcopenshell/api/project/append_asset.py @@ -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"):