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";
}
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,
...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";
...
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!
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
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";
}
}
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)
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
Copy link to clipboard
Copied
Thats solid advice, I'll give that a go and experiment. Thanks very much again for the two cents, been a tremendous help.