Tools cannot be registered into some contexts (e.g. PAINT_TEXTURE). #63892

Closed
opened 2019-04-25 23:22:50 +02:00 by Joshua Knauber · 10 comments

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: Intel(R) HD Graphics 620 Intel 4.5.0 - Build 24.20.100.6136

Blender Version
Broken: version: 2.80 (sub 59), branch: blender2.7, commit date: 2019-04-24 22:25, hash: blender/blender@d966c2f0c2

Short description of error
When trying to create an active tool in texture painting mode, a error message appears and the tool can't be registered.

Exact steps for others to reproduce the error

  • Load the script template for a UI tool simple
  • Remove the information for the second tool
  • Change the bl_context_mode to "PAINT_TEXTURE"
  • Run script: Name error: name "context" is not defined

Here's the script which is described above:
ui_tool_simple.py

**System Information** Operating system: Windows-10-10.0.17134 64 Bits Graphics card: Intel(R) HD Graphics 620 Intel 4.5.0 - Build 24.20.100.6136 **Blender Version** Broken: version: 2.80 (sub 59), branch: blender2.7, commit date: 2019-04-24 22:25, hash: `blender/blender@d966c2f0c2` **Short description of error** When trying to create an active tool in texture painting mode, a error message appears and the tool can't be registered. **Exact steps for others to reproduce the error** - Load the script template for a UI tool simple - Remove the information for the second tool - Change the bl_context_mode to "PAINT_TEXTURE" - Run script: Name error: name "context" is not defined Here's the script which is described above: [ui_tool_simple.py](https://archive.blender.org/developer/F7094586/ui_tool_simple.py)
Author

Added subscriber: @JoshuaKnauber

Added subscriber: @JoshuaKnauber
Campbell Barton was assigned by Sebastian Parborg 2019-04-26 15:05:49 +02:00

Added subscriber: @DanPool

Added subscriber: @DanPool

You're trying to use circle select tool in Texture Paint mode. That tool doesn't exist in the texture paint context.

You're trying to use circle select tool in Texture Paint mode. That tool doesn't exist in the texture paint context.
Author

In #63892#711736, @DanPool wrote:
You're trying to use circle select tool in Texture Paint mode. That tool doesn't exist in the texture paint context.

You're right, that could have caused the error, but I removed everything that has to do with the circle select and it still only runs in all the different edit modes and object mode. Sculpting and painting for example are not working.
Hopefully I missed something, it'd be great if you could check out this script:

ui_tool_simple.py

> In #63892#711736, @DanPool wrote: > You're trying to use circle select tool in Texture Paint mode. That tool doesn't exist in the texture paint context. You're right, that could have caused the error, but I removed everything that has to do with the circle select and it still only runs in all the different edit modes and object mode. Sculpting and painting for example are not working. Hopefully I missed something, it'd be great if you could check out this script: [ui_tool_simple.py](https://archive.blender.org/developer/F7563943/ui_tool_simple.py)
Campbell Barton was unassigned by Dalai Felinto 2019-12-23 16:34:34 +01:00

Added subscriber: @ideasman42

Added subscriber: @ideasman42

This issue was referenced by blender/blender@f9e51662bd

This issue was referenced by blender/blender@f9e51662bd9605d0fe5b22977e33f2c9caa420fe

This issue was referenced by blender/blender@d95e9c7cf8

This issue was referenced by blender/blender@d95e9c7cf80ae2eb40728e7369216e48146a3a36
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Reconfirmed.

This fails because some tool contexts define their tools with functions [see the following list for context that fail]:

  • PARTICLE (_defs_particle.generate_from_brushes)
  • SCULPT (_defs_sculpt.generate_from_brushes)
  • PAINT_TEXTURE (_defs_texture_paint.generate_from_brushes)
  • PAINT_VERTEX (_defs_vertex_paint.generate_from_brushes)
  • PAINT_WEIGHT (_defs_weight_paint.generate_from_brushes)
  • PAINT_GPENCIL (_defs_gpencil_paint.generate_from_brushes)
  • SCULPT_GPENCIL (_defs_gpencil_sculpt.generate_from_brushes)
  • WEIGHT_GPENCIL (_defs_gpencil_weight.generate_from_brushes)

ToolSelectPanelHelper._tools_flatten() is usually called with cls.tools_from_context(context) [that already yields from the function]
But when registering a tool, _tools_flatten() will still give back this function not a ToolDef - and we cannot get a bl_idname from that:

Traceback (most recent call last):
  File "/Text", line 30, in <module>
  File "/Text", line 24, in register
  File "/build_linux/bin/2.83/scripts/modules/bpy/utils/__init__.py", line 798, in register_tool
    item.idname for item in ToolSelectPanelHelper._tools_flatten(tools)
  File "/build_linux/bin/2.83/scripts/modules/bpy/utils/__init__.py", line 799, in <setcomp>
    if item is not None
AttributeError: 'function' object has no attribute 'idname'
Error: Python script failed, check the message in the system console
Reconfirmed. This fails because some tool contexts define their tools with **functions** [see the following list for context that fail]: - PARTICLE (_defs_particle.generate_from_brushes) - SCULPT (_defs_sculpt.generate_from_brushes) - PAINT_TEXTURE (_defs_texture_paint.generate_from_brushes) - PAINT_VERTEX (_defs_vertex_paint.generate_from_brushes) - PAINT_WEIGHT (_defs_weight_paint.generate_from_brushes) - PAINT_GPENCIL (_defs_gpencil_paint.generate_from_brushes) - SCULPT_GPENCIL (_defs_gpencil_sculpt.generate_from_brushes) - WEIGHT_GPENCIL (_defs_gpencil_weight.generate_from_brushes) `ToolSelectPanelHelper._tools_flatten()` is usually called with `cls.tools_from_context(context)` [that already yields from the function] But when registering a tool, _tools_flatten() will still give back this function not a `ToolDef` - and we cannot get a `bl_idname` from that: ``` Traceback (most recent call last): File "/Text", line 30, in <module> File "/Text", line 24, in register File "/build_linux/bin/2.83/scripts/modules/bpy/utils/__init__.py", line 798, in register_tool item.idname for item in ToolSelectPanelHelper._tools_flatten(tools) File "/build_linux/bin/2.83/scripts/modules/bpy/utils/__init__.py", line 799, in <setcomp> if item is not None AttributeError: 'function' object has no attribute 'idname' Error: Python script failed, check the message in the system console ```
Philipp Oeser changed title from Active tool in texture paint mode can't be registered to Tools cannot be registered into some contexts (e.g. PAINT_TEXTURE). 2020-02-06 14:10:58 +01:00
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Philipp Oeser self-assigned this 2020-02-20 13:32:17 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
5 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-addons#63892
No description provided.