Save this script as LK_AutoShowHideBones.lua in your custom content folder in: /moho pro/scripts/tool/
It won't show up in your tools panel, but it will automatically reveal all shy bones and vitruvian bones on entering frame 0, and it will hide them on leaving frame 0.
- Lukas
Code: Select all
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "LK_AutoShowHideBones"
-- **************************************************
-- General information about this script
-- **************************************************
LK_AutoShowHideBones = {}
function LK_AutoShowHideBones:Name()
return "LK_AutoShowHideBones"
end
function LK_AutoShowHideBones:Version()
return "0.1"
end
function LK_AutoShowHideBones:Description()
return "LK_AutoShowHideBones"
end
function LK_AutoShowHideBones:Creator()
return "Lukas Krepel, Frame Order"
end
function LK_AutoShowHideBones:UILabel()
return("LK_AutoShowHideBones")
end
-- **************************************************
-- The guts of this script
-- **************************************************
function LK_AutoShowHideBones:IsRelevant(moho)
if MohoMode ~= nil then
if MohoMode:Animation() then
self:Run(moho)
end
else
self:Run(moho)
end
return false
end
function LK_AutoShowHideBones:Run(moho)
-- * Disable in smartbone actions:
local action = moho.document:GetSelectedLayer(i):CurrentAction()
if moho.layer:IsSmartBoneAction(action) then
return
end
local hideBones = true
if moho.frame == 0 and self.prevFrame ~= 0 then
-- * Entered frame 0!
hideBones = false
elseif moho.frame ~= 0 and self.prevFrame == 0 then
-- * Left frame 0!
hideBones = true
else
-- * Do nothing:
return false
end
-- *
local skeletons = self:DocumentSkeletons(moho)
for i = 1, #skeletons do
local skel = skeletons[i]
for j = 0, skel:CountBones() - 1 do
local bone = skel:Bone(j)
if bone.fShy then
bone.fHidden = hideBones
else
bone.fHidden = false
end
end
for j = 0, skel:CountGroups() - 1 do
local group = skel:Group(j)
group.fEnabled = hideBones
end
end
-- *
if hideBones then
moho.layer:UpdateCurFrame()
end
self.prevFrame = moho.frame
end
-- **************************************************
-- Returns a table with all skeletons in the current document
-- **************************************************
function LK_AutoShowHideBones:DocumentSkeletons(moho)
local skeletons = {}
local count = 0
repeat
local layer = moho.document:LayerByAbsoluteID(count)
if layer then
count = count + 1
local skel = layer:ControllingSkeleton()
--
if not skel and layer:IsBoneType() then
skel = moho:LayerAsBone(layer):Skeleton()
end
--
if not table.contains(skeletons, skel) then
table.insert(skeletons, skel)
end
end
until not layer
return skeletons
end
-- **************************************************
-- Check whether a table contains an element
-- **************************************************
function table.contains(table, element)
if table ~= nil then
for _, value in pairs(table) do
if value == element then
return true
end
end
end
return false
end