Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions SCRIPTING: strip framenumbers from sequence filename…

  • SCRIPTING: strip framenumbers from sequence filename…

    Posted by Barend Onneweer on June 12, 2012 at 9:55 pm

    Hi,

    As promised I’m back for more 😉 And this time I think I’ve got a more complicated question.

    So I’ve got this script automatically creating comps from footage items, and adding them to the Render Que automatically. Working well so far.

    But… since the source files are also image sequences they show up in the Project Window like this: sequencename_[0000-9999].dpx

    When you manually create a comp from footage AE understands to reduce the comp name to ‘sequencename’. But when I use a script to set the name of the comp to the item name of course I get the whole item name.

    I can do something with .substring(0,n), to take only the first part of the name, if the length of the ‘meaningful’ part is consistent. But it’s not of course. So I guess what I need to do is remove anything between brackets and the extension (the latter is easy-ish by getting the .length and substracting 4 and putting that into the substring.

    (I’m actually pretty shocked that this makes sense to me…)

    The code below is what I use to create the comp from the item.

    var myComp = app.project.items.addComp(selectedItems[i].name, selectedItems[i].width, selectedItems[i].height, selectedItems[i].pixelAspect , selectedItems[i].duration, selectedItems[i].frameRate);

    So… what would be the most elegant way to create a comp name without the framenumbers and extension?

    For bonus points: sometimes there is a ‘.’ to separate filename from framenumbers, sometimes there’s an ‘_’ and sometimes there’s nothing. Ideally I’d strip the extension, the framenumbers AND if there’s an underscore or period stip also…

    I’m guessing there’s no way to just use the built-in mechanism in AE through a script?

    Barend

    Raamw3rk – independent colourist and visual effects artist

    Barend Onneweer replied 13 years, 11 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 12, 2012 at 11:40 pm

    Based on what you’ve described, something like this should work:

    myName = selectedItems[i].name;
    myName = myName.substr(0,myName.lastIndexOf(“[“));
    if(myName[myName.length-1] == “.” || myName[myName.length-1] == “_”)
    myName = myName.substr(0,myName.length-1);

    Dan

  • Barend Onneweer

    June 13, 2012 at 5:44 am

    Goodmorning, that works like a charm! And I can actually follow what you did there, so it’ll be a good example for future work. Not sure if I would have found out about the ‘lastIndexOf’ property without help, though.

    Thanks so much. Now I’ll continue coding myself into a corner.

    Barend

    Raamw3rk – independent colourist and visual effects artist

  • Barend Onneweer

    June 13, 2012 at 9:51 pm

    Hi Dan,

    It turns out that when the source item is a movie, the result is that the filename is completely stripped, because it doesn’t find a bracket…

    I’m guessing some kind of extra if statement checking whether there’s a bracket and if no, skipping these lines could solve that but actually putting the syntax together is beyond me at the moment.

    Barend

    Raamw3rk – independent colourist and visual effects artist

  • Dan Ebberts

    June 13, 2012 at 10:04 pm

    I guess I would first strip off the extension (if there is one), then the bracket stuff (and the preceeding “.” or “_”), like this:


    myName = selectedItems[i].name;
    if (myName.indexOf(".") > -1)
    myName = myName.substr(0,myName.lastIndexOf("."));
    if (myName.indexOf("[") > -1){
    myName = myName.substr(0,myName.lastIndexOf("["));
    if(myName[myName.length-1] == "." || myName[myName.length-1] == "_")
    myName = myName.substr(0,myName.length-1);
    }

    Dan

  • Barend Onneweer

    June 13, 2012 at 10:36 pm

    And of course that works like a charm!

    Thanks so much again. I’ll be sure to share the script with the COW community once it’s doing everything it needs to 🙂 Might be back for more help before that though…

    Barend

    Raamw3rk – independent colourist and visual effects artist

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