# Sculpt programatically poll() context is incorrect

**URL:** <https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557>\
**Category:** Python Support\
**Created:** [November 2, 2018, 3:38am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557 "2018-11-02T03:38:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMDBCG](https://blenderartists.org/user_avatar/blenderartists.org/amdbcg/32/4365_2.png) [@AMDBCG](https://blenderartists.org/u/AMDBCG)\
**Post date:** [November 2, 2018, 3:38am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/1 "2018-11-02T03:38:06Z")

</div>

I would like to programatically sculpt to draw a perfect circle on the x/y axis and sculpt it into a dynotopo mesh.  
I found this, but it gives me an error with the bpy.ops:

> def sculptit(self, context, location):  
> tuple\_location = tuple(location.strip(“()”).split(“,”))  
> stroke = [{ “name”: “defaultStroke”,  
> “mouse” : (0.0, 0.0),  
> “pen\_flip” : False,  
> “is\_start”: True,  
> “location”: tuple\_location,  
> “pressure”: 1.0,  
> “time”: 1.0}]  
> #bpy.ops.sculpt.brush\_stroke(stroke=stroke)

error is:  
RuntimeError: Operator bpy.ops.sculpt.brush\_stroke.poll() failed, context is incorrect

I found this:  
[https://docs.blender.org/api/blender\_python\_api\_current/info\_quickstart.html#operator-poll](https://docs.blender.org/api/blender_python_api_current/info_quickstart.html#operator-poll)  
and this:

> <https://blender.stackexchange.com/questions/3619/how-to-cut-a-mesh-into-smaller-pieces-with-python/3623#3623>

neither of which were helpful, I can check that the context is incorrect or I can move the current window to a VIEW\_3D context.  
:\

---

<div class="post-metadata">

**Author:** ![suenteus](https://blenderartists.org/user_avatar/blenderartists.org/suenteus/32/643020_2.png) [@suenteus](https://blenderartists.org/u/suenteus)\
**Post date:** [January 22, 2020, 5:06pm UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/2 "2020-01-22T17:06:54Z")

</div>

Anyone? I’m also having this same problem. As far as I can tell I am in SCULPT mode and yet this error still occurs. Is it a Blender bug?

---

<div class="post-metadata">

**Author:** ![AMDBCG](https://blenderartists.org/user_avatar/blenderartists.org/amdbcg/32/4365_2.png) [@AMDBCG](https://blenderartists.org/u/AMDBCG)\
**Post date:** [January 28, 2020, 6:03am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/3 "2020-01-28T06:03:17Z")

</div>

I asked this at the Blender Conference and just didn’t follow up.

  
I’ll ask on the blender-dev mailing list and post back results here.  
Pablo Dobarro mentioned he has a sculpt mode script that may handle this.

---

<div class="post-metadata">

**Author:** ![Travisty](https://blenderartists.org/user_avatar/blenderartists.org/travisty/32/755139_2.png) [@Travisty](https://blenderartists.org/u/Travisty)\
**Post date:** [January 28, 2020, 7:07am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/4 "2020-01-28T07:07:43Z")

</div>

Here is an example of overriding context for an operator:

```auto
import bpy

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} 
                    
bpy.ops.sculpt.brush_stroke(context_override())

```

---

<div class="post-metadata">

**Author:** ![AMDBCG](https://blenderartists.org/user_avatar/blenderartists.org/amdbcg/32/4365_2.png) [@AMDBCG](https://blenderartists.org/u/AMDBCG)\
**Post date:** [January 29, 2020, 2:32am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/5 "2020-01-29T02:32:10Z")

</div>

```auto
import bpy
import time
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 sculptit( location):
    tuple_location = location#tuple(location[1:-1].split(","))
    stroke = [{ "name": "defaultStroke", 
    "mouse" : (3640, 1303),
    "pen_flip" : False,
    "is_start": True,
    "location": tuple_location,
    "size":100,
    "pressure": 10,
    "time": 1.0}]
    bpy.ops.sculpt.brush_stroke(context_override(),stroke=stroke)
    print("done")

#time.sleep(5)
#bpy.ops.wm.mouse_position('INVOKE_DEFAULT')
sculptit((0,0,0))

```

No error, but that’s if I’m in sculpt mode in the 3d view. It looks like I will have to have a window open for the wm , sculpt, and ops to do their thing. I cannot get a stroke to occur

---

<div class="post-metadata">

**Author:** ![Travisty](https://blenderartists.org/user_avatar/blenderartists.org/travisty/32/755139_2.png) [@Travisty](https://blenderartists.org/u/Travisty)\
**Post date:** [January 29, 2020, 3:15am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/6 "2020-01-29T03:15:42Z")

</div>

In your test case, are you working with the default cube? I see you’re trying to add a stroke at (0,0,0). I’ve never used `bpy.ops.sculpt.brush_stroke` before, but I assume the location would need to be on the surface of a mesh.

Try this:

1. Add and subdivide a cube (Since we’re about to sculpt, we need more detail in our mesh.)  
 ![Selection_127](https://blenderartists.org/uploads/default/original/4X/0/8/3/083f07de8e23195529eec0f95ba0c4dd593a8098.png)
2. Call `sculptit` with a location of `(0,-1,0)` → `sculptit((0,-1,0))`

Here is my result:  
 ![Selection_128](https://blenderartists.org/uploads/default/original/4X/9/2/a/92aac67d9fb2554ef41617d8a4cec103a2965ad2.jpeg)

---

<div class="post-metadata">

**Author:** ![AMDBCG](https://blenderartists.org/user_avatar/blenderartists.org/amdbcg/32/4365_2.png) [@AMDBCG](https://blenderartists.org/u/AMDBCG)\
**Post date:** [January 29, 2020, 3:55am UTC](https://blenderartists.org/t/sculpt-programatically-poll-context-is-incorrect/1132557/7 "2020-01-29T03:55:04Z")

</div>

> [@Travisty](#):
>
> `sculptit((0,-1,0))`

That works! yay! Thanks Travisty!
