User Tools

Site Tools


Set Content Library Container

Summary

Below are examples demonstrating how to set the active DAZ Studio Formats path, Poser Formats path, Other Import Formats path, Products container, or Categories container in the Content Library pane via script.

API Areas of Interest

Example (DAZ Studio Formats)

Set_Content_Library_DAZ_Studio_Formats_Container.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sPath ){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Get the pane manager
	var oPaneMgr = MainWindow.getPaneMgr();
	// If the pane manager was not found
	if( !oPaneMgr ){
		// We're done...
		return;
	}
 
	// Find the content library pane
	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
	// If the pane was not found
	if( !oPane ){
		// We're done...
		return;
	}
 
	// If the app version is 4.8.1.51 or newer
	if( App.version64 >= 0x0004000800010033 ){
		// Browse to the path
		oPane.browseToNativeFolder( sPath );
	// Otherwise
	} else {
		// Attempt to fall back
		try {
			// Get the asset manager
			var oAssetMgr = App.getAssetMgr();
 
			// Get the content manager
			var oContentMgr = App.getContentMgr();
 
			// Set the base to the first mapped native formats directory
			var sBase = oContentMgr.getContentDirectoryPath( 0 );
 
			// Set the first value to the id of the top-level container,
			// set the second value to the base path within that container
			var aIdPath = [ oAssetMgr.getStudioDirID(), sBase ];
			// Split the relative path into its individual parts
			var aRelativeParts = sPath.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( "/" ) ) );
			}
 
			// Cause the "current" container to change
			oPane.browseToIDPath( aIdPath );
 
			// Cause the "current" container to update
			oPane.updateContainer( aIdPath );
		// Handle errors
		} catch( e ){
			// Define the strings used to provide feedback
			var sTitle = text("Resource Error");
			var sMessage = text("A newer version of %1 is required " +
				"to execute this script.").arg( App.appName );
			var sAccept = text("&OK");
 
			// Provide feedback to the user
			MessageBox.critical( sMessage, sTitle, sAccept );
 
			// We're done...
			return;
		}
	}
 
// Finalize the function and invoke
})( "People/Genesis 3 Female" );

Example (Poser Formats)

Set_Content_Library_Poser_Formats_Container.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sPath ){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Get the pane manager
	var oPaneMgr = MainWindow.getPaneMgr();
	// If the pane manager was not found
	if( !oPaneMgr ){
		// We're done...
		return;
	}
 
	// Find the content library pane
	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
	// If the pane was not found
	if( !oPane ){
		// We're done...
		return;
	}
 
	// If the app version is 4.8.1.51 or newer
	if( App.version64 >= 0x0004000800010033 ){
		// Browse to the path
		oPane.browseToPoserFolder( sPath );
	// Otherwise
	} else {
		// Attempt to fall back
		try {
			// Get the asset manager
			var oAssetMgr = App.getAssetMgr();
 
			// Get the content manager
			var oContentMgr = App.getContentMgr();
 
			// Set the base to the first mapped Poser formats directory
			var sBase = String("%1/Runtime/Libraries").arg( oContentMgr.getPoserDirectoryPath( 0 ) );
 
			// Set the first value to the id of the top-level container,
			// set the second value to the base path within that container
			var aIdPath = [ oAssetMgr.getPoserDirID(), sBase ];
			// Split the relative path into its individual parts
			var aRelativeParts = sPath.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( "/" ) ) );
			}
 
			// Cause the "current" container to change
			oPane.browseToIDPath( aIdPath );
 
			// Cause the "current" container to update
			oPane.updateContainer( aIdPath );
		// Handle errors
		} catch( e ){
			// Define the strings used to provide feedback
			var sTitle = text("Resource Error");
			var sMessage = text("A newer version of %1 is required " +
				"to execute this script.").arg( App.appName );
			var sAccept = text("&OK");
 
			// Provide feedback to the user
			MessageBox.critical( sMessage, sTitle, sAccept );
 
			// We're done...
			return;
		}
	}
 
// Finalize the function and invoke
})( "Character/DAZ People" );

Example (Other Import Formats)

Set_Content_Library_Other_Import_Formats_Container.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sPath ){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Get the pane manager
	var oPaneMgr = MainWindow.getPaneMgr();
	// If the pane manager was not found
	if( !oPaneMgr ){
		// We're done...
		return;
	}
 
	// Find the content library pane
	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
	// If the pane was not found
	if( !oPane ){
		// We're done...
		return;
	}
 
	// If the app version is 4.8.1.51 or newer
	if( App.version64 >= 0x0004000800010033 ){
		// Browse to the path
		oPane.browseToImportFolder( sPath );
	// Otherwise
	} else {
		// Attempt to fall back
		try {
			// Get the asset manager
			var oAssetMgr = App.getAssetMgr();
 
			// Get the content manager
			var oContentMgr = App.getContentMgr();
 
			// Set the base to the first mapped other import formats directory
			var sBase = oContentMgr.getImportDirectoryPath( 0 );
 
			// Set the first value to the id of the top-level container,
			// set the second value to the base path within that container
			var aIdPath = [ oAssetMgr.getImportDirID(), sBase ];
			// Split the relative path into its individual parts
			var aRelativeParts = sPath.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( "/" ) ) );
			}
 
			// Cause the "current" container to change
			oPane.browseToIDPath( aIdPath );
 
			// Cause the "current" container to update
			oPane.updateContainer( aIdPath );
		// Handle errors
		} catch( e ){
			// Define the strings used to provide feedback
			var sTitle = text("Resource Error");
			var sMessage = text("A newer version of %1 is required " +
				"to execute this script.").arg( App.appName );
			var sAccept = text("&OK");
 
			// Provide feedback to the user
			MessageBox.critical( sMessage, sTitle, sAccept );
 
			// We're done...
			return;
		}
	}
 
// Finalize the function and invoke
})( "Folder/SubFolder/SubSubFolder" );

Example (Products)

Set_Content_Library_Product_Container.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sProductName, sGuid ){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Get the pane manager
	var oPaneMgr = MainWindow.getPaneMgr();
	// If the pane manager was not found
	if( !oPaneMgr ){
		// We're done...
		return;
	}
 
	// Find the content library pane
	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
	// If the pane was not found
	if( !oPane ){
		// We're done...
		return;
	}
 
	// If the app version is 4.8.1.51 or newer
	if( App.version64 >= 0x0004000800010033 ){
		// Browse to the category
		oPane.browseToProduct( sProductName );
	// Otherwise
	} else {
		// Attempt to fall back
		try {
			// Set the intermediate to the first character of the product name
			var sFirst = sProductName.substring( 0, 1 );
 
			// Define the list of first words to skip
			var aSkip = [ "The", "A", "An" ];
 
			// Split the product name into words
			var aWords = sProductName.split( " " );
 
			// If there are multiple words and the first one is in the list
			if( aWords.length > 1 && aSkip.indexOf( aWords[ 0 ] ) > -1 ){
				// Set the intermediate to the first character of second word
				sFirst = aWords[ 1 ].substring( 0, 1 );
			}
 
			// Get the asset manager
			var oAssetMgr = App.getAssetMgr();
 
			// 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
			var aIdPath = [ oAssetMgr.getProductsID(), sFirst, sGuid ];
 
			// Cause the "current" container to change
			oPane.browseToIDPath( aIdPath );
 
			// Cause the "current" container to update
			oPane.updateContainer( aIdPath );
		// Handle errors
		} catch( e ){
			// Define the strings used to provide feedback
			var sTitle = text("Resource Error");
			var sMessage = text("A newer version of %1 is required " +
				"to execute this script.").arg( App.appName );
			var sAccept = text("&OK");
 
			// Provide feedback to the user
			MessageBox.critical( sMessage, sTitle, sAccept );
 
			// We're done...
			return;
		}
	}
 
// Finalize the function and invoke
})( "Genesis 3 Starter Essentials", "37c74e14-a461-4850-b03a-be7153806f6e" );
//"The Girl 7", "d4073ebf-4915-48dc-ad9d-802f34cad36a"

Example (Categories)

Set_Content_Library_Categories_Container.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sCategoryPath ){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// Get the pane manager
	var oPaneMgr = MainWindow.getPaneMgr();
	// If the pane manager was not found
	if( !oPaneMgr ){
		// We're done...
		return;
	}
 
	// Find the content library pane
	var oPane = oPaneMgr.findPane( "DzContentLibraryPane" );
	// If the pane was not found
	if( !oPane ){
		// We're done...
		return;
	}
 
	// If the app version is 4.8.1.51 or newer
	if( App.version64 >= 0x0004000800010033 ){
		// Browse to the category
		oPane.browseToCategory( sCategoryPath );
	// Otherwise
	} else {
		// Attempt to fall back
		try {
			// Create a new categories table
			var oDBCategory = new DzDBCategoriesTable();
			// Get the category object for the desired relative path
			var oDBCategory = oDBCategory.findCategory( sCategoryPath );
 
			// Initialize an ID path
			var sIdPtah = "";
			// If we have a category
			if( oDBCategory ){
				// Set the relative category index path
				sIdPtah = oDBCategory.getCategoryIDPath().join( "/" );
			}
 
			// Split the category ID path into its parts
			var aIdPath = sIdPtah.split( "/" );
 
			// Cause the "current" container to change
			oPane.browseToIDPath( aIdPath );
 
			// Cause the "current" container to update
			oPane.updateContainer( aIdPath );
		// Handle errors
		} catch( e ){
			// Define the strings used to provide feedback
			var sTitle = text("Resource Error");
			var sMessage = text("A newer version of %1 is required " +
				"to execute this script.").arg( App.appName );
			var sAccept = text("&OK");
 
			// Provide feedback to the user
			MessageBox.critical( sMessage, sTitle, sAccept );
 
			// We're done...
			return;
		}
	}
 
// Finalize the function and invoke
})( "Default/People/Real-World" );