Skip to main content
Inspiring
November 13, 2020
Answered

Looking for a JSFL script to prefix layers names with numbers in the timeline

  • November 13, 2020
  • 1 reply
  • 815 views

I need this to only run on layers in the active/open timeline and not go diving into symbols, etc.

 

So for example, the layers…

Man

Woman

Dog

Background

 

Would change to…

01 Man

02 Woman

03 Dog

04 Background

 

I found this in the Illustator forum, and I assumed the syntax would be similar but I can't get it to work.

 

var docRef = app.activeDocument;
with (docRef) {
     for (var i = 0; i < layers.length; i++) {
          layers.name = layers.length - i;
     }
}

 

Any help is appreciated!

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

Save this script in a .jsfl file using any text editor and execute it. Pleace notice that this script will prompt you to turn off the advanced layers mode first because layers cannot start with numbers in this mode.

 

var dom = fl.getDocumentDOM();
var timeline = dom.getTimeline();
var layers = timeline.layers;
var turnOffAdvancedLayers;

function main()
{	
	turnOffAdvancedLayers = confirm("For this script to work, the advanced layers mode needs do be turned off first. Do you want to continue?");
	
	if (!turnOffAdvancedLayers)
		return;
	
	timeline.advancedLayersEnabled = false;

	layers.forEach(function(layer, index)
	{
		layer.name = zeropad(index, 2) + " " + layer.name;
	});
}

function zeropad(number, length) {
   
    var str = '' + number;
	
    while (str.length < length)
		str = '0' + str;
   
    return str;
}

main();

 

Learn more about scripting with JSFL and creating extensions for Animate in the following links:

https://www.adobe.io/apis/creativecloud/animate.html

https://www.adobe.io/apis/creativecloud/animate/docs.html

https://help.adobe.com/archive/pt_BR/flash/cs5/flash_cs5_extending.pdf

 

Regards,

JC

 

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
November 13, 2020

Hi.

 

Save this script in a .jsfl file using any text editor and execute it. Pleace notice that this script will prompt you to turn off the advanced layers mode first because layers cannot start with numbers in this mode.

 

var dom = fl.getDocumentDOM();
var timeline = dom.getTimeline();
var layers = timeline.layers;
var turnOffAdvancedLayers;

function main()
{	
	turnOffAdvancedLayers = confirm("For this script to work, the advanced layers mode needs do be turned off first. Do you want to continue?");
	
	if (!turnOffAdvancedLayers)
		return;
	
	timeline.advancedLayersEnabled = false;

	layers.forEach(function(layer, index)
	{
		layer.name = zeropad(index, 2) + " " + layer.name;
	});
}

function zeropad(number, length) {
   
    var str = '' + number;
	
    while (str.length < length)
		str = '0' + str;
   
    return str;
}

main();

 

Learn more about scripting with JSFL and creating extensions for Animate in the following links:

https://www.adobe.io/apis/creativecloud/animate.html

https://www.adobe.io/apis/creativecloud/animate/docs.html

https://help.adobe.com/archive/pt_BR/flash/cs5/flash_cs5_extending.pdf

 

Regards,

JC

 

Inspiring
November 13, 2020

Thanks for the script and the helpful links!

JoãoCésar17023019
Community Expert
Community Expert
November 13, 2020

You're welcome!