Create New Continuous Layer

added couple of lines to add new layer above current active layer + name new layer as "Layer " + number:

app.transaction(function()
    local sprite = app.activeSprite
	local index = app.activeLayer.stackIndex 
	local stack = #sprite.layers 

    -- Create a new layer
    local newLayer = sprite:newLayer()
    newLayer.isContinuous = true 

    -- Creat a cel in the first frame of the layer, without this cels won't link
    sprite:newCel(newLayer, 1)

    -- Get all of the frame numbers into a table/array
    local frames = {}
    for frameNumber, _ in ipairs(sprite.frames) do
        table.insert(frames, frameNumber)
    end

    -- In order to select cels in range we need to specify both layers and frame - cels are their intersection
    app.range.frames = frames
    app.range.layers = {newLayer}

    app.command.LinkCels() 
	
    app.range:clear()
	
	newLayer.stackIndex = index + 1
	newLayer.name = "Layer " .. stack + 1 
end)
2 Likes