Last active
December 4, 2023 16:54
-
-
Save 01010111/95b55838ea7cc5a8637ab943a0fb4594 to your computer and use it in GitHub Desktop.
Export all frames within tags as separate PNG files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Export all frames within tags as seperate PNG files | |
-- based on Export Tags script by StarJackal57: https://github.com/StarJackal57/Aseprite-Export-Tags | |
-- Ex: if Sprite Prefix is "Sprite", and there is a tag "Run", and there are three frames within that tag, | |
-- you will get three files: | |
-- "Sprite_Run_0.png" | |
-- "Sprite_Run_1.png" | |
-- "Sprite_Run_2.png" | |
-- Get current sprite | |
local sprite = app.activeSprite | |
-- Returns the Path, Filename, and Extension as 3 values | |
local function SplitFilename(strFilename) | |
return string.match(strFilename, "(.-)([^\\]-([^\\%.]+))$") | |
end | |
-- Alert if no sprite loaded | |
if not sprite then | |
app.alert("No sprite to export!") | |
end | |
-- Get name | |
local sprite_name = "output" | |
if sprite.filename then sprite_name = app.fs.fileTitle(sprite.filename) end | |
-- Start dialog | |
local dialog = Dialog("Export All Frames") | |
:file{ | |
id = "dir", | |
label = "Select Directory", | |
title = "Sprite Prefix", | |
open = false, | |
save = true, | |
filename = "directory" | |
} | |
:entry{ | |
id = "name", | |
label = "Sprite Prefix", | |
text = sprite_name, | |
focus = true | |
} | |
:button{ | |
id = "ok", | |
text = "&Export" | |
} | |
:button{ | |
text = "&Cancel" | |
} | |
:show() | |
-- Check dialog data | |
local data = dialog.data | |
if not data.ok then | |
return | |
end | |
-- Get path, file, and extension | |
path, file, extension = SplitFilename(data.dir) | |
-- Save all frames | |
for i, tag in ipairs(sprite.tags) do | |
for j = 0, tag.frames - 1 do | |
local img = Image(sprite.width, sprite.height) | |
img:drawSprite(sprite, tag.fromFrame.frameNumber + j, Point(0, 0)) | |
img:saveAs(path .. data.name .. "_" .. tag.name .. "_" .. j .. ".png") | |
end | |
end | |
-- Refresh app | |
app.refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not a developer, is there any way I can get some options added? For example, I work with a file where there are several angles, each angle in a folder, then I want to ignore empty files, split the layers, trim cels and by grid