PDA

View Full Version : Finding which tool is currently selected for an object?



Konidias
02-18-2011, 04:20 PM
Is there a way to retrieve the tool name that is currently selected for an object? For example, if I select the object "Null" and change to the Move tool, is there a way I can detect that? Like if the tool is currently Move, or Rotate, or Size, etc.

evenflcw
02-18-2011, 04:32 PM
You can detect the change by picking up the command call in a master script/plugin. There is no way to query what tool is currently active.

PS. I guess you mean specifically when you switch between different item types, and LW automatically switches to whatever you were using last with that item type. This case you might not be able to pick up as NT hasn't always bothered to practice what they preach, ie try to use their own tools, ie the sdk, or stay faithful to the design choices they made, ie use the command based interface they developed. Sometimes they just shoot themselves and everybody else in the foot and hardcode stuff that could just aswell have been implemented via existing features.

PS2. Confirmed. LW will not send a command to change the active tool when switching item types. So there is no simple reliable way to query or keep track of currently active tool. I guess you could record what tool was last used for each item type. But that is still atleast 4 cases when your tool might fail to know what tool is active (ie on startup for current type, then the first time you switch to a new type).

Konidias
02-18-2011, 04:57 PM
How would I go about recording what tool was last used for each item type?

evenflcw
02-18-2011, 06:49 PM
Well...

In the master scripts process function, you can catch all commands issued, including the ones that activate tools. So when one of those commands is issued, you just check the type of the item is currently selected (if any) and store that however you like. Simplest way is probably by saving the tool name in an array indexed by the types constant value. In sloppy lscript with just the relevant bits and lots of comments.


var tool_activation_commands = @"MoveTool", "RotateTool" ... @;
var last_tool_per_type[4] = nil;

process: event, data {
//if the event is a command call,
//and the command matches any of the tool activation commands.
if(event==COMMAND && tool_activation_commands.contains(data) {
//get the first selected item,
if(item = Scene().firstSelect()) {
//and use its type/genus as an index to store the tools name in the array.
//Genus is one of a set of constants, MESH, BONE, LIGHT or CAMERA, all should
//be integer constants so you can use the as indices in an array. If you want
//to play it safe, then just make the value a string to make use of lscripts
//associative arrays feature instead.
last_tool_per_type[selected_item.genus] = tool_activation_command_name;
}
}
}
So later when you need to check what tool was used for a specific type you just read from the last_tool_per_type variable. Index it by the item type constant and you get your value, or nil if it hasn't been initialized yet.

Mind you, only master scripts have the ability to listen in on command calls. If you need this info in another type you'll have to setup some communication between it and a master script.