Automatic Import Spritesheet script

I’ve been experimenting a bit with creating some very simple scripts, but I can’t figure out how to make one that calls the Import Spritesheet command (skipping the UI menu) and automatically detects and fills in the correct dimensions. The spritesheets I’m working with are horizontal strips with a single animation and can all be easily divided into frames where the width and height are the same.

This was my own attempt, I’m struggling with how to skip the menu and how to send the values to the command:

local sprite = app.activeSprite

app.command.ImportSpriteSheet{
	use-ui = false,
	x = 0,
	y = 0,
	width = sprite.height,
	height = sprite.height
}
3 Likes

Welcome @djentalist! Actually I’m seeing the code of Import Sprite Sheet and it doesn’t support ignoring the UI (yet). I’ll add this, something to do (the Import Sprite Sheet needs some love, there are a lot of new options we would like to add in the future).

6 Likes

Awesome! I’ve noticed it’s a powerful tool, so I’m definitely looking forward to it. Meanwhile Aseprite has more than enough other features to keep me busy.

1 Like

We’ve added some options for ImportSpriteSheet in v1.2.26 now.

2 Likes

Thanks so much for the update!

1 Like

For me it seems like it’s not working, despite using Aseprite v1.2.27-x64. With ui=false it doesn’t seem to do anything, and even with ui=true it brings up the default parameters from the editor, instead of the values I set in the command:

importsheet

This is what I use in my script right now (see the bottom half of the script):

local sprite = app.activeSprite
local name = app.fs.fileTitle(sprite.filename)
local frame_count = string.gsub(name, "%D+", "")
local total_width = sprite.width
local frame_width = math.floor(total_width / frame_count)
app.alert{text = "import sprite, frame count = " .. frame_count .. ", frame wdith = " .. frame_width}

-- Every variable up to this point seems to give the correct value 

app.command.ImportSpriteSheet{
	type=SpriteSheetType.HORIZONTAL,
	ui=true, 
	x=12,
	y=34,
	 -- ??? frameBounds=Rectangle(frame_width, sprite.height),
	padding=Size(0, 0),
	partialTiles=false
}

I hope I’m not dumb and that I forgot something really obvious :stuck_out_tongue:

Just in case, check that to create a rectangle you have to pass x and y as first arguments too: frameBounds=Rectangle(x, y, width, height), so for example:

app.command.ImportSpriteSheet{
	type=SpriteSheetType.HORIZONTAL,
	ui=false, 
	frameBounds=Rectangle(12, 34, frame_width, sprite.height),
	padding=Size(0, 0),
	partialTiles=false
}
1 Like

@djentalist Did you get it working? I would love to use it :slight_smile:

Yeahh, that was it! Thanks again, it works now ^^.
My final code is below: (it doesn’t have any error handling or fancy stuff, but it seems to work)

local sprite = app.activeSprite
local name = app.fs.fileTitle(sprite.filename)
local frame_count = string.gsub(name, "%D+", "")
local total_width = sprite.width
local frame_width = math.floor(total_width / frame_count)

app.command.ImportSpriteSheet{
	type=SpriteSheetType.HORIZONTAL,
	ui=false, 
	frameBounds=Rectangle(0, 0, frame_width, sprite.height),
	padding=Size(0, 0),
	partialTiles=false
}

Just for clarification for people who want to use this: this script assumes there is a number in the filename describing the amount of frames (for example: strong_kick_strip13.png)

2 Likes

Thanks so much, this is a nice fast load option!

1 Like