How do I pass coordinates to the sculpt brush operator?

I’m trying to use bpy.ops.sculpt.brush_stroke(), but I need to be able to pass coordinates to the operator. Taking a cue from this docs page, what do I need to pass to the “stroke” argument to get it to perform a stroke at a given location?

I’m just shooting in the dark here, just passing whatever to it, trying to get errors that’ll clue me in to what I’m supposed to be doing, but I don’t really understand what this error is telling me:

Traceback (most recent call last):... 
line 188, in __call__
ret = op_call(self.idname_py(), None, kw)
TypeError: Converting py args to operator properties:  SCULPT_OT_brush_stroke.stroke expected a each sequence member to be a dict for an RNA collection, not bool


location: <unknown location>:-1

Hi ohsnap,

You need to pass a collection of http://www.blender.org/documentation/blender_python_api_2_69_7/bpy.types.OperatorStrokeElement.html?highlight=operatorstrokeelement#bpy.types.OperatorStrokeElement types to the stroke parameter. From experience with OperatorFileListELemnets I’d say the method is something like



stroke = [{ "is_start": True,
            "location": (1.0, 1.0, 1.0),
            "pressure": 0.4,
            "time": 2.0},
            
           {"location":(1.0, 2.0, 1.0),
            "pressure":0.5,
            "time":3.0
            }
            ]
            
bpy.ops.sculpt.brush_stroke(stroke=stroke) 

where you make dictionary elements to emulate the OperatorStrokeElement and pass those in a list to emulate the collection.

You will need to be in sculpt mode, or pass a first parameter to the op with a context dictionary to over-ride context.

1 Like

Thanks batFINGER, I’ll try that.

Thanks for the tip! It needed more items, when I tried it:

stroke = [{ "name": "defaultStroke",
                            "mouse" : (0.0, 0.0),
                            "pen_flip" : False,
                            "is_start": True,
                            "location": (x, y, z),
                            "pressure": 1.0,
                            "time": 1.0}]

Solved!