Texture Painting

Hey there!

I can’t seem to get Texture Painting to work and can’t find any examples of drawing a dot or a line. I believe it’s something to do with my stroke data. I was able to get Sculpting working with a similar script, and if I change the image tool type in the script below from DRAW to FILL it does fill the object’s texture.

Any ideas what I’m doing wrong?

def context_override():
    for window in bpy.context.window_manager.windows:
        screen = window.screen
        for area in screen.areas:
            if area.type == 'VIEW_3D':
                for region in area.regions:
                    if region.type == 'WINDOW':
                        return {'window': window, 'screen': screen, 'area': area, 'region': region, 'scene': bpy.context.scene} 

bpy.ops.object.mode_set(mode='TEXTURE_PAINT') 
bpy.data.objects['An object'].select_set(True)
bpy.ops.paint.brush_select(image_tool='DRAW')
 
strokes = [{
    "name": "",
    "location": (0, 0, 0),
    "mouse": (0, 0),
    "mouse_event": (0,0),
    "x_tilt": 0,
    "y_tilt": 0,
    "size": 100,
    "pressure": 1,
    "pen_flip": False,
    "time": 0,
    "is_start": True
    }]

bpy.ops.paint.image_paint(context_override(), stroke=strokes)

because you’re not drawing anything- just setting the starting point for your stroke. add more points to your stroke and it will work. FILL works because it only requires the start point to know where to fill.

1 Like

Awesome! Thanks so much Testure. I’ve been fighting with this far longer than I care to admit. I had tried putting in multiple stroke values but they didn’t work like yours did.

Can you give me a quick rundown on how location, mouse, and mouse_event data work together? Or point me to something that describes them more? I just want to stamp the brush like I would if I were texture painting manually and single clicked in one location.

i recently recovered a addon that does a lot of texture painting, maybe it gives you some insight into the painting system