I can Sculpt using Python but am having trouble getting Texture Painting to work.
Here is a working example of Sculpting:
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}
def sculpt(coordinates, brush = 'DRAW', strength=1):
bpy.ops.paint.brush_select(sculpt_tool=brush, toggle=False)
brush = bpy.data.brushes["SculptDraw"]
brush.strength = strength
bpy.context.tool_settings.sculpt.brush = brush
bpy.context.tool_settings.unified_paint_settings.unprojected_radius = 0.2
strokes = []
for i, coordinate in enumerate(coordinates):
stroke = {
"name": "stroke",
"mouse": (0,0),
"mouse_event": (0,0),
"x_tilt": 0,
"y_tilt": 0,
"pen_flip" : False,
"is_start": True if i==0 else False,
"location": coordinate,
"size": 10,
"pressure": 1,
"time": float(i)
}
strokes.append(stroke)
bpy.ops.sculpt.brush_stroke(context_override(), stroke=strokes)
points = [(0,0,0)]
bpy.ops.object.mode_set(mode='SCULPT')
bpy.data.objects['An Object'].select_set(True)
sculpt(points)
This however does not work for Texture Painting:
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}
def paint(coordinates, brush = 'DRAW', strength=1):
bpy.ops.paint.brush_select(image_tool=brush, toggle=False)
brush = bpy.data.brushes["Brush"]
brush.strength = strength
bpy.context.tool_settings.image_paint.brush = brush
bpy.context.tool_settings.unified_paint_settings.size = 100
strokes = []
for i, coordinate in enumerate(coordinates):
stroke = {
"name": "stroke",
"mouse": (0,0),
"mouse_event": (0,0),
"x_tilt": 0,
"y_tilt": 0,
"pen_flip" : False,
"is_start": True if i==0 else False,
"location": coordinate,
"size": 10,
"pressure": 1,
"time": float(i)
}
strokes.append(stroke)
bpy.ops.paint.image_paint(context_override(), stroke=strokes)
points = [(0,0,0)]
bpy.ops.object.mode_set(mode='TEXTURE_PAINT')
bpy.data.objects['An Object'].select_set(True)
paint(points)
What am I missing?