Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions AE script to duplicate and rename.

  • AE script to duplicate and rename.

    Posted by Tom Holmes on October 12, 2015 at 11:28 am

    Hey guys,

    Im trying to create my first script for AE.

    I have a comp called ‘1234_client_project_name_mon’… i want to have a script that duplicates it 6 times and replaces ‘mon’ with tue, wed, thu etc so i end up with 7 identical comps called.
    1234_client_project_name_mon, 1234_client_project_name_tue, 1234_client_project_name_wed etc.

    here what i have so far:

    var day = [“MON”,”TUE”,”WED”,”THU”,”FRI”,”SAT”,”SUN”];
    var active = app.project.activeItem; // defines ‘active’ as the active comp
    var compname = active.name; // defines ‘compname’ as the name of the active comp
    var namearray = compname.split(“_”); // defines ‘namearray’ as array of strings between the underscores.
    var suffix = namearray[namearray.length-1]; // defines ‘suffix’ as the string after the last underscore
    var prefix = compname.replace (new RegExp (suffix, “g”),””); //defines ‘prefix’ as the comp name minus the string after last underscore.
    var activeRoot = app.project.activeItem.parentFolder;

    for (var i=1; i<=6; i++) {
    var newname = (prefix+day[i]);
    active.duplicate();
    active.name=newname;
    }

    this seems to kind of work, but i end up with all the comp names ending in ‘2’ except for the original active item which has been renamed to ‘…_SUN’ (without 2)

    Am i going about it the complete wrong way?

    Thanks

    Tom

    Tom Holmes replied 10 years, 7 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    October 12, 2015 at 4:19 pm

    I think I’d do it like this:


    var days = ["tue","wed","thu","fri","sat","sun"];
    var myComp = app.project.activeItem;
    var myName = myComp.name;
    var newComp;

    for (var i = 0; i < days.length; i++){
    newComp = myComp.duplicate();
    newComp.name = myName.substr(0,myName.length-3) + days[i];
    }

    Dan

  • Tom Holmes

    October 12, 2015 at 4:25 pm

    Thank very much Dan! right as always 🙂

    Tom

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy