FORUMS: list search recent posts

Naming new comps with higher value every time

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>

Jacob Danell
Naming new comps with higher value every time
on Jul 27, 2013 at 10:07:13 pm

Hi! This is now my final stage until my first script is final!
One part of my script generates two new comps. The name of the comps are right now CompCut_001 and CompCut_002. Every time I run the script it generates two new ones but with the same name.
I would need a code that searches the project for folders named CompCut_xxx and if the script fineds "ComCut_002" the next one will be named "CompCut_003".

I have tried some with if and for but I can't figure out how to get it to be named CompCut_xxx.

My script also generates a folder the first time you run it named "Comp Cuts" where all the comps goes, so if it could searched in that specific folder it would be perfect!

Hope you really can help me with this one because I'm stuck :(

Thanks!


Return to posts index

Dan Ebberts
Re: Naming new comps with higher value every time
on Jul 27, 2013 at 10:29:16 pm

You're going to need to loop through all the items in the project bin, looking for comps with names that contain the string "CompCut_". When you find one you could also check to make sure that the name of the parent folder is "Comp Cuts". Then I would split the comp name at "_" and convert the rest to an integer:

var maxCompNum = 0;

// loop through project items...

var mySplit = myCompName.split("_");
maxCompNum = Math.max(parseInt(mySplit[1],10),maxCompNum);


and after your loop is finished:

newCompNum = maxCompNum+1;


Something like that.


Dan



Return to posts index

Jacob Danell
Re: Naming new comps with higher value every time
on Jul 28, 2013 at 11:37:34 pm

I never got it really working but I figured out how to make the script look into the folder, count the items and give the next created comp one higher value.

for (var i = 1; i <= app.project.numItems; i++){
if (app.project.item(i).name == "Comp Cuts" && app.project.item(i) instanceof FolderItem ){
var cutCompFolder = app.project.item(i);
}

var foldernr = cutCompFolder.numItems;

var tempComp1 = app.project.items.addComp("CutComp_"+foldernr, mainWm1theP, mainHm1theP, maincomPA , maincompDur, maincomFR);
var tempComp2 = app.project.items.addComp("CutComp_"+(foldernr+1), mainWtheP, mainHtheP, maincomPA , maincompDur, maincomFR);


The only "problem" (that I can live with but would be nice if it was fixed) is that they are named 1, 2, 3... 8, 9, 10, 11 and so on, so adobe arrange them as 1, 10, 11, 2, 3, 4 and so on. Is there any way to force two digits when creating the number? So it would be 08, 09, 10 and so on.


Return to posts index


Dan Ebberts
Re: Naming new comps with higher value every time
on Jul 28, 2013 at 11:44:33 pm

Something like this should work:

var foldernr = "" + cutCompFolder.numItems;
while (foldernr.length < 2) foldernr = "0" + foldernr;


Dan



Return to posts index


Xavier Gomez
Re: Naming new comps with higher value every time
on Jul 28, 2013 at 11:46:59 pm

var foldernr = cutCompFolder.numItems;
foldernr = (foldernr<10) ? "0"+foldernr.toString() : foldernr.toString();


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]