SOLVED Bulk rename Tags with a LUA script

Hi,

I have several ase files with a massive amount of tags, and I have to rename all the tags in every files.

I would like to do it in LUA, but I don’t really know where to start, or if it’s even doable.
Could someone help me out to get started ?

Thanks !

Jacques

Hi @Arkogelul, you can do that kind of work. One possibility would be to create a script that iterate through all open sprites and then all tags of that sprite. For each tag you can change its Tag.name property.

Thanks David,

I’m really new to LUA so I might not do the right thing.
So far I have this :

local sprite = app.activeSprite

for i,tag in ipairs(sprite.tags) do
tag.name = test
end

But nothing happens. No error nor warnings.

Try changing this to:

tag.name = "test"

It works !! Thanks :slight_smile:

So now I have this :

local sprite = app.activeSprite
local name1 = tag.name:match('^(.+)bad$')
local badTagName = nil

if name1 then
badTagName = tag.sprite.tags[name1 .. " bad"]
end

local function modifyTag(1)
tag.name = " good"
end

if badTagName then
modifyTag(badTagName)
end 

That obviousely didn’t work. I gathered some piece of code here and there, not at random, but not really knowing if it fits together. It gives me this error :

attempt to index a nil value (global'tag')

Basically, I would like to look for a particular string in the tag name, and if the string is in the tag name, change it with another one.

adult_char_down
change the word ‘adult’ for the word ‘kid’ would give
kid_char_down

I think the issue here is the 1 in the list of arguments of modifyTag, try this:

local function modifyTag(tag)
  tag.name = " good"
end

Anyway to get the desired result you are looking for something like this I guess:

local function modifyTag(tag)
  tag.name = name1 .. " good"
end

Using the name1 part of the name but changing bad with good.
I hope it helps!

Thanks a lot, once again.
I found a solution that works :slight_smile:

local sprite = app.activeSprite

for i, tag in ipairs(sprite.tags) do

local name = tag.name
tag.name = (string.gsub(name, "old string", "new string"))

end
2 Likes

Hi @Arkogelul! ^^

Would you mind sharing the final script so I can add it to this thread?

I don’t mind at all. The final script is in my last post. I’m planning to improve it a bit though. I’d like to add an interface and the ability to add a string before or after. I don’t how to deal with the interface yet. I will have to check on this.

2 Likes

Thanks! I went and made that interface for you! :wink:

imagen

Also I uploaded to a github repo for Aseprite scripts, I hope you don’t mind :slight_smile:

You can download the script here.

2 Likes

OMG you’re amazing! Thank you so much :grinning:

I’m glad you liked it! :smiley:

I went and added also the prefixes and suffixes functionality ^^

imagen

2 Likes

Haha! You’re great :grinning_face_with_smiling_eyes:
Thanks again, that is very thoughtful of you.
I’m glad to contribute to that great community.

1 Like