#How do I get the currently selected data in the inspector for a tool script?

1 messages · Page 1 of 1 (latest)

desert solar
#

first time tool script, I have this setup going, trying to get to the currently selected inspector contents in code

@tool
extends Node

var interfacenode : EditorInspector = EditorInterface.get_inspector()

func _ready() -> void:
    interfacenode.property_selected.connect(printfunc)

func printfunc(property):
    print(property)

all this does is give strings of names like

rotation
scale
surface_material/0```
can't figure out from the docs or google, how can I access the actual number or StandardMaterial3D or etc that is selected?
elfin falcon
#

To do exactly what you asked for, I'd guess you get the current focus owner? viewport.gui_get_focus_owner()

#

for the viewport in the editor (this is sneaky!) -- I guess something under the Editor namespace, like maybe hunting from EditorInterface.get_inspector()

#

but this is going to be pretty messy -- do you really want arbitrary data that's been selected? What are you trying to actually do?

#

usually we just take input from an @export var foo in our scene gdscripts/resources -- no tool necessary! -- or react to changes to those fields, which may need the @tool annotation, but doesn't need you to script against the editor directly

#

(and as of 4.4, you can also add buttons "on the fly" without needing to interact directly with inspector state, see @export_tool_button)

desert solar
#

basically i'd like to automate some shortcuts with a little popup window or panel. the main purpose being to tweak some materials. like being able to click a material slot and I can have my own streamlined UI or presets that are run with gdscript.

elfin falcon
#

kk. Well: the signal property_selected(property_name) are the paths on the object, the interfacenode.get_edited_object() is the object, so you should be able to get(property_name) on that object to get the value

#

(which isn't exactly the data in the inspector! but it's probably what you want -- I think I'm a bit slow today!)