Added button to update current style #3293

Example - https://i.imgur.com/f4Yi3MR.png
Now changing style type should be a bit more intuitive - previously there were no button and it wasn't possible to change style type for all selected objects / changing style type for the entire scene were hidden in N-panel Miscellaneous section.

Now it also able to change style type for all blender materials, even the ones that don't have any objects using them (wasn't possible before 7c0c934b4)
This commit is contained in:
Andrej730
2023-06-19 10:57:11 +05:00
parent ddef4820d0
commit 6a2bbfa85c
5 changed files with 52 additions and 10 deletions
@@ -30,8 +30,6 @@ class BIM_PT_misc_utilities(bpy.types.Panel):
def draw(self, context):
layout = self.layout
props = context.scene.BIMMiscProperties
row = layout.row()
row.prop(context.scene.BIMStylesProperties, "active_style_type", icon="SHADING_RENDERED", text="")
row = layout.split(factor=0.2, align=True)
row.prop(props, "override_colour", text="")
row.operator("bim.set_override_colour")
@@ -24,6 +24,7 @@ classes = (
operator.EnableEditingStyle,
operator.DisableEditingStyle,
operator.EditStyle,
operator.UpdateCurrentStyle,
operator.EnableEditingExternalStyle,
operator.DisableEditingExternalStyle,
operator.EditExternalStyle,
@@ -107,6 +107,53 @@ class EditStyle(bpy.types.Operator, tool.Ifc.Operator):
core.edit_style(tool.Ifc, tool.Style, obj=context.active_object.active_material)
class UpdateCurrentStyle(bpy.types.Operator):
bl_idname = "bim.update_current_style"
bl_label = "Update Current Style"
bl_description = (
"Update style for all selected objects according to current style type\n(Shading/External).\n\n"
+ "SHIFT+CLICK to update ALL styles in the .ifc file to current style type"
)
bl_options = {"REGISTER", "UNDO"}
update_all: bpy.props.BoolProperty(name="Update All", default=False)
@classmethod
def poll(cls, context):
poll = (
context.active_object is not None
and context.active_object.active_material is not None
and context.active_object.active_material.BIMMaterialProperties.ifc_style_id != 0
)
if not poll:
cls.poll_message_set(
"Object is not selected or material is not assigned or material doesn't have IFC Style"
)
return poll
def invoke(self, context, event):
# updating all styles on shift+click
if event.type == "LEFTMOUSE" and event.shift:
self.update_all = True
else:
# can't rely on default value since the line above
# will set the value to `True` for all future operator calls
self.update_all = False
return self.execute(context)
def execute(self, context):
current_style_type = context.active_object.active_material.BIMStyleProperties.active_style_type
if self.update_all:
context.scene.BIMStylesProperties.active_style_type = current_style_type
return {"FINISHED"}
materials = []
for obj in context.selected_objects:
mat = obj.active_material
if mat and mat.BIMMaterialProperties.ifc_style_id != 0:
mat.BIMStyleProperties.active_style_type = current_style_type
return {"FINISHED"}
class BrowseExternalStyle(bpy.types.Operator):
bl_idname = "bim.browse_external_style"
bl_label = "Browse External Style"
@@ -53,14 +53,9 @@ STYLE_TYPES = [
def update_shading_styles(self, context):
materials_to_objects = dict()
for obj in bpy.data.objects:
blender_material = obj.active_material
if blender_material and blender_material.BIMMaterialProperties.ifc_style_id != 0:
materials_to_objects[blender_material] = obj
for mat, obj in materials_to_objects.items():
for mat in bpy.data.materials:
if mat.BIMMaterialProperties.ifc_style_id == 0:
continue
tool.Style.change_current_style_type(mat, self.active_style_type)
@@ -90,6 +90,7 @@ class BIM_PT_style(MaterialButtonsPanel, Panel):
return
row.prop(style_props, "active_style_type", icon="SHADING_RENDERED", text="")
row.operator("bim.update_current_style", icon="FILE_REFRESH", text="")
row = self.layout.row(align=True)
row.operator("bim.update_style_colours", icon="GREASEPENCIL")
row.operator("bim.update_style_textures", icon="TEXTURE", text="")