Help needed with creating a brush texture slot with python

Hey guys,

For past few days I have been trying to learn scripting in blender, after learning the very basic concept by copy pasting some code I thought about making a simple addon. A addon that allows user to right click on a image in the file browser and set it as the paint brush texture. I managed to get the file path of the image and load it into blender but I cannot create a texture slot for a brush for some reason. I can access existing texture slot and edit its properties but oddly I cannot set a image to it.

bpy.data.textures["mytex"].repeat_y = 69 #this works

bpy.data.textures["mytex"].image = image #this does not work

bpy.data.textures.new("myanothertex", type='IMAGE') #this does not work either

I have been flipping through the api reference for a while and I cannot find anything that would help me. Am I missing something obvious? Please help.

I’m not sure how to proceed here as there is a lot going on in the initial premise to deal with. Maybe you should break it down into smaller bits of code to get things to happen first before trying to go about adding something from a right click. Maybe it would be easier to first get the active image in the Image Editor and send that to the brush texture of the active brush tool. If you can do that, then you can look at other code online to see about the right click menu creation.

The only things that didn’t work are creating texture slots and adding image texture to existing texture slot in python. I got everything else to work, no problem.