blender run python script from button

Solutions on MaxInterview for blender run python script from button by the best coders in the world

showing results for - "blender run python script from button"
Alex
12 Apr 2019
1import bpy
2
3class MatShaderInfoPanel(bpy.types.Panel):
4    """Create shaders for your Poser figure: Panel"""
5    bl_label = "Figure Files Info"
6    bl_idname = "MATERIALS_PT_shaders"
7    bl_space_type = 'VIEW_3D'
8    bl_region_type = 'TOOLS'
9    bl_category = "Skin Shaders"
10
11    def draw(self, context):
12        layout = self.layout
13
14        obj = context.object
15
16        row = layout.row()
17        row.label(text='Figure Name')
18
19        row = layout.row()
20        row.label(text="Active object is: " + obj.name)
21        row = layout.row()
22        row.prop(obj, "name")
23
24        row = layout.row()
25        row.operator("mesh.primitive_cube_add", text='Find Images', icon='FILESEL')
26        row = layout.row()
27        row.operator("object.run_script", text = 'Apply Shaders')
28
29class runScript(bpy.types.Operator):
30    """Tooltip"""
31    # was bl_idname = "object.run_script" - is now:
32    bl_idname = "object.run_script"
33    bl_label = "Invokes a Script"
34
35    @classmethod
36    def poll(cls, context):
37        return context.active_object is not None
38
39    def execute(self, context):
40        print('Yay!')
41
42        return {'FINISHED'}
43
44def register():
45    bpy.utils.register_module(__name__)
46
47def unregister():
48    bpy.utils.unregister_class(__name__)
49
50if __name__ == "__main__":
51    register()
52