Page 1 of 1

Function to get Project Item by Name

Posted: December 12th, 2007, 10:33 am
by sundstedt
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 :D

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

Thanks!

Posted: January 9th, 2008, 8:23 am
by lya98
Thanks for posting! It's pretty useful. I'm surprised there isn't a built in function to retrieve a comp items name.