[Script] New Frame with only continuous cells

I often need to create frames that keep my continuous layers linked, but are empty otherwise. This is a script that automates this. It makes a regular New Frame, but then deletes any of the newly created cels that are in discontinuous layers, keeping only cels in layers that are marked as continuous.

do
app.transaction(
	function()
		local originalSelection = app.activeCel --Save the selected cel to go back to.
		app.command.NewFrame();
		local newFrame = app.activeFrame; --This should be the new frame since New Frame usually sets it to the new frame.
		assert(newFrame ~= nil and newFrame.frameNumber ~= nil)
		local sprite = newFrame.sprite;
		for i,layer in ipairs(sprite.layers) do
			if(layer.isContinuous == false) then
				local cel = layer:cel(newFrame.frameNumber);
				if(cel ~= nil) then
					app.activeCel = cel
					app.command.ClearCel()
				end
			end
		end
		app.activeCel = originalSelection --Select the cel the user had selected prior to running this script.
	end
)
end

2021 edit: Fixed a bug that caused the script to work or break depending on which cel you previously had selected. I was accidentally saving the original selected cel after creating the new frame rather than before, and if that new cel got cleared, that made the cel object invalid and invalidated the transaction, rolling it back.

3 Likes