FORUMS: list search recent posts

Select / Find a file in Project Panel by Word

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Borja Tierra
Select / Find a file in Project Panel by Word
on Mar 23, 2016 at 12:29:09 pm

Hi everyone,

I'm trying to write a script but I'm newbie and it's not working.

I have a bunch of files from different sources. The only thing in common between them are some words in the name, for example FullHD.

What I need is select all the files with the word FullHD in the project panel, and then create a comp with each one.

Can you help me??

Thanks!


Return to posts index

David Conklin
Re: Select / Find a file in Project Panel by Word
on Mar 23, 2016 at 5:25:11 pm

Hey there,

Here's an example of how to do something like this.

The main method you'll be using here is "indexOf()", which basically checks if a string contains another string, and returns where in the string that new string is. For instance, "MyComp_FullHD".indexOf("FullHD") will return 7. The nice part of indexOf() is that it returns -1 if it can't find your string. For instance "MyComp".indexOf("FullHD") will return -1, since it doesn't appear in the string. This is what I'm doing on Ln 31 and is what's filtering your comp items.

The only other tricky part is that making a composition requires 6 parameters (name, width, height, PAR, duration and frame rate). Since certain project items (like a still, or audio) don't have all of these parameters, you need to supply the .addComp() method with fallbacks to handle these situations.

This is what the 'defaults' object on line 6 does. In case the source file you're using doesn't have a frame rate, for example, the script will use defaults.frameRate instead. You can do this by supplying your ideal argument, then an || (or), followed by your default.

For instance projItem.name||defaults.name first tries to use the name of the projItem object, but should it not exist instead uses defaults.name.

Other than that, just change the function call on ln 55 to to use your preferred text filter. Keep in mind, it's case sensitive!

Good luck!

(function makeCompsFromFilesWithWord(thisObj){

// Shortcuts
var proj = app.project;

var defaults = {
name: "Comp",
width: 1920,
height: 1080,
pixelAspect: 1,
duration: 1,
frameRate: 30
}

// function findItemsByWord(theWord)
// This function finds every project item containing theWord
// Args:
// theWord - String - the word to search for.
// Returns
// An array containing all project items with theWord
// in their name.
function findItemsByWord(theWord){

// Holder for items with theWord in their name.
var itms = [];

// Loop through entire project/
for (var i = 1; i &lt;= proj.numItems; ++i){

// does the name of this item have theWord in it?
if(proj.item(i).name.indexOf(theWord) != -1){
itms.push(proj.item(i));
}
}

return itms;

} // end findItemsByWord();


// function makeComps(projItem)
// This function makes a composition out of the project item.
// Args:
// projItem - Project Item - the item to make the comp from.
// Returns:
// The newly created Comp.
function makeComps(projItem){

var theComp = proj.items.addComp(projItem.name||defaults.name, projItem.width||defaults.width, projItem.height||defaults.height, projItem.pixelAspect||defaults.pixelAspect, projItem.duration||defaults.duration, projItem.frameRate||defaults.frameRate);
theComp.layers.add(projItem)
return theComp;

}

// Filter project items.
var getComps = findItemsByWord("FullHD");

// Make a comp for each project item retuned by findItemsByWord()
for(var i = 0; i &lt; getComps.length; ++i){
makeComps(getComps[i]);
}

})(this);


David Conklin
Motion Designer


Return to posts index

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