Modify the "select Bone layer" plugin

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

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
peng
Posts: 57
Joined: Mon Oct 18, 2021 3:13 am

Modify the "select Bone layer" plugin

Post by peng »

Code: Select all

-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************

ScriptName = "AM_SelectBonelayer"

-- **************************************************
-- General information about this script
-- **************************************************

AM_SelectBonelayer = {}

function AM_SelectBonelayer:Name()
	return 'Select Bonelayer'
end

function AM_SelectBonelayer:Version()
	return '1.4'
end

function AM_SelectBonelayer:UILabel()
	return 'Select Bonelayer'
end

function AM_SelectBonelayer:Creator()
	return 'Aleksei Maletin'
end

function AM_SelectBonelayer:Description()
	return 'Select Bonelayer'
end


-- **************************************************
-- Is Relevant / Is Enabled
-- **************************************************

function AM_SelectBonelayer:IsRelevant(moho)
	local hasParent = moho.layer:Parent()
	if hasParent then
		return true 
	end
	return false
end

function AM_SelectBonelayer:IsEnabled(moho)
	if moho.layer:LayerType() ~= MOHO.LT_BONE then
		return true
	end
end

-- **************************************************
-- The guts of this script
-- **************************************************

function AM_SelectBonelayer:Run(moho)
  local layerToSearchForBoneParent = moho.layer
  local layerParentBone = layerToSearchForBoneParent:ControllingBoneLayer()
  if layerParentBone then
    moho:SetSelLayer(layerParentBone)
  else
    repeat
      local parent = layerToSearchForBoneParent:Parent()
      if parent then
        if parent:LayerType() == MOHO.LT_BONE then
          moho:SetSelLayer(parent)
          moho:ShowLayerInLayersPalette(parent)
          break
        else
          layerToSearchForBoneParent = parent
        end
      end	
     until not parent
  end
end
this is a plugin that allows to use shortcut to select bone layer https://mohoscripts.com/script/am_select_bonelayer. Just want to know if anyone knows how to modify that allows the same function to select "transform bone" tool at the same time.

thank you very much.
User avatar
SimplSam
Posts: 1218
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Modify the "select Bone layer" plugin

Post by SimplSam »

From what I know, you cannot select or change the active tool using a Moho script.

The only alternative is to use an external tool like AutoHotkey, Stream Deck, Python to send key-command sequences to Moho.
Moho 14.3 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
User avatar
570295535
Posts: 32
Joined: Sat Feb 04, 2023 9:32 am

Re: Modify the "select Bone layer" plugin

Post by 570295535 »

You can modify this file: C:\Program Files\Moho 14\Resources\Support\Scripts\Tool\_tool_list.txt
Adjust the order of lm_transform-bone to the first position to achieve it.
Change it to this:

Code: Select all

group MOHO.Localize("/Tools/Group/Bone=Bone")
tool	lm_transform_bone	...
tool	lm_select_bone		...
tool	lm_add_bone			...
tool	lm_manipulate_bones	...
I'm from China, currently using: Moho 15 » Win10 System
:D :D :D :D :D :D :D :D :D :D :D
User avatar
SimplSam
Posts: 1218
Joined: Thu Mar 13, 2014 5:09 pm
Location: London, UK
Contact:

Re: Modify the "select Bone layer" plugin

Post by SimplSam »

Interesting approach, but I don't think that will consistently choose the Transform Bone tool. It will depend on what tool you are in previously (i.e. Transform Layer etc. will affect this).

You should not need to edit _tool_list. If you need to change the order of Tools, you can do so via Preferences:

Image

Also .. an alternate approach to this would be changing to the bone group, when you select the Bone tool. i.e. mod the tool to also select the bone layer. This approach was recently discussed/implemented for the Mr Pose tool: viewtopic.php?p=219548#p219548 (though it may currently have some drawbacks)
Moho 14.3 » Win 11 Pro 64GB » NVIDIA GTX 1080ti 11GB
Moho 14.3 » Mac mini 2012 8GB » macOS 10.15 Catalina
Tube: SimplSam


Sam
Post Reply