I want create simple button.

class Interactive_mask(bpy.types.Operator):
    def execute(self, context):
        bpy.ops.sculpt.mask_expand(invert=True, smooth_iterations=2, use_normals=False, keep_previous_mask=False,)
        return {'FINISHED'} 

And I have problem with bpy.ops.sculpt.mask_expand When I press my button i have such a error RuntimeError: Operator bpy.ops.sculpt.mask_expand()failed, context is incorrect What I should change or add to code ?


Not in sculpt mode.

Result in python console of changing absolute mode of object to 'SCULPT' followed by toggling mode

>>> bpy.ops.object.mode_set(mode='SCULPT')

>>> bpy.ops.sculpt.sculptmode_toggle()

>>> C.mode

hence out of context, since bpy.ops.sculpt.* operators require sculpt mode for context.

Remove toggle to remain in sculpt mode or move to the last line to toggle.


Making a poll method for your operator returning false for selected objects that cannot be sculpted will disable button in UI and remove it from context operator search.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.