User Tools

Site Tools


Mark Selected Assets As New

Summary

Below is an example demonstrating how you can mark the selected assets in the Content Library pane as 'new' (untouched), via script.

API Areas of Interest

Example

Mark_Selected_Assets_New.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	// Get the pane manager
	var oPaneMgr = MainWindow.getPaneMgr();
	// Find the content library pane
	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
	// If the pane was not found
	if( !oPane ){
		// We are done...
		return;
	}
 
	// Declare working variables
	var oAsset, oMeta, oInstance;
 
	// Get the selected assets
	var aAssets = oPane.getSelectedAssets();
	// Iterate over the selected assets
	for( var i = 0, nAssets = aAssets.length; i < nAssets; i += 1 ){
		// Get the 'current' asset
		oAsset = aAssets[ i ];
		// If the app version is 4.9.0.11 or newer
		if( App.version64 >= 0x000400090000000b ){
			// Set the group identifier to the "New" group
			oAsset.groupId = -1; //0 = None, -1 = New
		// Otherwise
		} else {
			// Attempt to fall back
			try {
				// Get the metadata for the asset
				oMeta = oAsset.getMetadata();
				// Mark the item as 'new'
				oMeta.newItem = true;
				// Propagate the change
				oMeta.update();
			// Handle errors
			} catch( e ){
				// Define the strings used to provide feedback
				var sTitle = qsTr("Resource Error");
				var sMessage = qsTr("A newer version of %1 is required " +
					"to execute this script.").arg( App.appName );
				var sAccept = qsTr("&OK");
 
				// Provide feedback to the user
				MessageBox.critical( sMessage, sTitle, sAccept );
 
				// We are done...
				break;
			}
		}
	}
 
	// Get the selected container
	var oContainer = oPane.getSelectedContainer();
	// Force a redraw of the assets
	oPane.updateContainer( oContainer.getIDPath() );
 
// Finalize the function and invoke
})();