Check item type (clip, bin, folder, file)

Hello,
I have a code snippet that reads the items in the root of my project.
However, it does not display the folders that exist there.

I’m not sure if the code is suitable for determining the item type.

var activeProject = await app.Project.getActiveProject();
var rootItem = await activeProject.getRootItem();
var items = await rootItem.getItems();

for (const item of items) {
    let eachItem = await app.ClipProjectItem.cast(item);
    if (eachItem ){

        // Code to read the item type. Is it correct?
        let content = await eachItem.getContentType();

        console.log("eachItem : ", eachItem.name);
        console.log("content: ", content); // Is the value of "content" the media type? 1, 2?
    }
}

And… How do I differentiate between CLIP BIN ROOT and FILE (available on CEP panels)?

Thank you in advance :blush:
Joan

getContentType is helpful for differentiating between ClipProjectItem content type, like if it is a sequence, media, and other kind.

You can use console.log(app.Constants.ContentType) to access the definition. 2 refers to Sequence and 1 refers to Media.

Your code does not display the folders because FolderItem cannot be casted be ClipProjectItem. Following code will help differentiate between CLIP and BIN item:

for (const item of items) {
    let eachItem = await app.ClipProjectItem.cast(item);
    if (eachItem){

        // Code to read the item content type. 
        let content = await eachItem.getContentType();

        console.log("eachItem : ", eachItem.name);
        console.log("content: ", content); // 1 = media, 2 = sequence
    }
    else{
        // see if it's folderItem
        let folderItem = app.FolderItem.cast(item);
        if (folderItem){
            console.log("folderItem : ", folderItem.name); // display folder name
        }
    }
}

Unfortunately, there is no API to directly access projectItem type like CEP does at this point. However, the workaround is to check if projectItem can be casted to ClipProjectItem (CLIP) or FolderItem (BIN). If it can’t be casted to both, it is a FILE item. If you see a projectItem can be casted to FolderItem and its name is the same as project name, it’s likely the ROOT item unless user have named some of the bin the same as the project.

Thanks for trying out UXP!

1 Like

Very nice trick!
Thank you very much for the detailed explanations. They help a lot in understanding how UXP works.

2 Likes