Trying to make a script to flip normal maps, can't figure how to do the flip part

Hi, I’m trying to make a simple script to flip the red channel of a selection to make normal maps quicker. I’d like to have a single shortcut for both the channel inversion and the flip horizontal. But I can’t find anything in the API and the function just flips the entire screen, it doesn’t even care about my parameters.
vertical and horizontal (or no params at all) flips the screen horizontally.
Has anyone managed to make a flip on a selection via scripting? Thanks!

Here is what I have so far:

local lay = app.activeLayer
if not lay then return app.alert "There is no active layer" end
app.transaction(
   function()
      app.command.InvertColor {
            ui=false,
            channels=FilterChannels.RED
      }
      
      app.command.Flip{ 
         target=mask,
         orientation=vertical
      }
      
   end)

I got it to work by treating the arguments as strings, enclosing them in quotation marks.

app.command.Flip {
    target = "mask",
    orientation = "vertical"
}

I’ve found that a type definition is helpful.

Barring that, I look at the source code when the docs are ambiguous.

Thank you very much! It indeed works, but now I have an error in aseprite after the script executed. If i click anywhere, it brings the console and say “A problem has occurred. Details: cannot modify the sprite. It is being used by another command. Try again”.
Is this the case on your side when executing the script?

I tried to look at the code and the API but, me not being a developer, my understanding of all this is quite limited.

Now that I tried the script in full, that error message showed up for me… one of the reasons I try to avoid commands :slight_smile: . See if this hack of inverting the mask twice works.

local lay = app.layer
if not lay then return app.alert "There is no active layer" end

app.transaction("Flip Normal Map", function()
    app.command.Flip {
        target = "mask",
        orientation = "vertical"
    }

    app.command.InvertMask()
    app.command.InvertMask()

    app.command.InvertColor {
        ui = false,
        channels = FilterChannels.RED,
    }

    app.command.InvertMask()
    app.command.InvertMask()
end)

app.refresh()

Normal_inverter_script

It works! Thank you very much! <3