[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()
		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;
		local originalSelection = app.activeCel --Save the selected cel to go back to.
		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