diff --git a/src/bonsai/bonsai/bim/module/style/operator.py b/src/bonsai/bonsai/bim/module/style/operator.py index 3bea090594..5c5d9d82d7 100644 --- a/src/bonsai/bonsai/bim/module/style/operator.py +++ b/src/bonsai/bonsai/bim/module/style/operator.py @@ -1053,7 +1053,6 @@ class AssignStyleToSelected(bpy.types.Operator, tool.Ifc.Operator): bl_label = "Assign Style To Selected" bl_description = "Assign style to the selected objects' active representations" bl_options = {"REGISTER", "UNDO"} - style_id: bpy.props.IntProperty(name="Style ID") @classmethod @@ -1069,19 +1068,30 @@ class AssignStyleToSelected(bpy.types.Operator, tool.Ifc.Operator): return {"CANCELLED"} ifc_file = tool.Ifc.get() style = ifc_file.by_id(self.style_id) + material = tool.Ifc.get_object(style) + has_items = False representations: dict[ifcopenshell.entity_instance, bpy.types.Object] = {} for obj in context.selected_objects: - representation = tool.Geometry.get_active_representation(obj) - if not representation: - continue - representation = tool.Geometry.resolve_mapped_representation(representation) - representations.setdefault(representation, obj) + if tool.Geometry.is_representation_item(obj): + has_items = True + item = tool.Ifc.get().by_id(obj.data.BIMMeshProperties.ifc_definition_id) + tool.Style.assign_style_to_representation_item(item, style) + obj.data.materials.clear() + obj.data.materials.append(material) + elif representation := tool.Geometry.get_active_representation(obj): + representation = tool.Geometry.resolve_mapped_representation(representation) + representations.setdefault(representation, obj) - if not representations: + if not has_items and not representations: self.report({"INFO"}, "No IFC objects with representations selected.") return {"FINISHED"} + if has_items: + tool.Geometry.reload_representation(context.scene.BIMGeometryProperties.representation_obj) + bpy.ops.bim.disable_editing_representation_items() + bpy.ops.bim.enable_editing_representation_items() + for representation in representations: ifcopenshell.api.style.assign_representation_styles( ifc_file, diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 00e7d7418b..83b510aa76 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -1513,6 +1513,10 @@ class Geometry(bonsai.core.tool.Geometry): verts = geometry.verts tool.Loader.convert_geometry_to_mesh(geometry, obj.data, verts=verts) + if ios_materials := list(obj.data["ios_materials"]): + material = tool.Ifc.get_object(tool.Ifc.get().by_id(ios_materials[0])) + obj.data.materials.append(material) + obj.matrix_world = rep_obj.matrix_world.copy() if (is_swept_area := item.is_a("IfcSweptAreaSolid")) or item.is_a("IfcConic"):