Order of selection?

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

Order of selection?

Post by mmmaarten »

Hi,
For a script I'd like to know the order in which bones were selected when multi-select. Is there a way to retrieve the order bones were selected by the user?

Thanks in advance!
Adults should play more often
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Order of selection?

Post by synthsin75 »

You'd have to track these, like adding their IDs to a table, as they're selected. If your script is the one doing the selecting, that's pretty easy. If not, you'd need to devise a way to do it, like using the IsEnabled function of your script. You can track the last selected bone, and add it to the table the first time more then one is selected, and continue adding bones. Then just empty the table when only one bone is selected again.

If you want to account for the user removing from the selection, using ctrl-click, you'd need to double check your table against the current selection and remove values accordingly.
User avatar
mmmaarten
Posts: 271
Joined: Mon Sep 19, 2022 2:19 pm
Location: Utrecht, The Netherlands
Contact:

Re: Order of selection?

Post by mmmaarten »

Thanks for your quick response. Damn, would've been nice if Moho could 'just' return the selected bones in order of selection. I cannot track selection of bones because the tool is just a run-immediately-on-click-tool and only used when the bone selection is already done by the user.
Looks like I need to convert the tool now to the type of tool that uses the top bar and add a button and settings there.
That's unfortunate, because with this tool it's fine, but sometimes you just want to have a quick tool that fires immediately.
Anyway, thanks for the confirmation, going to rework it :)
Adults should play more often
User avatar
synthsin75
Posts: 9979
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: Order of selection?

Post by synthsin75 »

mmmaarten wrote: Wed Dec 06, 2023 2:29 am Thanks for your quick response. Damn, would've been nice if Moho could 'just' return the selected bones in order of selection. I cannot track selection of bones because the tool is just a run-immediately-on-click-tool and only used when the bone selection is already done by the user.
Looks like I need to convert the tool now to the type of tool that uses the top bar and add a button and settings there.
No need. That's why I said you could use the IsEnabled function of your script. Since this function is ran often by Moho, including when a bone is selected, you can use it to keep track of the bone selection. Just make a global table so you can access it from the Run function of your script.

So even though it's a button/menu script, IsEnabled can still track what's going on when your script isn't being ran.
Post Reply