Face sets operators not working from python console #76324

Closed
opened 2020-05-02 11:54:52 +02:00 by Daniel Grauer · 20 comments
Member

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: 83304e4c22
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
    image.png

  4. note how all loose parts get a face set, this is what is expected.
    image.png

  5. now undo the face sets again and try the same via the python console

  6. 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
    image.png
**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: `83304e4c22` 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 ![image.png](https://archive.blender.org/developer/F8507301/image.png) 4. note how all loose parts get a face set, this is what is expected. ![image.png](https://archive.blender.org/developer/F8507304/image.png) 5. now undo the face sets again and try the same via the python console 6. go to the python console and enter ``` bpy.ops.sculpt.face_sets_init(mode='LOOSE_PARTS') ``` 7. i would expect the same result but instead nothing happens and no face sets are created ![image.png](https://archive.blender.org/developer/F8507309/image.png)
Author
Member

Added subscriber: @DanielGrauer

Added subscriber: @DanielGrauer
Member

Added subscriber: @ankitm

Added subscriber: @ankitm
Member

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.

> 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.

Added subscriber: @RodDavis

Added subscriber: @RodDavis

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.

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.

Added subscriber: @iss

Added subscriber: @iss

@DanielGrauer 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

@DanielGrauer 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

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'

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

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

@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')

@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')

Faces sets Pass through.blend
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.

[Faces sets Pass through.blend](https://archive.blender.org/developer/F8512352/Faces_sets_Pass_through.blend) 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.

In #76324#923996, @DanielGrauer wrote:
@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.

> In #76324#923996, @DanielGrauer wrote: > @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`.
Author
Member

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 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 ```

In #76324#926389, @DanielGrauer 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.

> In #76324#926389, @DanielGrauer 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.

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'
Richard Antalik self-assigned this 2020-05-08 01:52:51 +02:00

This issue was referenced by 7f5570ceff

This issue was referenced by 7f5570ceff7f74621268dba9268c603eccce435f

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'

Added subscriber: @brecht

Added subscriber: @brecht

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.

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.

In #76324#926525, @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.

> In #76324#926525, @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.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#76324
No description provided.