Page MenuHome

Python method Set Pivot to unmasked has no effect
Closed, ResolvedPublicBUG

Description

System Information
Operating system: Win 10
Graphics card: NVidia GTX 1060

Blender Version
2.83 Master

Short description of error
I call this line of Python code in the invoke method of an operator in sculpt mode, the move tool is selected:

bpy.ops.sculpt.set_pivot_position(mode='UNMASKED')

But the gizmo doesnt move to the unmasked area of the mesh. When I do the same operation using the UI (Toolbar: Set Pivot) it works.

I debugged the Blender code and the function

static int sculpt_set_pivot_position_invoke(bContext *C, wmOperator *op, const wmEvent *event)

isn't executed for the Python call.

Operators like the mask_flood_fill can be called for they have exec-API callback - does set_pivot_position need an exec-callback as well so that it can be called by Python?

Event Timeline

Germano Cavalcante (mano-wii) changed the task status from Needs Triage to Needs Information from User.Feb 17 2020, 2:07 PM

We require steps to reproduce the problem.
This facilitates the investigation process.

@Germano Cavalcante (mano-wii)

  1. Go to sculpt mode, remesh a cube to increase the resolution
  2. Add a simple mask with the mask brush, invert the mask
  3. Select the move tool/brush
  4. open a Python console and type in
bpy.ops.sculpt.set_pivot_position(mode='UNMASKED')

to invoke the set_pivot_position operator

Nothing happens, it is not invoked.

Germano Cavalcante (mano-wii) changed the task status from Needs Information from User to Needs Triage.Feb 17 2020, 7:55 PM
Jacques Lucke (JacquesLucke) changed the task status from Needs Triage to Needs Information from User.Feb 18 2020, 1:11 PM

It seems to work when you do this: bpy.ops.sculpt.set_pivot_position('INVOKE_DEFAULT', mode='UNMASKED'). Does this solve your issue?

The problem is that this operator does not have an exec callback.
You can work around the problem by specifying the context 'INVOKE_DEFAULT'.
https://docs.blender.org/api/current/bpy.ops.html#execution-context

Thanks for the report, but this is not considered a bug. Closing as this bug tracker is only for bugs and errors.

For user requests and feedback, please use other channels: https://wiki.blender.org/wiki/Communication/Contact#User_Feedback_and_Requests

Brecht Van Lommel (brecht) reopened this task as Confirmed.Feb 18 2020, 1:37 PM

I consider this a bug, there's no way a user of the Python API can know this without looking at the source code.

It should call invoke instead of exec automatically in this case.

Brecht Van Lommel (brecht) changed the subtype of this task from "Report" to "Bug".Feb 18 2020, 1:39 PM

This operator could also get an exec callback, there's only very few types of operators that need only invoke and no exec.

@Jacques Lucke (JacquesLucke) Basically yes, but then we have two possibilities: The API documentation has to be changed, or the first parameter has to be used internally - I guess the second solution is better cause other Python method calls don't need this parameter either.

Or even better, as I mentioned in the issue, the operator should get an exec-API callback.

I'll put the code in the exec method and pass the mouse position from invoke to exec using new properties on the operator.

@Jacques Lucke (JacquesLucke) : Ok, just to let you know, I applied the diff, compiled and it works in my operator and from the Python Console as well.