1

Refactoring this post to simplify the request:

I need to draw a straight line/continuous Stroke in Python with Texture Paint. Unfortunately it is currently only placing a single dot at either end of the stroke.

Desired Outcome:

enter image description here

Current Code does this:

enter image description here

Tried:

  • Using "location" & "mouse_event" instead of mouse
  • Making "name" unique
  • Using different Stroke settings in Texture Paint (like Line)
  • UV unwrapping
  • Every combination of "is_start" for each stroke

I've seen multiple posts about this with no solutions, is bpy.ops.paint.image_paint just broken?

Code:

import bpy

x1 = 500 x2 = 800

the line should be horizontal, ie 500-800px

strokes = [{"name": "", "is_start": True, "location": (0,0,0), "mouse":(x1, 500), "mouse_event":(0,0), "pen_flip":False, "pressure":1.0, "size":10, "time":0, "x_tilt":0.0, "y_tilt":0.0},

{"name": "",
"is_start": False,
"location": (0,0,0),
"mouse":(x2, 500),
"mouse_event":(0,0),
"pen_flip":False,
"pressure":1.0,
"size":10,
"time":0,
"x_tilt":0.0,
"y_tilt":0.0}]  

bpy.ops.object.mode_set(mode='TEXTURE_PAINT')

areas = [area for area in bpy.context.window.screen.areas if area.type == 'VIEW_3D']

with bpy.context.temp_override( window=bpy.context.window, area=areas[0], region=[region for region in areas[0].regions if region.type == 'WINDOW'][0], screen=bpy.context.window.screen ): bpy.ops.paint.brush_select(vertex_tool="DRAW", toggle=False) bpy.ops.paint.image_paint(stroke=strokes)

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
nytemairqt
  • 21
  • 4
  • I'm on Blender 3.6 and nothing happens. Are you sure your code works? the bpy.ops statement will even error out as poll context fail. so i updated it to be executed in the right context. it runs without errors now but nothing happens. Not even a dot gets painted. – Harry McKenzie Aug 09 '23 at 14:17
  • thanks for adding the context override, i was in the middle of adding it but you were faster ;)

    the rest should work, it works on my end (it's an operator in a bigger addon), i just don't understand why it doesn't paint a continuous line, i've tried in 3.3 and 3.6

    edit: try adding a plane, and zooming in so the plane covers the full 3d view, then try running the operator, since it's using fixed x/y values if you're zoomed out it might be "missing" the mesh

    – nytemairqt Aug 09 '23 at 14:17
  • oooh ok. cool now i see the 2 dots drawn. now something i can work on. – Harry McKenzie Aug 09 '23 at 14:20
  • sweet, i appreciate you taking the time! – nytemairqt Aug 09 '23 at 14:21

1 Answers1

0

I think it's not the way it works where we expected it to fill the gap. You have to manually define the points where a stroke will be applied:

import bpy

points = []

for i in range(0,800): points.append((i*6,500))

strokes = [] for i, point in enumerate(points): stroke = { "name": "", "is_start": True, "location": (0, 0, 0), "mouse": point, "mouse_event": (0, 0), "pen_flip": False, "pressure": 1.0, "size": 10, "time": 0, "x_tilt": 0.0, "y_tilt": 0.0 } strokes.append(stroke)

bpy.ops.object.mode_set(mode='TEXTURE_PAINT')

areas = [area for area in bpy.context.window.screen.areas if area.type == 'VIEW_3D']

with bpy.context.temp_override( window=bpy.context.window, area=areas[0], region=[region for region in areas[0].regions if region.type == 'WINDOW'][0], screen=bpy.context.window.screen ): bpy.ops.paint.brush_select(image_tool="DRAW", toggle=False) bpy.ops.paint.image_paint(stroke=strokes)

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
  • damn unfortunately to get a rectangle I'd have to call this line operator with a 1px size a few hundred times using a nested loop and it's just extremely slow, I was hoping Blender had a way to draw the strokes continuously

    i appreciate your help anyway!

    – nytemairqt Aug 09 '23 at 15:19
  • but im not 100% sure if there is another way, there is unfortunately not enough documentation on this. – Harry McKenzie Aug 09 '23 at 15:21
  • 1
    ill dig into the source a bit and see if there's anything but I don't have high hopes considering the previous posts asking similar questions – nytemairqt Aug 09 '23 at 15:24