The parameter of the API app.command.SaveFileCopyAs() fromFrame/toFrame doesn't seem to work

The parameter of the api fromFrame/toFrame doesn’t seem to work,
I want to export the image of the current frame,
But he always starts with the first frame to export the image
Code samples

app.command.SaveFileCopyAs {
        ui = false,
        filename = "path/00001.png",
        fromFrame=app.frame,
        toFrame=app.frame,
        ignoreEmpty = false,
        scale = 10
    }

The parameter of the api fromFrame/toFrame doesn’t seem to work,
I want to export the image of the current frame,
But he always starts with the first frame to export the image
Code samples

Is it that this API does not support these two parameters, or that I have passed this parameter incorrectly

2 Likes

Hi @nff, could you please try the following code:

app.command.SaveFileCopyAs {
        ui = false,
        filename = "path/00001.png",
        fromFrame=app.frame.frameNumber,
        toFrame=app.frame.frameNumber,
        ignoreEmpty = false,
        scale = 10
    }


Each time the second frame canvas is operated, but the above code always saves from the first frame, and cannot only save the canvas content of the current frame (2).

I’ve tried it and it’s still the same

here’s my lua code


if app.apiVersion < 22 then
    return app.alert("This script requires Aseprite v1.3-rc2")
end

-- This script requires UI
if not app.isUIAvailable then
    return
end

-- Console print log
local debug = true
-- Record ordered img(png) save in this folder
local saveFolder = ""
local DIRECTORY_SEPARATOR = "/"
-- Record img start Number
local imgStartNumber = 0
-- Record current active sprite
local currentSprite = nil

-- Save folder parse
local function fileinfoGet(filePath)
    if string.match(filePath, "\\") then
      --widows
      DIRECTORY_SEPARATOR = "\\"
    end
  
    local folder = string.match(filePath, "(.+)" .. DIRECTORY_SEPARATOR .. "[^" .. DIRECTORY_SEPARATOR .. "]*%.%w+$")
    local filename = string.match(filePath, ".+" .. DIRECTORY_SEPARATOR .. "([^" .. DIRECTORY_SEPARATOR .. "]*)%.%w+$")
  
    if (folder == nil or filename == nil)
    then
      return nil
    end

    local self = {}
    self.folder = folder
    self.filename = filename

    self.imgStartNoGet = function()
        local no = tonumber(self.filename)
        if no then
            return no
        end
        return 0
    end
  
    return self
end

local function debugPrint(str)
    if debug then
        print(str)
    end
end

-- Sprite onChange event
-- Record ordered images(png) every time changes occur
-- The img will resize 500%, The purpose is to use ff tool to synthesize videos in the later stage to ensure clarity
local currentSpriteOnChange = function(ev)
    debugPrint('The sprite has changed')
    
    local curNo = imgStartNumber + 1
    local imgfile = string.format(saveFolder .. DIRECTORY_SEPARATOR .. "%07d.png", curNo)
    debugPrint("Save change img:" .. imgfile)

    debugPrint("current frame: " .. app.frame.frameNumber)
    app.command.SaveFileCopyAs {
        ui = false,
        filename = imgfile,
        fromFrame=app.frame.frameNumber,
        toFrame=app.frame.frameNumber,
        ignoreEmpty = true,
        scale = 10
    }

    imgStartNumber = curNo

end
-- Remvoe currentSprite event
local removeCurrentSpriteEvent = function()
    if currentSprite ~= nil then
        currentSprite.events:off(currentSpriteOnChange)
        currentSprite = nil
        debugPrint('remvoe currentSprite event')
    end
end

local dialog = Dialog({
    title = "Screen Record",
    onclose = function()
        removeCurrentSpriteEvent()
        app.alert("Screen Record Close !!!")
    end
})

dialog:file{
        id = "record_folder",
        label = "Save Folder:",
        title = "Select a file to determine the save folder, and record sprite change ordered img(png) in folder",
        open = false,
        save = false 
    }
    :button{
        id = "record_start",
        text = "Start",
        onclick = function()
            local f = dialog.data.record_folder
            if f == nil then
                return app.alert("Error file selected !!!")     
            end

            local finfo  = fileinfoGet(f)
            if finfo == nil then
                return app.alert("Error file selected !!!")
            end

            saveFolder = finfo.folder
            local fno = finfo:imgStartNoGet()
            if fno > imgStartNumber then imgStartNumber = fno end

            currentSprite = app.sprite
            if not currentSprite then return app.alert "No active sprite" end

            --add sprite event
            currentSprite.events:on('change', currentSpriteOnChange)

            debugPrint("Save folder:" .. finfo.folder)
            debugPrint("selected file start img number:" .. fno)
        end
    }
    :button{
        id = "record_stop",
        text = "Stop",
        onclick = function()
            debugPrint("Stop screen record")
            removeCurrentSpriteEvent()
        end

    }

dialog:show({wait=false})

I found a solution today, I don’t know if it will affect other functions, but I think this change is in line with the saved frame of the selected frame.

Since I can only send one image, I put all the processing process into one image.

1 Like