diff --git a/src/blenderbim/blenderbim/bim/module/material/operator.py b/src/blenderbim/blenderbim/bim/module/material/operator.py index b41a862252..32723ed46b 100644 --- a/src/blenderbim/blenderbim/bim/module/material/operator.py +++ b/src/blenderbim/blenderbim/bim/module/material/operator.py @@ -728,6 +728,20 @@ class EnableEditingMaterialStyle(bpy.types.Operator, tool.Ifc.Operator): props.active_material_id = self.material props.editing_material_type = "STYLE" + # set already applied style and context if possible + if not 0 <= props.active_material_index < len(props.materials): + return + + material = tool.Ifc.get().by_id(props.materials[props.active_material_index].ifc_definition_id) + if not material.HasRepresentation: + return + + rep = material.HasRepresentation[0].Representations[0] # IfcStyledRepresentation + props.contexts = str(rep.ContextOfItems.id()) + style = rep.Items[0].Styles[0] + if style.Name: # props.styles only has named styles + props.styles = str(rep.Items[0].Styles[0].id()) + class EditMaterialStyle(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.edit_material_style" diff --git a/src/blenderbim/blenderbim/bim/module/material/ui.py b/src/blenderbim/blenderbim/bim/module/material/ui.py index 3a755a9413..d609c9d201 100644 --- a/src/blenderbim/blenderbim/bim/module/material/ui.py +++ b/src/blenderbim/blenderbim/bim/module/material/ui.py @@ -81,6 +81,8 @@ class BIM_PT_materials(Panel): self.layout.template_list("BIM_UL_materials", "", self.props, "materials", self.props, "active_material_index") + # TODO: data.py is not updated on changing active_material_index + # so the active material styles go out of sync with the active material for style in MaterialsData.data["active_styles"]: row = self.layout.row(align=True) row.label(text="", icon="SHADING_RENDERED")