pitiwazou
(Pitiwazou)
January 22, 2020, 9:09pm
1
Hey guys,
I would like to set the current active tool (select, rotate, scale, etc ) in a variable to be able to active if after a modal.
Select box (as active tool)
Launch modal, change to something else
Exit modal and use the select box active tool.
If you have an idea
thx for your help!
kkar
(kkar)
January 22, 2020, 9:12pm
2
You can store the name of the tool in a window manager or scene property and match the name to the function when done. Since these are global and saved with the scene , it can be handy later as way. I did it this way for a similarish need.
You might need to check the undo history to see what was triggered prior to your tool?
pitiwazou
(Pitiwazou)
January 22, 2020, 9:14pm
3
something like this?
bpy.types.WindowManager.active_tool_name = StringProperty(type= ?)
kkar
(kkar)
January 22, 2020, 9:15pm
4
Yeah that is how I did, as long as you know the tool’s name.
pitiwazou
(Pitiwazou)
January 22, 2020, 9:16pm
5
What I need it to find the active tool name ^^
I don’t have it.
To change the tool it’s this code
bpy.ops.wm.tool_set_by_id(name="builtin.cursor")
But how to find the name?
1 Like
kkar
(kkar)
January 22, 2020, 9:24pm
6
This used to bring up a popup in 2.79 for last actions list, but it is not assinged in 2.8x however the command in there. I wonder if you could get the list from the popup and revert back Maybe there is a stack for the successful command history. There is undo history but I am not seeing how one can get a name, without undoing.
bpy.ops.screen.repeat_history
(F3)
pitiwazou
(Pitiwazou)
January 22, 2020, 9:28pm
7
ok, I see, but there should be something better than checking for the history.
For example, if we use this in the console and press ctrl space, we have the name
bpy.context.workspace.tools
>>> bpy.context.workspace.tools['builtin.select']
I don’t find how to make a variable for this
current_active_tool = bpy.context.workspace.tools ?
kkar
(kkar)
January 22, 2020, 9:31pm
8
If that works for you then you can pass the command as a text then parse it.
>>> last_command="bpy.context.workspace.tools['builtin.select']".split("'")[1]
>>> last_command
'builtin.select'
>>> type(last_command)
<class 'str'>
pitiwazou
(Pitiwazou)
January 22, 2020, 9:33pm
9
The thing is that it will not be the last command ^^
pitiwazou
(Pitiwazou)
January 22, 2020, 9:33pm
10
Ok, this code give me the name.
tools = bpy.context.workspace.tools
current_active_tool = tools.from_space_view3d_mode(bpy.context.mode).idname
print(current_active_tool)
3 Likes
kkar
(kkar)
January 22, 2020, 10:06pm
11
Btw I did a search in the source and this is all the builtin
tools which should work with the method above
editors/transform/transform_gizmo_3d.c: if (tref && STREQ(tref->idname, "builtin.move")) {
editors/transform/transform_gizmo_3d.c: else if (tref && STREQ(tref->idname, "builtin.rotate")) {
editors/transform/transform_gizmo_3d.c: else if (tref && STREQ(tref->idname, "builtin.scale")) {
editors/transform/transform_gizmo_3d.c: else if (tref && STREQ(tref->idname, "builtin.transform")) {
editors/transform/transform_gizmo_3d.c: /* This is also correct logic for 'builtin.transform', no special check needed. */
windowmanager/intern/wm_toolsystem.c: return "builtin.cursor";
windowmanager/intern/wm_toolsystem.c: return "builtin.select_box";
windowmanager/intern/wm_toolsystem.c: return "builtin.select";
windowmanager/intern/wm_toolsystem.c: return "builtin.annotate";
windowmanager/intern/wm_toolsystem.c: return "builtin.select";
windowmanager/intern/wm_toolsystem.c: return "builtin.select_box";
windowmanager/intern/wm_toolsystem.c: return "builtin.select_box";
1 Like