rd: Kinda Sorta
added a new ae script: rd: Kinda Sorta.
this one’s been simmering for awhile in the lab, but i decided to “front burner” it based on a request by Phil Spitler on the AE List. you can sort layers by selection order, random order, layer in or out point (honoring negatively stretched layers, too!), or layer name. plus, you can reverse the order, and act on all or selected layers in the comp, for most of these.
nab says:
20-Aug-2007 @ 7:36 pm
Time for brainstorming
May I suggest this snippet for the “random order”, slight modification inside the loop (how to put a link ? http://www.nabscripts.com/Forum/Scripts/rd_order.txt )
Your code generates random indices within the range [0,numLayers] which is not convenient if you use moveBefore and moveAfter.
As you probably noticed, for a given layer there exists two situations that pop up an error: when the generated index 1) is not within the valid range, 2) is the same as the current layer index.
2) is okay as soon as we add an additional “if” statement, and we can avoid 1). Then the try…catch is not necessary anymore as we are sure there won’t be any errors and we produce in the same time a “more random” stack.
Be careful Jeff, script junkies are watching you
redefinery says:
20-Aug-2007 @ 11:05 pm
hey nab… ya gotta cut me some slack for posting a script late on a friday night. besides, haven’t you read the disclaimer that i put in each script: “In other words, I’m just trying to share knowledge with and help out my fellow AE script heads, so don’t blame me if my code doesn’t rate. :-)”? :-), indeed.
i think i was using the original code because the reference for Math.random() i had used said it wouldn’t hit 1, but checking a more authoritative source, it can.
i tried your snippet (thanks for that!), but couldn’t get it to place layers at the top/bottom when using Selected Layers in Comp mode. here’s a proposed solution that should handle situations 1 and 2 a little better…
var lIndex;
for (var i=0; i<layers.length; i++)
{
do
{
lIndex = 1 + Math.round(Math.random() * (comp.numLayers - 1));
}
while (lIndex == layers[i].index);
if (Math.random() > 0.5)
layers[i].moveBefore(comp.layer(lIndex));
else
layers[i].moveAfter(comp.layer(lIndex));
}
what do you think?
(and, yes, i am often surprised/embarrassed at where i find snippets of my code.)
nab says:
21-Aug-2007 @ 12:53 am
I forgot to mention that my snippet was for the “All layers in Comp” mode.
In the initial script the random range covers the whole set of indices, so randomizing only the selected layers makes no sense to me…since a non-selected layer can be swapped as well (when a selected layer takes its place in the stack).
If you want to randomize the selected layers only, you would have to generate random indices among the selected indices, not the whole set
(treat the two cases separately).
I don’t think Math.random() can hit 1 (this snippet might convince you http://www.nabscripts.com/Forum/Scripts/rd_test.txt ) but it’s always hard to check these sort of things in practice.
You are my “scripting teacher” (or guru if you prefer), I wasn’t blaming you
! just a little suggestion with a bit of humor to participate in your blog.
redefinery says:
21-Aug-2007 @ 1:04 am
yeah, Selected Layers mode should be treated separately (and sort/randomize w/o changing indices), but i’ll leave that work for another day. Selected Layers mode was more a ‘freebie’. whether it’s useful is another issue.
it’s definitely cool that you’re providing feedback in my comments. i appreciate it. keeps me honest.
i’m trying to learn this stuff as well. and don’t worry, i like to keep things light/irreverent around here. (Que Es Span Null, anyone?
)
nab says:
21-Aug-2007 @ 6:01 pm
Today I sent you a gift at Adobe Seattle to excuse my irreverent attitude