Premiere/UXP iterating through folders in Bin

Hello!I’m trying to figure out how to get items in a specific bin.Bigger idea is to add clips to the track from a specific folder using clip filename filter.However getItems seems to work fine on the root level, but doesn’t return items within a specific bin. Or I got it wrong how to access it.Here is a sample code:

const rootItem = await project.getRootItem();
const newItems = await rootItem.getItems();
const srcBin = newItems.find((item) => item.name == “SRC”);
(0, utils_1.log)(got bin object: ${srcBin.name})
let mediaitem;
for(let srcBinItem of srcBin.getItems()){
const clipBniItem = ppro.ClipProjectItem.cast(binItem);
if (clipBniItem && (await clipBniItem.getContentType()) === ppro.Constants.ContentType.MEDIA) {
(0, utils_1.log)(media item name: ${clipBniItem.name});
}
}

In the output window I see “got bin object: SRC” so folder is there and then
I’m getting error srcBin.getItems is not a function or its return value is not iterable.

Could someone give me a hint please how to get items from a bin?

The issue is that getItems() returns generic ProjectItem objects.
If an item is a bin (type === 2), you cannot directly call getItems() on it.
You must first cast it to a FolderItem.

Example:

const ppro = require("premierepro");

async function scanBin(bin, depth = 0) {
  const items = await bin.getItems();

  for (const item of items) {
    console.log(item.name, item.type);

    // type 2 = Bin
    if (item.type === 2) {
      const folder = ppro.FolderItem.cast(item);
      if (folder) {
        await scanBin(folder, depth + 1);
      }
    }
  }
}

async function run() {
  const project = await ppro.Project.getActiveProject();
  const root = await project.getRootItem();
  await scanBin(root);
}

run();

The important part is:

const folder = ppro.FolderItem.cast(item);

Only the cast FolderItem exposes getItems() for recursive traversal.

1 Like