Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Empty layer

Explorer ,
Nov 19, 2020 Nov 19, 2020

Hello.

 

Is there a way to delete all empty layers on adobe animate?

 

Thanks

451
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 19, 2020 Nov 19, 2020

Hi.

 

This script should be able to remove all layers in a document.

 

WARNING:

Please save your document first and also make a backup of it in case of an unwanted result or errors.

 

 

 

var dom, libray, items, layersCount, deleted;
var symbols = ["button", "graphic", "movie clip"];

function main()
{
	dom = fl.getDocumentDOM();
	
	if (!dom)
	{
		alert("Please open up a document first.");
		return;
	}
	
	var i, total;
	
	library = dom.library;
	items = library.items;
	layersCount = 0;
	deleted = 0;
	searchLibrary();
	
	for (i = 0, total = dom.timelines.length; i < total; i++)
		searchTimeline(dom.timelines[i]);
	
	alert(deleted + " layers of " + layersCount + " have been deleted");
}

function searchLibrary()
{
	var i, total, item;
	
	for (i = 0, total = items.length; i < total; i++)
	{
		item = items[i];
		
		if (symbols.indexOf(item.itemType) > -1)
			searchTimeline(item.timeline);
	}
}

function searchTimeline(timeline)
{
	var layers = timeline.layers.reverse();
	var count = 0;
	var i, total, layer;
	
	for (i = 0, total = layers.length; i < total; i++)
	{
		layer = layers[i];
		layersCount++;
		count++;
		
		if (layer.layerType !== "folder")
		{		
			var isEmpty = layer.frames.every(function(frame)
			{
				return frame.isEmpty;
			});
			
			if (isEmpty)
			{
				timeline.deleteLayer(total - count);
				deleted++;
			}			
		}
	}
}

main();

 

 

 

 

Usage:

1 - Just copy and paste it in a text editor and save it with a .jsfl extension or just grab it from the link below.

2 - Double-click the JSFL file or drag and drop it over Animate or go to Commands... > Run Command...

 

File / source / JSFl download:

https://bit.ly/2IQaYIw

 

I hope it helps.

 

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 20, 2020 Nov 20, 2020

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 20, 2020 Nov 20, 2020
LATEST

You're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines