Function to get Project Item by Name

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
sundstedt
Posts: 15
Joined: November 30th, 2007, 8:46 am

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
lya98
Posts: 15
Joined: December 7th, 2006, 10:39 pm

Thanks for posting! It's pretty useful. I'm surprised there isn't a built in function to retrieve a comp items name.
Post Reply