Info Tip - File Collections

Is it possible in an Info Tip to see if that item belongs to a File Collection?

Add a script column and set infotiponly to True.

Opus Manual

Yes, with a Script Add-In, like so:

function OnInit(initData) {
    initData.name = 'IsCollectionMember';
    initData.version = '1.0';
    initData.copyright = '';
    initData.desc = '';
    initData.default_enable = true;
    initData.min_version = '12.0';

    var col = initData.AddColumn();
    col.method = 'OnIsCollectionMember';
    col.name = 'IsCollectionMember';
    col.label = 'IsCollectionMember';
    col.header = 'IsCollectionMember';
    col.justify = 'center';
    col.defwidth = 6;
    col.autorefresh = 1;
    col.autogroup = true;
}

function OnIsCollectionMember(scriptColData) {
    var fsu = DOpus.FSUtil();
    scriptColData.value = 'no';
    var file = String(scriptColData.item.realpath);
    var folderEnum = fsu.ReadDir('coll://', 'r');
    while (!folderEnum.complete) {
        var folderItem = folderEnum.Next();
        if (String(fsu.Resolve(folderItem)) != file) continue;
        scriptColData.value = 'yes';
        break;
    }
}

ColumnIsCollectionMember.js.txt (962 Bytes)

Copy ColumnIsCollectionMember.js to /scripts, then pick the field in the FileType Editor:


2 Likes

Thank you very much lxp. That works. Is it too hard to modify it to actually give the names of all the collections it belongs to?

Thank you again. I'm studying the script and modifying it. It helped a lot. The first thing I'm changing is that it no longer be recursive. It goes too deep. It takes time and it gives a false positive if a file is inside a folder that is in a collection. The items that are at the root of a collection are important to me. If we go inside folders, I don't consider it a collection anymore.

This is my modified function. It only searches the root items of a collection. It does not stop at the first result. An item could exist in several collections and it returns a list of all the collections that the item belongs to.

function OnIsCollectionMember(scriptColData) {
    var fsu = DOpus.FSUtil();
    scriptColData.value = 'no';
    var file = String(scriptColData.item.realpath);
    var collectionsEnum = fsu.ReadDir('coll://');
	
    while (!collectionsEnum.complete) 
	{
        var collectionsItem = collectionsEnum.Next();
        var collectionName = String(collectionsItem).replace("coll://", "");
        var coll_Enum = fsu.ReadDir(collectionsItem);
		
        while (!coll_Enum.complete) 
		{
			var coll_Item = coll_Enum.Next();
			if (String(coll_Item.realpath) == file) 
            {
                if (scriptColData.value == 'no') scriptColData.value = collectionName;
				else scriptColData.value = scriptColData.value + '\n' + collectionName;
			}
		}
    }
}