I did not find a way of getting a Project Item by it's name, so I wrote this little function to allow you to directly refer to a Project item by it's name (assuming you know the name). This way you do not have to use the index number. Use the name of the item as the parameter, see the example below
Code: Select all
// Function projectItem()
// Author: Anders Sundstedt
function projectItem(name)
{
var items = app.project.items;
i = 1;
while (i <= items.length) {
if (items[i].name == name)
{
return app.project.item(i);
break;
}
i++;
}
}
And here is an example of using it. Assuming there is a folder named 'folder' in the Project Window. This line will add a new comp within the folder called 'folder':
Code: Select all
newComp = projectItem("folder").items.addComp("Lower-Level Comp", 640, 480, 1.0, 5.0, 25.0);
Copy and paste, or download the Script
http://www.sundstedt.se/aescripts/projectItem.jsx