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

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

Community Beginner ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

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";
}

TOPICS
ActionScript , Code , Exchange extensions , How to , Performance , Timeline

Views

612

Translate

Translate

Report

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

correct answers 2 Correct answers

Explorer , Oct 02, 2021 Oct 02, 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,

...

Votes

Translate

Translate
Explorer , Oct 02, 2021 Oct 02, 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";
			
...

Votes

Translate

Translate
Explorer ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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 Beginner ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

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 

Votes

Translate

Translate

Report

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 ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

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";
	}
}

 

Votes

Translate

Translate

Report

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 Beginner ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

Colour me dazzled, thank you very much again for the speedy responses. The code works wonderfully, again! This is helping a ton, especially seeing where my syntax is falling flat. 

 

And you've brought up a good point about the masks -- which I didn't consider until now, haha! Could a workaround then, be something like... guide all layers, except layer masks? 

 

(Piggy-backing off your code, I gave "if(selected.indexOf(i)!=-1) layers[i].layerType="mask";" a go but I couldn't seem to insert it in a place that actually got it to function. So far I've accidentally turned my selected layer into a mask instead haha) 

 

Votes

Translate

Translate

Report

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 ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

Really depends on how you want it to function. If you want only certain types of layers to become guides, you could do a check for the layertype being "normal", where as if you want all layers to become guides and accuratly become the type they were before, something like a layer id system might be helpful. For example; maybe have the layer name be added on to with a small string, and the next time you run the command, it sees this string and can undo what it did.

 

something like _N for normal, _M for mask, _F for folder, and onward

 

Votes

Translate

Translate

Report

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 Beginner ,
Oct 02, 2021 Oct 02, 2021

Copy link to clipboard

Copied

LATEST

Thats solid advice, I'll give that a go and experiment. Thanks very much again for the two cents, been a tremendous help.

Votes

Translate

Translate

Report

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