0
$\begingroup$

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.

Here you can see the angle and zoom that influenced the result.

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?

$\endgroup$

1 Answer 1

0
$\begingroup$

Ok, I think I understand how this works. When I used this method for sculpting, I only used "location" and ignored the rest. For painting you can discard location and as far as i can tell "mouse_event" as well. To specify the location for painting the "mouse" value is used. The vector passed to mouse refers to the cursor position in the 3d View based on a 2D coordinate system where (0,0) is the bottom left corner and around (720,720) is the top right corner. So to paint with the python API one has to adjust the angle and distance with which the object is spectated(I will just use the camera view to do this).

I hope this can help others to use the API for painting.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .