Maniphest T76324

Face sets operators not working from python console
Closed, Resolved

Assigned To
Richard Antalik (ISS)
Authored By
dan grauer (kromar)
May 2 2020, 11:54 AM
Tags
  • BF Blender
Subscribers
Ankit Meel (ankitm)
Brecht Van Lommel (brecht)
dan grauer (kromar)
Richard Antalik (ISS)
Rodger Davis (RodDavis)

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: Radeon (TM) RX 480 Graphics ATI Technologies Inc. 4.5.13587 Core Profile Context 20.4.2 26.20.15029.27016

Blender Version
Broken: version: 2.90 (sub 0), branch: master, commit date: 2020-05-01 21:55, hash: rB83304e4c221b
Worked: (newest version of Blender that worked as expected)

Short description of error
i tried to apply face sets via a addon and noticed that when i run any of the face sets operators it does nothing. i then tried to run them from the python console within blender and it just returns a {PASS_THROUGH} but nothing is applied to the model.

Exact steps for others to reproduce the error

  1. add suzanne to your scene and make sure its active
  2. enter sculpt mode
  3. use the Face Maps > Init Faces Set > By Loose parts

  1. note how all loose parts get a face set, this is what is expected.

  1. now undo the face sets again and try the same via the python console
  2. go to the python console and enter
bpy.ops.sculpt.face_sets_init(mode='LOOSE_PARTS')
  1. i would expect the same result but instead nothing happens and no face sets are created

Revisions and Commits

rB Blender

Event Timeline

dan grauer (kromar) created this task.May 2 2020, 11:54 AM
dan grauer (kromar) updated the task description.
dan grauer (kromar) updated the task description.May 2 2020, 11:57 AM
Ankit Meel (ankitm) added a subscriber: Ankit Meel (ankitm).May 2 2020, 12:18 PM

i would expect the same result but instead nothing happens and no face sets are created

https://docs.blender.org/api/current/bpy.ops.sculpt.html
Is that supported by the API ?

Also, since you asked it on support channel, I'm tempted to close it as support request.

Rodger Davis (RodDavis) added a subscriber: Rodger Davis (RodDavis).May 2 2020, 4:55 PM

https://docs.blender.org/api/2.83/bpy.ops.sculpt.html

Facesets should be supported in the 2.83 api. I'm guessing there is something stopping it for the time being.

Richard Antalik (ISS) added a subscriber: Richard Antalik (ISS).May 4 2020, 9:47 AM

@dan grauer (kromar) I think what you need to do is override context of operator. It is probably "confused" by instruction to select face masks in console https://docs.blender.org/api/current/bpy.ops.html#overriding-context

Richard Antalik (ISS) changed the task status from Needs Triage to Needs Information from User.May 4 2020, 9:50 AM

I will change status and ask you to check if my info helped you to resolve this issue

dan grauer (kromar) added a comment.May 4 2020, 6:16 PM

@Richard Antalik (ISS)
i was looking into the context and when i print the mode and the active obejct it gives me the correct context. i have not tried overriding it since it seems to be correct. might there be some other context that confuses the operator?

import bpy
print(bpy.context.active_object) > <bpy_struct, Object("FrontCasing")> (the correct active object)
print(bpy.context.mode) > SCULPT
bpy.ops.sculpt.face_sets_init(mode='LOOSE_PARTS')

Rodger Davis (RodDavis) added a comment.May 4 2020, 7:33 PM


Here is a short demo file using facesets. It has a text file using loose parts. Just to make it a little more clear and quick.

Richard Antalik (ISS) added a comment.May 5 2020, 9:53 AM
In T76324#923996, @dan grauer (kromar) wrote:

@Richard Antalik (ISS)
i was looking into the context and when i print the mode and the active obejct it gives me the correct context. i have not tried overriding it since it seems to be correct. might there be some other context that confuses the operator?

import bpy
print(bpy.context.active_object) > <bpy_struct, Object("FrontCasing")> (the correct active object)
print(bpy.context.mode) > SCULPT
bpy.ops.sculpt.face_sets_init(mode='LOOSE_PARTS')

Yes, selected object and mode are "global". Problem is that editor from within you run operator is not.

The idea of overriding context is that you want to trick operator that it is executed from different editor

you nedd to do something like bpy.ops.transform.seq_slide({'area':editor_area}, value = (0,distance)) and you have to search for editor_area.

dan grauer (kromar) added a comment.May 7 2020, 10:50 PM

i tried to override the context as in the documentation ( https://docs.blender.org/api/current/bpy.ops.html#overriding-context ) and also the way you described but i can not get it to work.

import bpy
bpy.ops.object.mode_set(mode='SCULPT')  ## **is working**

for window in bpy.context.window_manager.windows:
    screen = window.screen

    for area in screen.areas:
        if area.type == 'VIEW_3D':
            override = {'window': window, 'screen': screen, 'area': area}
            #bpy.ops.screen.screen_full_area(override)         
            bpy.ops.sculpt.face_sets_create(override, mode='VISIBLE') ## **not working **

            #bpy.ops.paint.mask_flood_fill(mode='VALUE', value=1)    ## **is working**
            bpy.ops.sculpt.dirty_mask()                              ## **is working**
            break
Richard Antalik (ISS) added a comment.May 8 2020, 1:52 AM
In T76324#926389, @dan grauer (kromar) wrote:

i tried to override the context as in the documentation ( https://docs.blender.org/api/current/bpy.ops.html#overriding-context ) and also the way you described but i can not get it to work.

import bpy
bpy.ops.object.mode_set(mode='SCULPT')  ## **is working**

for window in bpy.context.window_manager.windows:
    screen = window.screen

    for area in screen.areas:
        if area.type == 'VIEW_3D':
            override = {'window': window, 'screen': screen, 'area': area}
            #bpy.ops.screen.screen_full_area(override)         
            bpy.ops.sculpt.face_sets_create(override, mode='VISIBLE') ## **not working **

            #bpy.ops.paint.mask_flood_fill(mode='VALUE', value=1)    ## **is working**
            bpy.ops.sculpt.dirty_mask()                              ## **is working**
            break

I thought there may be some issue, but after digging in code it seems, that there isn't.
Turns out, that you don't even need to override context, but rather execution context https://docs.blender.org/api/current/bpy.ops.html#execution-context

Pass 'INVOKE_DEFAULT' as first parameter.
bpy.ops.sculpt.face_sets_create('INVOKE_DEFAULT', mode='VISIBLE')

I have done this only 2 times really so I don't know much about this off top of my head. Sorry for misleading you.

Unfortunately unless you look at operator code, you don't really know if you want to call invoke() or exec() function and this is kinda low-level even for quite advanced users.
Sometimes you may need to override both contexts I guess.

Richard Antalik (ISS) closed this task as Archived.May 8 2020, 1:52 AM
Richard Antalik (ISS) claimed this task.
Brecht Van Lommel (brecht) changed the task status from Archived to Resolved by committing rB7f5570ceff7f: Fix T76324: face set operators not working from Python console by default.May 8 2020, 2:05 AM
Brecht Van Lommel (brecht) added a commit: rB7f5570ceff7f: Fix T76324: face set operators not working from Python console by default.
Brecht Van Lommel (brecht) added a subscriber: Brecht Van Lommel (brecht).May 8 2020, 2:07 AM

There actually was a bug here, though the operator API is not strictly defined enough for it to be clear. By convention operators should always implement exec() for non-interactive execution, with only a few exceptions.

Richard Antalik (ISS) added a comment.May 8 2020, 2:47 AM
In T76324#926525, @Brecht Van Lommel (brecht) wrote:

There actually was a bug here, though the operator API is not strictly defined enough for it to be clear. By convention operators should always implement exec() for non-interactive execution, with only a few exceptions.

Thanks for clarification. I have seen quite a few operators without exec function, so I probably wouldn't consider this a bug (not working as designed)
Makes sense to consider this a bug though, so I will keep it in mind.