0
$\begingroup$

I have a problem with adding a workspace tool to particles.

import bpy
from bpy.types import WorkSpaceTool

bl_info = {
    "name" : "ToolX",
    "author" : "Author",
    "description" : "",
    "blender" : (2, 80, 0),
    "location" : "",
    "warning" : "",
    "category" : "Generic"
}

class MyTool(WorkSpaceTool):
    bl_space_type='VIEW_3D'
    bl_context_mode='PARTICLE'

    # The prefix of the idname should be your add-on name.
    bl_idname = "my_template.my_circle_select"
    bl_label = "My Circle Select2"
    bl_description = (
        "This is a tooltip\n"
        "with multiple lines"
    )
    bl_icon = "ops.generic.select_circle"




def register():
    bpy.utils.register_tool(MyTool)

def unregister():
    bpy.utils.unregister_tool(MyTool)

if __name__ == "__main__":
    register()

I get the following error:

RuntimeError: Error: Traceback (most recent call last):
  File "/home/janez/Software/blender/2.80/scripts/modules/addon_utils.py", line 384, in enable
    mod.register()
  File "/home/janez/.config/blender/2.80/scripts/addons/temp_scripts/__init__.py", line 63, in register
    bpy.utils.register_tool(MyTool)
  File "/home/janez/Software/blender/2.80/scripts/modules/bpy/utils/__init__.py", line 755, in register_tool
    item.idname for item in ToolSelectPanelHelper._tools_flatten(tools)
  File "/home/janez/Software/blender/2.80/scripts/modules/bpy/utils/__init__.py", line 754, in <setcomp>
    tools_id = {
  File "/home/janez/Software/blender/2.80/scripts/startup/bl_ui/space_toolsystem_common.py", line 219, in _tools_flatten
    yield from item(context)
NameError: name 'context' is not defined

This code works fine if I change bl_context_mode with "OBJECT" or "EDIT_MESH", but this is not the result I want. However it fails for "PARTICLE" and "SCULPT".

Am I supposed to call things differently?

The goal here is to add a button into "T" side menu in "PARTICLE" mode.

I am using the latest version of blender 2.80

$\endgroup$

1 Answer 1

1
$\begingroup$

I had the same issue and figured out that there are a few issues in the python code. The problem is that context is not being passed into the methods for sculpt, but it is for all the rest. If you are up to it, you can edit the python scripts to fix this. There are 4 locations in space_toolsystem_common.py, 1 in keymap_from_toolbar.py, and 1 in _ _init__.py.

space_toolsystem_common.py:

Line 219 @staticmethod
Line 220     def _tools_flatten(**context**, tools):
.........
Line 241 @staticmethod
Line 242     def _tools_flatten_with_tool_index(**context**, tools):
.........
Line 274     for item in ToolSelectPanelHelper._tools_flatten(**context**, cls.tools_from_context(context, mode)):
.........
Line 291     for item, index in ToolSelectPanelHelper._tools_flatten_with_tool_index(**context**, cls.tools_from_context(context)):

keymap_from_toolbar.py:

Line 59     for item in ToolSelectPanelHelper._tools_flatten(**context**, cls.tools_from_context(context))

scripts/modules/bpy/utils/_ _init__.py

Line 769    item.idname for item in ToolSelectPanelHelper._tools_flatten(**_bpy.context**, tools)

That should fix it.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .