GPencil: GPencilStrokePoints.weight_get throws an "index out of range" error for Vertex groups IDs with no points assigned #87790

Closed
opened 2021-04-25 07:41:04 +02:00 by Maurizio Memoli · 9 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71

Blender Version
Broken: version: 2.93.0 Beta, branch: master, commit date: 2021-04-21 20:15, hash: 0f66dbea90
Worked: (newest version of Blender that worked as expected)

Short description of error
GPencilStrokePoints.weight_get throws an "index out of range" error for Vertex groups IDs with no points assigned

Exact steps for others to reproduce the error
Create a Grease pencil stroke.
Create a vertex group
In a text window create a new file and run the following script

import bpy
ob = bpy.context.active_object
gpd = ob.data
gps = gpd.layers[1].frames[0].strokes[0]
i = 0
for pt in gps.points:
    weight = gps.points.weight_get(vertex_group_index=0, point_index=i)
    print(weight)
**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71 **Blender Version** Broken: version: 2.93.0 Beta, branch: master, commit date: 2021-04-21 20:15, hash: `0f66dbea90` Worked: (newest version of Blender that worked as expected) **Short description of error** GPencilStrokePoints.weight_get throws an "index out of range" error for Vertex groups IDs with no points assigned **Exact steps for others to reproduce the error** Create a Grease pencil stroke. Create a vertex group In a text window create a new file and run the following script ``` import bpy ob = bpy.context.active_object gpd = ob.data gps = gpd.layers[1].frames[0].strokes[0] i = 0 for pt in gps.points: weight = gps.points.weight_get(vertex_group_index=0, point_index=i) print(weight) ```

Added subscriber: @maumemoli

Added subscriber: @maumemoli

Added subscriber: @antoniov

Added subscriber: @antoniov

The python api is not designed to check if the data is valid or not, just try to get the data.

I have checked and the first message is: "Groups: No groups for this stroke" The reason is the stroke hasn't any group, only the object.

If you assign a weight to the stroke, then you need pass the correct index. If the index is incorrect, you get the mensaje: "GPencilStrokePoints: index out of range"

This is the underlying C code:

BKE_report(reports, RPT_ERROR, "GPencilStrokePoints: index out of range");
return -1.0f;
}```


In any case, your script has `i += 1` missing:

```import bpy
ob = bpy.context.active_object
gpd = ob.data
gps = gpd.layers- [x].frames- [x].strokes[0]
i = 0
for pt in gps.points:

weight = gps.points.weight_get(vertex_group_index=0, point_index=i)
print(i, weight)
i += 1```

The python api is not designed to check if the data is valid or not, just try to get the data. I have checked and the first message is: "Groups: No groups for this stroke" The reason is the stroke hasn't any group, only the object. If you assign a weight to the stroke, then you need pass the correct index. If the index is incorrect, you get the mensaje: "GPencilStrokePoints: index out of range" This is the underlying C code: ```if (stroke->totpoints <= point_index || point_index < 0) { ``` BKE_report(reports, RPT_ERROR, "GPencilStrokePoints: index out of range"); return -1.0f; }``` ``` In any case, your script has `i += 1` missing: ```import bpy ob = bpy.context.active_object gpd = ob.data gps = gpd.layers- [x].frames- [x].strokes[0] i = 0 for pt in gps.points: ``` weight = gps.points.weight_get(vertex_group_index=0, point_index=i) print(i, weight) i += 1```

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

Changed status from 'Needs Triage' to: 'Needs User Info'
Antonio Vazquez changed title from GPencilStrokePoints.weight_get throws an "index out of range" error for Vertex groups IDs with no points assigned to GPencil: GPencilStrokePoints.weight_get throws an "index out of range" error for Vertex groups IDs with no points assigned 2021-04-25 21:36:47 +02:00

I understand what you mean and I think it should work that way
Now my question is on how I can check if the strokePoints I am iterating are assigned to a vertex group without getting any error.
I guess it is complicated to have the vertex groups values available in the strokePoints as it is for vertices.
Shall I just use a "try" and let it continue if there is a exception?
Any help is really appreciated.

I understand what you mean and I think it should work that way Now my question is on how I can check if the strokePoints I am iterating are assigned to a vertex group without getting any error. I guess it is complicated to have the vertex groups values available in the strokePoints as it is for vertices. Shall I just use a "try" and let it continue if there is a exception? Any help is really appreciated.
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

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

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

As soon as any point has a weight assigned, the unassigned will return a value of -1.0.
Only if none is assigned at all, you'll get the Error: Groups: index out of range.

So you are probably best of doing a check prior to the loop if any points are in the group [try/except is not nice, but possibly your best friend here].

Then if that check succeeds, you should be able to loop over all points (and the ones returning -1.0 weight are not assigned).

Mesh vertices have the groups property (https://docs.blender.org/api/master/bpy.types.MeshVertex.html#bpy.types.MeshVertex.groups) which can be utalized in similar mesh cases, maybe that should be implemented for stroke points at some point, I would not consider the current behavior a bug though, will archive for now (of course feel free to comment again if issues persist).

As soon as any point has a weight assigned, the unassigned will return a value of -1.0. Only if none is assigned at all, you'll get the `Error: Groups: index out of range`. So you are probably best of doing a check prior to the loop if any points are in the group [try/except is not nice, but possibly your best friend here]. Then if that check succeeds, you should be able to loop over all points (and the ones returning -1.0 weight are not assigned). Mesh vertices have the `groups` property (https://docs.blender.org/api/master/bpy.types.MeshVertex.html#bpy.types.MeshVertex.groups) which can be utalized in similar mesh cases, maybe that should be implemented for stroke points at some point, I would not consider the current behavior a bug though, will archive for now (of course feel free to comment again if issues persist).

I agree with you Philippe,
this is more of a feature request. I guess I will go with the try, except solution.
Thank you for the help.

I agree with you Philippe, this is more of a feature request. I guess I will go with the try, except solution. Thank you for the help.
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#87790
No description provided.