rt_next_keyframe - prev

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
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

rt_next_keyframe - prev

Post by davoodice2 »

any body can edit theses script to skip hided bones. I want it acts like ctrl+alt+Right or left arrows. but this script calculate hide bone key frames to.

I want this two script only, not complete tool. simply for assign shortkey. ctrl+alt+arrow are extremely bad shortkeys and useless for me.
thanks friends


rt_next_keyframe

Code: Select all

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

ScriptName = "RT_NextKeyframe"

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

RT_NextKeyframe = {}

function RT_NextKeyframe:Name()
    return "Go to next keyframe"
end

function RT_NextKeyframe:Version()
    return "0.1"
end

function RT_NextKeyframe:Description()
    return "Go to next keyframe for current layer"
end

function RT_NextKeyframe:Creator()
    return "Rudiger"
end

function RT_NextKeyframe:UILabel()
    return("Next keyframe")
end

-- **************************************************
-- The guts of this script
-- **************************************************
function RT_NextKeyframe:AllChannelsHasKey(channels, global_channels, start_frame, end_frame, moho)
    -- Check whether any channels have keyframe in the given frame range

    local doc
    local found_key = false
    local incr
    local layer = moho.layer
    local timing_offset

    if end_frame > start_frame then
        incr = 1
    else
        incr = -1
    end
    
    if layer.TotalTimingOffset ~= nil then
        timing_offset = layer:TotalTimingOffset()
    else
	timing_offset = 0
    end

    -- Go through next/previous frames and stop when a keyframe is found
    for frame = start_frame, end_frame, incr do
        for i, channel in ipairs(channels) do
           if channel.HasKey ~= nil and channel:HasKey(frame) then
               found_key = true
               break
           end
        end
        if found_key == false and global_channels ~= nil then
            for i, channel in ipairs(global_channels) do
                if channel.HasKey ~= nil and channel:HasKey(frame) then
                    found_key = true
                    break
                end
            end
        end
        if found_key then
            moho:SetCurFrame(frame-timing_offset)
            break
        end
    end
    
    return found_key

end

function RT_NextKeyframe:Run(moho)

    local layer = moho.layer
    local doc
    local current_frame
    local channels 
    local channel
    local i
    local global_channels

    if moho.layerFrame ~= nil then
        current_frame = moho.layerFrame
    else
        current_frame = moho.frame
    end

    -- Modify to only detect point keys
    --channels = RT_Utilities:get_point_channels(moho)

    -- Get all layer and global channels
    channels = RT_Utilities:get_layer_channels(moho, moho.layer)
    if layer:CurrentAction() == "" then
        global_channels = RT_Utilities:get_global_channels(moho)
    end
    
    -- Do it in two stages as running AnimDuration takes a while
    local found_key = RT_NextKeyframe:AllChannelsHasKey(channels, global_channels, 
                                                        current_frame+1, current_frame+20, moho)

    if found_key then
        return
    end
    
    local anim_duration = moho.document:AnimDuration()
    RT_NextKeyframe:AllChannelsHasKey(channels, global_channels, 
                                      current_frame+21, anim_duration, moho)

    -- **ToDo: Figure out how to update Frame indicator
    moho:UpdateUI()

end
rt_prev_keyframe

Code: Select all

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

ScriptName = "RT_PrevKeyframe"

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

RT_PrevKeyframe = {}

function RT_PrevKeyframe:Name()
    return "Go to previous keyframe"
end

function RT_PrevKeyframe:Version()
    return "0.1"
end

function RT_PrevKeyframe:Description()
    return "Go to previous keyframe for current layer"
end

function RT_PrevKeyframe:Creator()
    return "Rudiger"
end

function RT_PrevKeyframe:UILabel()
    return("Previous keyframe")
end

-- **************************************************
-- The guts of this script
-- **************************************************
function RT_PrevKeyframe:Run(moho)

    local layer = moho.layer
    local doc = moho.document
    local current_frame 
    local frame
    local channels
    local channel
    local i
    local global_channels
    
    if moho.layerFrame ~= nil then
        current_frame = moho.layerFrame
    else
        current_frame = moho.frame
    end

    -- Get all layer and global channels
    channels = RT_Utilities:get_layer_channels(moho, layer)
    if layer:CurrentAction() == "" then
        global_channels = RT_Utilities:get_global_channels(moho)
    end

    -- Check whether there are any keys to the left of the cursor
    RT_NextKeyframe:AllChannelsHasKey(channels, global_channels, current_frame-1, 0, moho)

    -- **ToDo: Figure out how to update Frame indicator
    moho:UpdateUI()

end
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
User avatar
synthsin75
Posts: 10007
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: rt_next_keyframe - prev

Post by synthsin75 »

https://mohoscripting.com/classes/M_Bone#fHidden to tell which bones are hidden.
https://www.lostmarble.com/forum/viewto ... 12&t=31612 for a scripting example of which keyframes go with which bones.
User avatar
davoodice2
Posts: 381
Joined: Tue Jun 15, 2021 1:14 pm

Re: rt_next_keyframe - prev

Post by davoodice2 »

synthsin75 wrote: Wed Aug 25, 2021 4:00 pm https://mohoscripting.com/classes/M_Bone#fHidden to tell which bones are hidden.
https://www.lostmarble.com/forum/viewto ... 12&t=31612 for a scripting example of which keyframes go with which bones.
thanks.
I updated rt_utilities.lua
old

Code: Select all

if not RT_NudgeKeysLeft.nudge_selected_bones_only or bone.fSelected then
new

Code: Select all

if ((not RT_NudgeKeysLeft.nudge_selected_bones_only or bone.fSelected) and not bone.fHidden )  then
خیام اگر ز باده مستی خوش باش
با ماهرخی اگر نشستی خوش باش
چون عاقبت کار جهان نیستی است
انگار که نیستی چو هستی خوش باش
Post Reply