mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 05:46:51 +00:00
Implement support for removing styles. See #1557.
This commit is contained in:
@@ -4,6 +4,7 @@ from . import ui, operator
|
||||
classes = (
|
||||
operator.AddStyle,
|
||||
operator.EditStyle,
|
||||
operator.RemoveStyle,
|
||||
operator.UnlinkStyle,
|
||||
ui.BIM_PT_style,
|
||||
)
|
||||
|
||||
@@ -29,13 +29,32 @@ class EditStyle(bpy.types.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
material = bpy.data.objects.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
settings = get_colour_settings(material)
|
||||
settings["style"] = self.file.by_id(material.BIMMaterialProperties.ifc_style_id)
|
||||
ifcopenshell.api.run("style.edit_style", self.file, **settings)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RemoveStyle(bpy.types.Operator):
|
||||
bl_idname = "bim.remove_style"
|
||||
bl_label = "Remove Style"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
material: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
return IfcStore.execute_ifc_operator(self, context)
|
||||
|
||||
def _execute(self, context):
|
||||
self.file = IfcStore.get_file()
|
||||
material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
ifcopenshell.api.run(
|
||||
"style.remove_style", self.file, style=self.file.by_id(material.BIMMaterialProperties.ifc_style_id)
|
||||
)
|
||||
material.BIMMaterialProperties.ifc_style_id = 0
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AddStyle(bpy.types.Operator):
|
||||
bl_idname = "bim.add_style"
|
||||
bl_label = "Add Style"
|
||||
@@ -50,9 +69,9 @@ class AddStyle(bpy.types.Operator):
|
||||
material = bpy.data.materials.get(self.material) if self.material else bpy.context.active_object.active_material
|
||||
settings = get_colour_settings(material)
|
||||
settings["name"] = material.name
|
||||
settings["external_definition"] = None # TODO: Implement. See #1222
|
||||
settings["external_definition"] = None # TODO: Implement. See #1222
|
||||
style = ifcopenshell.api.run("style.add_style", self.file, **settings)
|
||||
material.BIMMaterialProperties.ifc_style_id = int(style.id())
|
||||
material.BIMMaterialProperties.ifc_style_id = style.id()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
|
||||
@@ -24,5 +24,7 @@ class BIM_PT_style(Panel):
|
||||
row.operator("bim.edit_style", icon="GREASEPENCIL")
|
||||
op = row.operator("bim.unlink_style", icon="UNLINKED", text="")
|
||||
op.material = context.active_object.active_material.name
|
||||
op = row.operator("bim.remove_style", icon="X", text="")
|
||||
op.material = context.active_object.active_material.name
|
||||
else:
|
||||
row.operator("bim.add_style", icon="ADD")
|
||||
|
||||
Reference in New Issue
Block a user