bpy.ops.gpencil.vertex_group_assign() doesn't work when invoked from the python console #74538

Closed
opened 2020-03-08 03:27:21 +01:00 by Marcelo Demian Gómez · 8 comments

System Information
Operating system: Linux-5.3.0-40-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 435.21

Blender Version
Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: 77d23b0bd7
Worked: (optional)

Short description of error
Having a GP object in Edit Mode with selected vertices and an active vertex group and invoking the bpy.ops.gpencil.vertex_group_assign() operator
from the python console or a script fails to assign the selected vertices to the active vertex group. This also happens in the greasepencil-object branch.

Exact steps for others to reproduce the error
1)Start blender.
2)Add a GP object.
3) Create a stroke.
4) Create a vertex group.
5) Tab into edit mode.
6) Select some vertices.
7) In the python console type bpy.ops.gpencil.vertex_group_assign()

The selected vertices are not assigned to the active vertex group.

**System Information** Operating system: Linux-5.3.0-40-generic-x86_64-with-debian-buster-sid 64 Bits Graphics card: GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 435.21 **Blender Version** Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: `77d23b0bd7` Worked: (optional) **Short description of error** Having a GP object in Edit Mode with selected vertices and an active vertex group and invoking the bpy.ops.gpencil.vertex_group_assign() operator from the python console or a script fails to assign the selected vertices to the active vertex group. This also happens in the greasepencil-object branch. **Exact steps for others to reproduce the error** 1)Start blender. 2)Add a GP object. 3) Create a stroke. 4) Create a vertex group. 5) Tab into edit mode. 6) Select some vertices. 7) In the python console type bpy.ops.gpencil.vertex_group_assign() The selected vertices are not assigned to the active vertex group.

Added subscriber: @MarceloGomez

Added subscriber: @MarceloGomez

Added subscriber: @iss

Added subscriber: @iss

Changed status from 'Needs Triage' to: 'Archived'

Changed status from 'Needs Triage' to: 'Archived'
Richard Antalik self-assigned this 2020-03-10 15:43:40 +01:00

You need to override context for this operator, see https://docs.blender.org/api/current/bpy.ops.html#overriding-context

You need to override context for this operator, see https://docs.blender.org/api/current/bpy.ops.html#overriding-context

Added subscriber: @Ornibulon

Added subscriber: @Ornibulon

Blender version: 3.3.1 master b292cfe5a9

Tried overriding context and stuff, whatever I test, no problem with operators in bpy.ops.object and bpy.ops.view3d, but operators in bpy.ops.gpencil either execute successfully but don't affect the scene or fail with incorrect context while contect seems coherent with the documentation.

example:

import bpy
from bpy import context

override = bpy.context.copy()
area = [area for area in bpy.context.screen.areas if area.type == "VIEW_3D"][0]
override['area'] = area
override['region'] = area.regions[-1]
override['space_data'] = area.spaces.active

with context.temp_override(**override):
    # makes overriden area gpencil edit mode
    bpy.ops.object.mode_set(mode='EDIT_GPENCIL')
    # displays the toolbar
    bpy.ops.wm.toolbar()
    # changes the view
    bpy.ops.view3d.view_camera()
    # doesn't smooth, no python error
    bpy.ops.gpencil.stroke_smooth()
    # doesn't affect selection, no python error
    bpy.ops.gpencil.select_all(action='SELECT')
    # fails with incorrect context
    bpy.ops.gpencil.delete(type='POINTS')

Scene was just a grease pencil stroke, I had selected a few points in edit mode before switching to object mode before running the script.

I am not familiar with context override so that's probably the reason, if someone stumbles on this again could they explain a bit more what Richard Antalik (ISS) meant ?
thanks

Blender version: 3.3.1 master b292cfe5a936 Tried overriding context and stuff, whatever I test, no problem with operators in bpy.ops.object and bpy.ops.view3d, but operators in bpy.ops.gpencil either execute successfully but don't affect the scene or fail with incorrect context while contect seems coherent with the documentation. example: ``` import bpy from bpy import context override = bpy.context.copy() area = [area for area in bpy.context.screen.areas if area.type == "VIEW_3D"][0] override['area'] = area override['region'] = area.regions[-1] override['space_data'] = area.spaces.active with context.temp_override(**override): # makes overriden area gpencil edit mode bpy.ops.object.mode_set(mode='EDIT_GPENCIL') # displays the toolbar bpy.ops.wm.toolbar() # changes the view bpy.ops.view3d.view_camera() # doesn't smooth, no python error bpy.ops.gpencil.stroke_smooth() # doesn't affect selection, no python error bpy.ops.gpencil.select_all(action='SELECT') # fails with incorrect context bpy.ops.gpencil.delete(type='POINTS') ``` Scene was just a grease pencil stroke, I had selected a few points in edit mode before switching to object mode before running the script. I am not familiar with context override so that's probably the reason, if someone stumbles on this again could they explain a bit more what Richard Antalik (ISS) meant ? thanks

@Ornibulon Usually you need to override area and region which seems you have done. If above doesn't work, it could be a bug, so you can make new report for this. But I would encourage you to discuss such issues on one of the community websites: https://www.blender.org/community/

We do not handle user support on this tracker.

@Ornibulon Usually you need to override area and region which seems you have done. If above doesn't work, it could be a bug, so you can make new report for this. But I would encourage you to discuss such issues on one of the community websites: https://www.blender.org/community/ We do not handle user support on this tracker.

ok thanks a lot!
I'll try a bit more and discuss it there.

ok thanks a lot! I'll try a bit more and discuss it there.
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
3 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#74538
No description provided.