Export As: [ PDF | ODT ]

Set Content Library Container

Summary

Below is an example demonstrating how you can set the active path/container in the Content Library pane via script.

API Areas of Interest

Example

Click the name of the example below to save it as a file.

Set_Content_Library_Container.dsa
// DAZ Studio version 4.5 filetype DAZ Script
 
// Get the pane manager
var oPaneMgr = MainWindow.getPaneMgr();
// Find the content library pane
var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
// If the pane was found
if( oPane ){
	// Get the asset manager
	var oAssetMgr = App.getAssetMgr();
 
	// Get the ids of the various top-level containers
	var sStudioDir = oAssetMgr.getStudioDirID();
	var sPoserDir = oAssetMgr.getPoserDirID();
	var sOtherDir = oAssetMgr.getImportDirID();
	var sProducts = oAssetMgr.getProductsID();
	var sCategories = oAssetMgr.getCategoriesID();
 
	// Get the content manager
	var oContentMgr = App.getContentMgr();
 
	// Declare some variables we need for collecting values
	var sBase, sRelative;
	var aIdPath = [];
 
	// Set the id used by the switches
	var sContainer = sStudioDir;
 
	// Based on which top-level container we need to use,
	// set the base and relative values that define the "path"
	switch( sContainer ){
		case sStudioDir:
			// Set the base to the first mapped native formats directory
			sBase = oContentMgr.getContentDirectoryPath( 0 );
			// Set the relative path to the target directory
			sRelative = "Scripts/Utilities";
			break;
		case sPoserDir:
			// Set the base to the first mapped Poser formats directory
			sBase = String("%1/Runtime/Libraries")
				.arg( oContentMgr.getPoserDirectoryPath( 0 ) );
			// Set the relative path to the target directory
			sRelative = "Character/DAZ People";
			break;
		case sOtherDir:
			// Set the base to the first mapped other import formats directory
			sBase = oContentMgr.getImportDirectoryPath( 0 );
			// Set the relative path to the target directory
			sRelative = "Folder/SubFolder/SubSubFolder";
			break;
		case sProducts:
			// Set the base to the first alpha-numeric character of the product name
			sBase = "D";
			// Set the "relative path" to the product GUID
			sRelative = "3bca6dfe-5c8b-4420-8d3e-d7f2a972416e";
			break;
		case sCategories:
			// Create a new categories table
			var oDBCategory = new DzDBCategoriesTable();
			// Get the category object for the desired relative path
			var oDBCategory = oDBCategory.findCategory("Default/People/Real-World");
			// If we have a category
			if( oDBCategory ){
				// Set the relative category index path
				sRelative = oDBCategory.getCategoryIDPath().join("/");
			}
			break;
	}
 
	// Based on which top-level container we need to use, set the id path array
	// to the values needed to navigate the pane to the desired container
	switch( sContainer ){
		case sStudioDir:
		case sPoserDir:
		case sOtherDir:
			// Set the first value to the id of the top-level container,
			// set the second value to the base path within that container
			aIdPath = [ sContainer, sBase ];
			// Split the relative path into its individual parts
			var aRelativeParts = sRelative.split( "/" );
			// Iterate over each part in the relative path,
			for( var i = 0; i < aRelativeParts.length; i += 1 ){
				// Push the full path of the "current" part onto the id path array
				aIdPath.push( String("%1/%2")
					.arg( sBase )
					.arg( aRelativeParts.slice(0, i + 1).join( "/" ) ) );
			}
			break;
		case sProducts:
			// Set the first value to the id of the top-level container,
			// set the second value to the first character of the product name,
			// set the third value to the product GUID
			aIdPath = [ sContainer, sBase, sRelative ];
			break;
		case sCategories:
			// Set the id path array to the category index path
			aIdPath = sRelative.split("/");
			break;
	}
 
	// Cause the "current" container to change
	oPane.browseToIDPath( aIdPath );
 
	// Cause the "current" container to update
	oPane.updateContainer( aIdPath );
}