Clearing grease pencil data/frame/layer using python does not clear viewport #104121

Closed
opened 2023-01-24 16:43:51 +01:00 by Amélie Fondevilla · 11 comments

System Information
Operating system: Linux-5.4.0-137-generic-x86_64-with-glibc2.31 64 Bits
Graphics card: NVIDIA GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.47.03

Blender Version
Broken: version: 3.5.0 Alpha
Worked: never? (doesn't work until 2.83)

Short description of error
When clearing grease pencil data using python API, the strokes are not disappearing in the viewport.
They do disappear when update is sent to viewport (eg. change object mode, attempt to draw stroke, etc.)
The same problem appear when clearing a grease pencil frame or layer.

Exact steps for others to reproduce the error
Open the "New 2D animation" template file.
Draw a stroke.
Open a Python console.
Type C.active_object.data.clear() to clear out data from grease pencil object.
The stroke is still visible in viewport while all data from the object has been removed.

clear_data_update.mp4

**System Information** Operating system: Linux-5.4.0-137-generic-x86_64-with-glibc2.31 64 Bits Graphics card: NVIDIA GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.47.03 **Blender Version** Broken: version: 3.5.0 Alpha Worked: never? (doesn't work until 2.83) **Short description of error** When clearing grease pencil data using python API, the strokes are not disappearing in the viewport. They do disappear when update is sent to viewport (eg. change object mode, attempt to draw stroke, etc.) The same problem appear when clearing a grease pencil frame or layer. **Exact steps for others to reproduce the error** Open the "New 2D animation" template file. Draw a stroke. Open a Python console. Type `C.active_object.data.clear()` to clear out data from grease pencil object. The stroke is still visible in viewport while all data from the object has been removed. [clear_data_update.mp4](https://archive.blender.org/developer/F14193583/clear_data_update.mp4)
Author
Member

Added subscriber: @amelief

Added subscriber: @amelief
Member

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

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123

Added subscriber: @antoniov

Added subscriber: @antoniov

I have no idea where the "clear" data API is defined, but for sure this problem is a missing notifier. I guess the solution is find where this clear is done and check if the ID type is ID_GD.

I have no idea where the "clear" data API is defined, but for sure this problem is a missing notifier. I guess the solution is find where this `clear` is done and check if the `ID` type is `ID_GD`.
Author
Member

So far, I found that the API function is defined in rna_gpencil.c:2726, and is linked to the rna_GPencil_clear C function that is defined in rna_gpencil.c:1118.
This function calls a notifier : WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL); which should in theory re-draw the grease pencil object in the viewport, right ?

I am not sure where to check for the ID type though.

So far, I found that the API function is defined in `rna_gpencil.c:2726`, and is linked to the `rna_GPencil_clear` C function that is defined in `rna_gpencil.c:1118`. This function calls a notifier : `WM_main_add_notifier(NC_GPENCIL | ND_DATA | NA_EDITED, NULL);` which should in theory re-draw the grease pencil object in the viewport, right ? I am not sure where to check for the ID type though.

Try adding DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY); after BKE_gpencil_free_layers(&gpd->layers); in rna_GPencil_clear

Try adding `DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);` after `BKE_gpencil_free_layers(&gpd->layers);` in `rna_GPencil_clear`
Author
Member

Yay it works !
Now we only need to make it work for frame/layer clear functions, because they have as only parameter bGPDframe*/ bGPDlayer* which don't have an id field.. (rna_gpencil:1104-1111)

Yay it works ! Now we only need to make it work for frame/layer clear functions, because they have as only parameter `bGPDframe*`/ `bGPDlayer*` which don't have an `id` field.. (`rna_gpencil:1104-1111`)

@amelief Look at rna_GPencil_stroke_remove

You need set this:

  func = RNA_def_function(srna, "remove", "rna_GPencil_stroke_remove");
  RNA_def_function_flag(func, FUNC_USE_SELF_ID);

Then in the called function, just add the ID as parameter.

static void rna_GPencil_frame_clear(ID *id, bGPDframe *frame)

@amelief Look at `rna_GPencil_stroke_remove` You need set this: ``` func = RNA_def_function(srna, "remove", "rna_GPencil_stroke_remove"); RNA_def_function_flag(func, FUNC_USE_SELF_ID); ``` Then in the called function, just add the ID as parameter. `static void rna_GPencil_frame_clear(ID *id, bGPDframe *frame)`

This issue was referenced by ef39d85d7c

This issue was referenced by ef39d85d7c94c28e952683c0ddd0f3b7435b8460
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Amélie Fondevilla self-assigned this 2023-01-26 09:17:15 +01:00
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
4 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#104121
No description provided.