In a tooldata, is it possible to detect when the user selects an object in the tree structure?
Solved detect the selection of an object
no, that's not possible. Can you give us a use-case, where this is needed for in a ToolData? Maybe we can come up with something else.
It's an improvement I want to make to OnFloor.
Currently, the tool is activated and then click on each object in the 3D view to place it on the ground.
In the case of a complex scene, it can be difficult to find an object in the 3D view. So I would like to include the possibility of clicking on the object in the scene tree structure.
A PickSession() lets you retrieve objects. The transfer tool uses something similar.
Although, it may not be possible to directly click in the object tree with a tool enabled (and there are no tools in C4D that I know of), but you could add a link to your tool that allows you to pick an object that should be considered for placing.
Take a look at the transfer tool - maybe that's what you're looking for.
I have been in need of something similar as well. And if I remember correctly it has been discussed a few years ago.
Reason is that a ToolData or DescriptionToolData might need to initialize some stuff depending the currently active object. When the user selects a different object in the ObjectManager, the ToolData might need to reinitialize some stuff.
The solution proposed in the past was to use a MessageData and listen to EVMSG_CHANGE to check if a different object has been selected using the object's "unique" id and then trigger the ToolData by sending a SpecialEvent ... or something.
It is quite a complex implementation that seems to work, but probably is very error prone.
I wish we would have had some kind of message telling the active object selection was changed (from inside the ToolData), not via-via. And definitely not using such a hacky and complex solution.
It has been a while, but I seem to remember that the whole use of the object's unique id was rather flawed as the id didn't exactly seem to be that unique after all.
Anyway, I am still hoping for a nice solution to detect when user changes the current active object. But it seems to not be possible after all.
@passion3d said in detect the selection of an object:
It's from R19 only. It will remove OnFloor compatibility from R13 to R18
If I'm not mistaken, in prior versions it must have been ViewportSelect.PickObject().
C4DS approach sounds a bit more elegant, yet hacky and thus probably error-prone. I'd go for the more robust solution. Even if that means a lack in comfort.
ViewportSelect.PickObject(), this is what I use to select an object in the 3D View.
What I'm trying to do seems complex and unreliable.
I'll try to find another solution.
As I said, when the scene is complex, it is difficult to reach a particular object, especially if it is small.
Then, why don't you simply add a LinkListGui or a Link field? I had a similar plugin written, which allows me to build a list for snapping candidates. That works pretty well.
As this topic seems to be "solved" could the solution be provided, or discussed. It might be helpful to others. And I am definitely interested to hearing a solution in more details.
Although a solution has not been given (as I wish to do), explanations have been provided. I have therefore considered it resolved.
For IRL reasons, I could not do so. I will be able to get back to it, and if I find THE solution, I will post it