I’m working on an addon to display in the tool shelf while in “Texture Paint” mode.
import bpy
class betterPaint(bpy.types.Panel):
bl_label = "Layers"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
#Place Addon in the Texture Paint mode of the Tool Shelf
@classmethod
def poll(cls, context):
return (context.image_paint_object)
def draw(self, context):
layout = self.layout
row = layout.row()
row.operator(<i>"WHAT ARE THINGS THAT CAN GO HERE?"</i>, text = "Add Color", icon='BRUSH_DATA')
row = layout.row()
row.label(text="Add Bump", icon='BRUSH_DATA')
row = layout.row()
row.label(text="Add Specular", icon='BRUSH_DATA')
def register():
bpy.utils.register_class(betterPaint)
def unregister():
bpy.utils.unregister_class(betterPaint)
if __name__ == "__main__":
register()
Where I have “What are things that can go here”, does anyone know of a list which specifies my options here? Or how might I call a function here that I write somewhere else in my code? I’m just a little confused as to what the parameters are here.
You need to wrap custom functions with an operator in order to create a button in UI the user can click to run your function.
It could look like this:
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "object.simple_operator"
bl_label = "Simple Object Operator"
# SOME PRE-CONDITION, operator can only be run if poll() returns True.
@classmethod
def poll(cls, context):
return context.active_object is not None
def execute(self, context):
call_your_function_here(context) # ... and pass the context for instance
return {'FINISHED'}
Don’t forget to register the operator. You can usually use the following at the bottom of your script:
Thanks CoDEManX. I’ve read that tutorial and several others, several times. I’m just having a hard time digesting everything and remembering things to apply them relevantly to other things. I greatly appreciate your help.
Just a quick conclusion. My real trouble here was figuring out how to attach the commands I could syphon from the Python tool tips and the Info window and stack rather liberally under the single line “import bpy” while in the text editor and run them, to panel menus and tool options. As CoDEmanX explained the same type of classes you can use to draw panels and menus into Blender’s UI you can also use to define operators where you can syphon and stack all the commands you want and then place their operator name inside the main Class you’re using to draw your toolbar or panel.