Make an operator
For the most part a button in blender calls an operator.
Using the simple operator template, here is a quick edit to hardcode in some settings.
- I have made the operator poll only in the 3d view area.
- Haven't sanitized name.
Since your addon panel also resides in this area, it is simply a matter of adding
self.layout.operator("object.simple_operator")
into your panel's draw method.
import bpy
def main(context):
space = context.space_data
space.shading.light = 'MATCAP'
space.shading.color_type = 'SINGLE'
space.shading.show_xray = False
space.shading.show_cavity = True
space.shading.show_object_outline = False
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
@classmethod
def poll(cls, context):
return context.area.type == 'VIEW_3D'
def execute(self, context):
main(context)
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
Further to this, for saving multiple settings
- there is the preset system for saving an operators, or some tools settings to a text file. How to use presets for operator properties?
- A collection of settings can be defined as a property group. Multiple can be saved as a
CollectionPropery the "current" as a PointerProperty