Skip to main content
24styx
Participating Frequently
October 2, 2021
Answered

JSFL: How to guide all layers, except selected layer?

  • October 2, 2021
  • 1 reply
  • 1396 views

I'm trying to figure out a way to make a command that guides all layers, except the current layer I have selected. This is what I've cobbled so far, however its fallen flat and I'm unsure how to tackle the syntax from here. Could someone shed some light on how to make the magic happen? Thanks!

 

var doc=fl.getDocumentDOM();
var tl=doc.getTimeline();
var layers=tl.layers;
for(var i=0;i<layers.length;i++)
{
if(an.getDocumentDOM().selection)continue;
else layers[i].layerType="guide";
}

This topic has been closed for replies.
Correct answer Charlie Bickett

Sure! This is where it can get complicated though, since logic to know what layers were masks or folders might be a little harder to program.

Here I replaced the 'continue;' with 'layers[i].layerType="normal";', so it'll make them normal if they are selected

if(fl.getDocumentDOM()){
	var doc=fl.getDocumentDOM();
	var tl=doc.getTimeline();
	var layers=tl.layers;
	var selected=tl.getSelectedLayers();
	for(var i=0;i<layers.length;i++)
	{
		if(selected.indexOf(i)!=-1) layers[i].layerType="normal";
			else layers[i].layerType="guide";
	}
}

 

1 reply

Charlie Bickett
Inspiring
October 2, 2021

Hey! You got pretty close, but the layer selection is 'tl.getSelectedLayers()' and it returns an array of numbers.

Here's the code I wrote based on yours, seems to work pretty well!

if(fl.getDocumentDOM()){
	var doc=fl.getDocumentDOM();
	var tl=doc.getTimeline();
	var layers=tl.layers;
	var selected=tl.getSelectedLayers();
	for(var i=0;i<layers.length;i++)
	{
		if(selected.indexOf(i)!=-1)continue;
			else layers[i].layerType="guide";
	}
}

 Hope that helps! If that's the answer you were looking for, be sure to make this as correct, thanks!

24styx
24styxAuthor
Participating Frequently
October 2, 2021

This works wonderfully, thank you very much. I ran into a new issue I didn't consider -- may I ask, how would you create another "else" statement if, say, I run this command again on a different selected layer -- but because I've ran it the first time, it's already been guided, and as it is right now it doesn't unguide itself. 

 

So I suppose -- what would be the proper syntax to tell Animate, keep the selected layer unguided, and guide out the rest -- and if the selected layer _is_ guided, unguide it and keep the rest unguided. Does this make sense? :B 

Charlie Bickett
Charlie BickettCorrect answer
Inspiring
October 2, 2021

Sure! This is where it can get complicated though, since logic to know what layers were masks or folders might be a little harder to program.

Here I replaced the 'continue;' with 'layers[i].layerType="normal";', so it'll make them normal if they are selected

if(fl.getDocumentDOM()){
	var doc=fl.getDocumentDOM();
	var tl=doc.getTimeline();
	var layers=tl.layers;
	var selected=tl.getSelectedLayers();
	for(var i=0;i<layers.length;i++)
	{
		if(selected.indexOf(i)!=-1) layers[i].layerType="normal";
			else layers[i].layerType="guide";
	}
}