SelectedBoneID() return value?

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

SelectedBoneID() return value?

Post by lehtiniemi »

Documentation says SelectedBoneID() returns the ID of the selected bone. What does this mean? Isn't it possible to select multiple bones? Is the return value some array?
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: SelectedBoneID() return value?

Post by synthsin75 »

This returns the first (lowest) selected bone ID. Looking at the select and transform bone tools, it seems to be a quick way to get bone names and settings to display in tool option texts, where only one can be shown, even if more are selected. It's also a quick way to check that any bones are selected, before running the code to count through all bones. If there's no selected bones, there may be no need to waste processing counting through them.
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: SelectedBoneID() return value?

Post by lehtiniemi »

synthsin75 wrote:This returns the first (lowest) selected bone ID. Looking at the select and transform bone tools, it seems to be a quick way to get bone names and settings to display in tool option texts, where only one can be shown, even if more are selected. It's also a quick way to check that any bones are selected, before running the code to count through all bones. If there's no selected bones, there may be no need to waste processing counting through them.
Ah, great! Thanks for a quick answer. I just wrote my own function to detect if there are bones selected, I'll replace it now :D
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: SelectedBoneID() return value?

Post by synthsin75 »

moho:CountSelectedBones(bool) would also work just to find if any are selected, but I'm not sure what the scope of that is. Maybe layer and parent layer?
lehtiniemi
Posts: 107
Joined: Mon Jan 14, 2013 3:18 pm

Re: SelectedBoneID() return value?

Post by lehtiniemi »

synthsin75 wrote:moho:CountSelectedBones(bool) would also work just to find if any are selected, but I'm not sure what the scope of that is. Maybe layer and parent layer?
Thanks again. I don't know how I missed this, I was looking for it earlier. I'll go with this one!
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: SelectedBoneID() return value?

Post by hayasidist »

you also have the fSelected field such as

Code: Select all

	for j = 0, skel:CountBones()-1 do
		if skel:Bone(j).fSelected then ...
that works on the active layer.

if you want to work on the whole doc the you'll need an outer loop to check all the layers

Code: Select all


	for i = 0, moho.document:CountLayers()-1 do	
		if moho.document:Layer(i):LayerType() = MOHO.LT_BONE then ...
Post Reply