Fix #3120. You can now assign styles to individual items.

This commit is contained in:
Dion Moult
2024-10-09 18:17:12 +11:00
parent d09ab54869
commit 11eb1c26f0
2 changed files with 21 additions and 7 deletions
+17 -7
View File
@@ -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,
+4
View File
@@ -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"):