I am trying to apply colour to an object with a python script. I have found several other posts that were also struggling with this. However, their solutions didn’t fix my problem. Drawing on the object in 3d View manually works just fine. I am using the function below.
def paint(_PATH_,_SWITCH_):
stroke = [{
"name":"paint",
"mouse":(0,0),
"mouse_event":(0,0),
"x_tilt":0,
"y_tilt":0,
"pen_flip":False,
"is_start":True if _SWITCH_==0 else False,
"pressure": 1.0,
"location":_PATH_,
"size":1.0,
"pressure":1.0,
"time":1.0}]
bpy.ops.paint.image_paint(context_override(), stroke=stroke)
The function is running in a for loop. PATH is a coordinate triple and SWITCH is the current index of the for loop. Before executing this loop I have set the brush strength and radius to maximum and selected the brush by using
bpy.ops.paint.brush_select(image_tool='DRAW',toggle = True)
I am using basically the same setup for sculpting, and it is working perfectly fine. Short note, I must do the painting in 3D View because the UV map of the object is very convoluted.
Long story short, the code compiles with no error messages, but nothing happens.
EDIT: Using fill instead of draw works for some reason.
EDIT: After going through several stages of desperation, I have found something. I used code from another forum post and replicated the setup and was rewarded with a result that confused me even more.
The code is as follows. EDIT: Because I was in a hurry i accidentally copied the wrong code. I have now postet the right code.
def paint_start():
stroke = [{
"name":"stroke",
"mouse":(0,0),
"mouse_event":(0,0),
"x_tilt":0,
"y_tilt":0,
"pen_flip":False,
"is_start":True,
"pressure": 1.0,
"location":(0,0,0),
"size":100.0,
"time":0.0},
{
"name":"stroke",
"mouse":(500,500),
"mouse_event":(500,500),
"x_tilt":0,
"y_tilt":0,
"pen_flip":False,
"is_start":False,
"pressure": 1.0,
"location":(50,50,0),
"size":100.0,
"time":0.0}]
It seems that location is pretty much useless, while mouse or mouse_event are the essential values. Changing the angle in the 3d View will affect the result. Can someone explain how these values and the angle in 3d View lead to the resulting brush stroke?