Image
--[[
    **************************************************
    **************************************************

    This script generates a sequence of numbers as text layers.

    Original Programming: Mike Clifton
      Update Programming: Sam Cogheil (SimplSam) #5307

    **************************************************
    **************************************************
]] --
-- **************************************************
-- Provide Moho with the name of this script object
-- **************************************************
ScriptName = "SS_NumberSequence"

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

SS_NumberSequence = {}
local SS_NumberSequenceDialog = {}

function SS_NumberSequence:Name()
    return "Number Sequence+"
end

function SS_NumberSequence:Version()
    return "1.0+"
end

function SS_NumberSequence:Description()
    return "Creates a sequence of numbers+"
end

function SS_NumberSequence:Creator()
    return "Lost Marble LLC + SimplSam"
end

function SS_NumberSequence:UILabel()
    return "Number Sequence+"
end

-- **************************************************
-- Recurring & Pref values
-- **************************************************

function SS_NumberSequence:LoadPrefs(prefs)
    self.startValue = prefs:GetInt("SS_NumberSequence.startValue", 1)
    self.endValue = prefs:GetInt("SS_NumberSequence.endValue", 50)
    self.countInterval = prefs:GetInt("SS_NumberSequence.countInterval", 1)
    self.frameInterval = prefs:GetInt("SS_NumberSequence.frameInterval", 1)
    self.leadingZeros = prefs:GetBool("SS_NumberSequence.leadingZeros", false)
    self.font = prefs:GetString("SS_NumberSequence.font", "")
end

function SS_NumberSequence:SavePrefs(prefs)
    prefs:SetInt("SS_NumberSequence.startValue", self.startValue)
    prefs:SetInt("SS_NumberSequence.endValue", self.endValue)
    prefs:SetInt("SS_NumberSequence.countInterval", self.countInterval)
    prefs:SetInt("SS_NumberSequence.frameInterval", self.frameInterval)
    prefs:SetBool("SS_NumberSequence.leadingZeros", self.leadingZeros)
    prefs:SetString("SS_NumberSequence.font", self.font)
end

function SS_NumberSequence:ResetPrefs()
    self.startValue = 1
    self.endValue = 50
    self.countInterval = 1
    self.frameInterval = 1
    self.leadingZeros = false
    self.reverseCount = false
    self.font = ""
end

SS_NumberSequence.previewText = "1234567890"
SS_NumberSequence:ResetPrefs()

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

function SS_NumberSequence:Run(moho)
    local dlog = SS_NumberSequenceDialog:new(moho)
    if (dlog:DoModal() == LM.GUI.MSG_CANCEL) then
        return
    end

    moho.document:SetDirty()
    moho.document:PrepUndo(nil)

    local frame = moho.frame
    local countWidth = self.leadingZeros and math.max(#("%d"):format(self.startValue), #("%d"):format(self.endValue)) or 0
    local switchLayer = moho:LayerAsSwitch(moho:CreateNewLayer(MOHO.LT_SWITCH, false))
    switchLayer:Expand(false)
    switchLayer:SetName(("Numbers %0" .. countWidth .. "d - %0" .. countWidth .. "d"):format(self.startValue, self.endValue))
    switchLayer:SetValue(0, self.startValue)
    local signedInterval = ((self.startValue <= self.endValue) and 1 or -1) * self.countInterval
    for countValue = self.startValue, self.endValue, signedInterval do
        local layer = moho:CreateNewLayer(MOHO.LT_VECTOR, false)
        moho:PlaceLayerInGroup(layer, switchLayer, false)
        local countText = ("%0" .. countWidth .. "d"):format(countValue)
        layer:SetName(countText)
        switchLayer:SetValue(frame, countText)
        moho:InsertText(countText, self.font, true, false, true, true, 0)
        frame = frame + self.frameInterval
    end
    moho:SetSelLayer(switchLayer)
end

-- **************************************************
-- Dialog
-- **************************************************

SS_NumberSequenceDialog.UPDATE = MOHO.MSG_BASE
SS_NumberSequenceDialog.LEADING_ZEROS = MOHO.MSG_BASE + 1

function SS_NumberSequenceDialog:new(moho)
    local d = LM.GUI.SimpleDialog("Number Sequence+", SS_NumberSequenceDialog)
    local l = d:GetLayout()

    d.moho = moho

    l:PushV()

    l:PushH()

    l:PushV()
    l:AddChild(LM.GUI.StaticText("Start Value"), LM.GUI.ALIGN_LEFT)
    l:AddChild(LM.GUI.StaticText("End Value"), LM.GUI.ALIGN_LEFT)
    l:AddChild(LM.GUI.StaticText("Count Interval"), LM.GUI.ALIGN_LEFT)
    l:AddChild(LM.GUI.StaticText("Frame Interval"), LM.GUI.ALIGN_LEFT)
    l:AddChild(LM.GUI.StaticText("Leading Zero's"), LM.GUI.ALIGN_LEFT)
    l:Pop()

    l:PushV()
    d.startValueText = LM.GUI.TextControl(0, "00000", 0, LM.GUI.FIELD_UINT)
    l:AddChild(d.startValueText)
    d.endValueText = LM.GUI.TextControl(0, "00000", 0, LM.GUI.FIELD_UINT)
    l:AddChild(d.endValueText)
    d.countIntervalText = LM.GUI.TextControl(0, "00000", 0, LM.GUI.FIELD_UINT)
    l:AddChild(d.countIntervalText)
    d.frameIntervalText = LM.GUI.TextControl(0, "00000", 0, LM.GUI.FIELD_UINT)
    l:AddChild(d.frameIntervalText)
    d.leadingZerosCheck = LM.GUI.CheckBox("", self.LEADING_ZEROS)
    l:AddChild(d.leadingZerosCheck, LM.GUI.ALIGN_LEFT)
    l:Pop()

    l:AddPadding(16)
    d.fontList = LM.GUI.TextList(280, 64, self.UPDATE)
    l:AddChild(d.fontList, LM.GUI.ALIGN_FILL)

    l:Pop() -- H

    d.fontPreview = MOHO.FontPreview(200, 64)
    l:AddChild(d.fontPreview, LM.GUI.ALIGN_FILL)

    d.textPreview = LM.GUI.DynamicText("12345", 0)
    l:AddChild(d.textPreview, LM.GUI.ALIGN_FILL)

    l:Pop() -- V

    moho:FillInFontList(d.fontList)

    return d
end

function SS_NumberSequenceDialog:UpdateWidgets()
    self.startValueText:SetValue(SS_NumberSequence.startValue)
    self.endValueText:SetValue(SS_NumberSequence.endValue)
    self.countIntervalText:SetValue(SS_NumberSequence.countInterval)
    self.frameIntervalText:SetValue(SS_NumberSequence.frameInterval)
    self.leadingZerosCheck:SetValue(SS_NumberSequence.leadingZeros)
    if (not self.fontList:SetSelItem(SS_NumberSequence.font)) then
        self.fontList:SetSelItem(0)
    end
    self:HandleMessage(self.UPDATE)
end

function SS_NumberSequenceDialog:OnValidate()
    local b = true
    if (not self:Validate(self.startValueText, 0, 10000000)) then
        b = false
    end
    if (not self:Validate(self.endValueText, 0, 10000000)) then
        b = false
    end
    if (not self:Validate(self.countIntervalText, 1, 1000)) then
        b = false
    end
    if (not self:Validate(self.frameIntervalText, 1, 100)) then
        b = false
    end
    return b
end

function SS_NumberSequenceDialog:HandleMessage(msg)
    if (msg == self.UPDATE or msg == self.LEADING_ZEROS) then
        self.fontPreview:SetPreviewText((self.leadingZerosCheck:Value() and "00" or "") .. SS_NumberSequence.previewText)
        self.fontPreview:SetFontName(self.fontList:SelItemLabel())
        self.fontPreview:Refresh()
        self.textPreview:SetValue(self.fontList:SelItemLabel())
    end
end

function SS_NumberSequenceDialog:OnOK()
    SS_NumberSequence.startValue = tonumber(self.startValueText:Value()) -- IntValue max is 1M
    SS_NumberSequence.endValue = tonumber(self.endValueText:Value())
    SS_NumberSequence.countInterval = self.countIntervalText:IntValue()
    SS_NumberSequence.frameInterval = self.frameIntervalText:IntValue()
    SS_NumberSequence.leadingZeros = self.leadingZerosCheck:Value()
    SS_NumberSequence.font = self.fontList:SelItemLabel()
end

SS - Number Sequence
Listed

Script type: Button/Menu

Uploaded: Jul 12 2023, 08:24

Script Version: 1.0+

Quickly create animated number sequences
An update to the built-in number sequence menu script

Enhanced Features:
+ Specify Start and End of sequence
+ Starts from current frame
+ Specify Count and/or Frame Interval
+ Forward or Reverse numbers (Low-to-High, High-to-Low)
+ Option to Display leading zeros
+ Sequence created in Switch Layer

Image

Image

Image

Installation Options:

This script, and all other scripts on this site are distributed as free software under the GNU General Public License 3.0 or later.
Downloads count: 493