mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 22:31:55 +00:00
BBIM - update related representations on assigning style to material
This commit is contained in:
@@ -750,14 +750,14 @@ class EditMaterialStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = bpy.context.scene.BIMMaterialProperties
|
props = bpy.context.scene.BIMMaterialProperties
|
||||||
material = tool.Ifc.get().by_id(props.active_material_id)
|
ifc_file = tool.Ifc.get()
|
||||||
style = tool.Ifc.get().by_id(int(props.styles))
|
material = ifc_file.by_id(props.active_material_id)
|
||||||
context = tool.Ifc.get().by_id(int(props.contexts))
|
style = ifc_file.by_id(int(props.styles))
|
||||||
ifcopenshell.api.run(
|
context = ifc_file.by_id(int(props.contexts))
|
||||||
"style.assign_material_style", tool.Ifc.get(), material=material, style=style, context=context
|
ifcopenshell.api.run("style.assign_material_style", ifc_file, material=material, style=style, context=context)
|
||||||
)
|
|
||||||
tool.Material.disable_editing_material()
|
tool.Material.disable_editing_material()
|
||||||
core.load_materials(tool.Material, props.material_type)
|
core.load_materials(tool.Material, props.material_type)
|
||||||
|
tool.Material.update_elements_using_material(material)
|
||||||
|
|
||||||
|
|
||||||
class UnassignMaterialStyle(bpy.types.Operator, tool.Ifc.Operator):
|
class UnassignMaterialStyle(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -776,3 +776,4 @@ class UnassignMaterialStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
"style.unassign_material_style", tool.Ifc.get(), material=material, style=style, context=context
|
"style.unassign_material_style", tool.Ifc.get(), material=material, style=style, context=context
|
||||||
)
|
)
|
||||||
core.load_materials(tool.Material, props.material_type)
|
core.load_materials(tool.Material, props.material_type)
|
||||||
|
tool.Material.update_elements_using_material(material)
|
||||||
|
|||||||
@@ -223,3 +223,16 @@ class Material(blenderbim.core.tool.Material):
|
|||||||
assinged_material = cls.get_material(element)
|
assinged_material = cls.get_material(element)
|
||||||
material_profile = tool.Ifc.run("material.add_profile", profile_set=assinged_material, material=material)
|
material_profile = tool.Ifc.run("material.add_profile", profile_set=assinged_material, material=material)
|
||||||
return material_profile
|
return material_profile
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def update_elements_using_material(cls, material):
|
||||||
|
# update elements that are using this material
|
||||||
|
elements = ifcopenshell.util.element.get_elements_by_material(tool.Ifc.get(), material)
|
||||||
|
# filter only unique representations to avoid reloading same representations multiple times
|
||||||
|
meshes_to_objects = dict()
|
||||||
|
for e in elements:
|
||||||
|
obj = tool.Ifc.get_object(e)
|
||||||
|
mesh = obj.data
|
||||||
|
meshes_to_objects[mesh] = obj
|
||||||
|
for obj in meshes_to_objects.values():
|
||||||
|
tool.Geometry.reload_representation(obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user