Camera Models column - Collate child file metadata for parent folder

Overview:

This script adds a Camera Models column which displays a list of all the camera models used by files within the folder (recursively):

The script also provides an easy starting point should you need to make similar columns for folders to show other data about the files below them.

Installation and Usage:

Requires Directory Opus Pro 12.0 or above.

  • Download: Folder Camera Models.js.txt (1.8 KB)
  • Open Settings > Preferences / Toolbars / Scripts.
  • Drag Folder Camera Models.js.txt to the list of scripts.

A new column will now be available:

  • Script > Camera Models

History:

1.0 (23/Aug/2018):

  • Initial version.

Script code:

The script code from the download above is reproduced below. This is for people browsing the forum for scripting techniques. You do not need to care about this code if you just want to use the script.

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "Folder Camera Models";
	initData.version = "1.0";
	initData.copyright = "(c) 2018 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/camera-models-column-collate-child-file-metadata-for-parent-folder/29717";
	initData.desc = "Column for camera models of files within folders";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var col = initData.AddColumn();
	col.name = "CameraModels";
	col.method = "OnCameraModels";
	col.label = "Camera Models";
	col.justify = "left";
	col.autogroup = true;
}


// Implement the CameraModel column
function OnCameraModels(scriptColData)
{
	var item = scriptColData.item;
	if (!item.is_dir)
	{
		var cameraModel = GetCameraModelFromFile(item);
		if (cameraModel != null)
			scriptColData.value = cameraModel;
		return;
	}

	var isRecursive = true;

	var modelSet = DOpus.Create.StringSetI();

	var folderEnum = DOpus.FSUtil.ReadDir(item, isRecursive);
	while (!folderEnum.complete)
	{
		var childItem = folderEnum.next;
		if (!childItem.is_dir)
		{
			var cameraModel = GetCameraModelFromFile(childItem);
			if (cameraModel != null)
				modelSet.insert(cameraModel);
		}
	}

	if (modelSet.empty)
		return;

	var cameraModels = null;
	for (var e = new Enumerator(modelSet); !e.atEnd(); e.moveNext())
	{
		if (cameraModels == null)
			cameraModels = e.item();
		else
			cameraModels += ("; " + e.item());
	}

	scriptColData.value = cameraModels;
}

function GetCameraModelFromFile(fileItem)
{
	var imageMeta = fileItem.metadata.image;
	if (imageMeta == null)
		return null;

	var cameraModel = imageMeta.cameramodel;
	if (cameraModel == null || typeof(cameraModel) != "string" || cameraModel == "")
		return null;

	return cameraModel;
}
2 Likes