aseprite/aseprite

Using `fromFrame` and `toFrame` in `app.command.SaveFileAsCopy()` doesn't overwrite existing files in folder

Opened this issue · 1 comments

Hi there,

I am unsure if this intended behaviour, but thought I'd report it:

When using the API's app.command.SaveFileCopyAs with fromFrame and toFrame range arguments alongside a file format containing {frame}, the resulting file frame numbers will start from the last frame number present in a file at the export path.

For example, if I have a sprite with 15 frames, the first export will result in Sprite_001 ... Sprite_015, and a subsequent export will create files with Sprite_016 .. Sprite_030

For API use, I would expect the existing range Sprite_001 .. Sprite_015 to be overwritten instead of being appended to , and this does happen when using the tags argument alongside a {tag}_{frame} file format.

For a use case, this would help exporting frames where the resulting save parameters are frame specific. E.g. in my use case, I am trimming the resulting image to that sprite's visual bounds, which I believe requires using app.SaveFileAsCopy() in a for loop to provide the proper bounds argument.

I am aware this might be very specific use case, please disregard this report.

I've done a little bit of extra testing.

It turns out that the issue seems to be related to creating a dialogue, and calling a function that uses app.command.SaveFile() (and related commands) from this dialogue.

Essentially, until the dialogue is closed, each call to a function containing the command above will generate N frames for every time it's been called. E.g. for a 15 frame sprite, pressing export 3x times will result in 45 frames being saved.

This is the test script I've used:

`function Export()
local currentSprite = app.sprite
local exportSprite = Sprite(currentSprite)

local path = app.fs.filePath(app.sprite.filename) 
local title = "TEST_" .. app.fs.fileTitle(app.sprite.filename) .. "_{innertag}" .. "_{frame01}"
local ext = ".png" 
local outputName = app.fs.joinPath(path, title) .. ext 

app.sprite = exportSprite
local bounds = Rectangle(16, 16, exportSprite.width, exportSprite.height)
--Behaviour is the same whether you for-loop through frames individually or give the entire range: 
app.command.SaveFile{
	ui = false, 
	filename = outputName, 
	fromFrame = 1,
	toFrame = #exportSprite.frames,
	bounds = bounds
}
--[[for f, frame in ipairs(exportSprite.frames) do 
	app.command.SaveFile{
		ui = false, 
		filename = outputName, 
		fromFrame = f,
		toFrame = f,
		bounds = bounds
	}
end]]
exportSprite:close()

end

local dialog = Dialog("Export Frames")
dialog:button{
id = "Export",
text = "Export Frames",
onclick = function()
Export()
dialog:close()
dialog:show()
end
}
dialog:show()`