User Tools

Site Tools


List Compatibility Bases

Summary

Below is an example demonstrating how to obtain a list of compatibility bases in the database.

API Areas of Interest

Example

DB_List_Compatibility_Bases.dsa
// DAZ Studio version 4.11.0.94 filetype DAZ Script
 
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// Boolean : A function for testing whether or not a QObject instance
	// inherits one of a list of types
	function inheritsType( oObject, aTypeNames )
	{
		// If the object does not define the 'inherits' function
		if( !oObject || typeof( oObject.inherits ) != "function" ){
			// We are done... it is not a QObject
			return false;
		}
 
		// Iterate over the list of type names
		for( var i = 0, nTypes = aTypeNames.length; i < nTypes; i += 1 ){
			// If the object does not inherit the 'current' type
			if( !oObject.inherits( aTypeNames[i] ) ){
				// Next!!
				continue;
			}
 
			// Return the result
			return true;
		}
 
		// Return the result
		return false;
	};
 
	/*********************************************************************/
	// Array<String> : A function for testing whether an asset container inherits a type
	function isSupportedAssetContainerType( oContainer )
	{
		// Define the list of types that support the getPath()
		var aTypes = [
			"DzCategoryAssetContainer",
			"DzCompatibilityBaseAssetContainer"
		];
 
		// Return the result
		return inheritsType( oContainer, aTypes );
	};
 
	/*********************************************************************/
	// Array<String> : A function for getting the path(s) of an asset container
	function getAssetContainerPath( oContainer, sOwnership, bRecurse )
	{
		// If we do not have a supported asset container
		if( !oContainer || !isSupportedAssetContainerType( oContainer ) ){
			// We are done...
			return [];
		}
 
		// Declare working variable
		var aPaths;
 
		// Get the path of the current container
		var sPath = oContainer.getPath();
		// If we have a path
		if( !sPath.isEmpty() ){
			switch( sOwnership.toLowerCase() ){
				default:
				case "any":
					// Initialize
					aPaths = [ sPath ];
					break;
				case "user":
					// If the container is not vendor owned
					if( !oContainer.isVendor )
					{
						// Initialize
						aPaths = [ sPath ];
					// If the container is vendor owned
					} else {
						// Initialize
						aPaths = [];
					}
					break;
				case "vendor":
					// If the container is vendor owned
					if( oContainer.isVendor )
					{
						// Initialize
						aPaths = [ sPath ];
					// If the container is not vendor owned
					} else {
						// Initialize
						aPaths = [];
					}
					break;
			}
		// If we do not have a path
		} else {
			// Initialize
			aPaths = [];
		}
 
		// If we are recursing
		if( bRecurse ){
			// Declare working variable
			var oChild;
			// Get the number of child containers
			var nChildren = oContainer.getNumChildContainers();
			// Iterate over all child containers
			for( var i = 0; i < nChildren; i += 1 ){
				// Get the 'current' child container
				oChild = oContainer.getChildContainer( i );
 
				// Recurse and collect
				aPaths = aPaths.concat( getAssetContainerPath( oChild, sOwnership, bRecurse ) );
			}
		}
 
		// Return the path(s)
		return aPaths;
	};
 
	/*********************************************************************/
	// Get the asset manager
	var oAssetMgr = App.getAssetMgr();
	// If the asset manager was not found, or we do not
	// have a database to retrieve information from
	if( !oAssetMgr || !oAssetMgr.haveDatabase() ){
		// We are done...
		return;
	}
 
	// Let the user know we are busy
	setBusyCursor();
 
	// Get the top level compatibility bases asset container
	var oContainer = oAssetMgr.getCompatibilityBases( true );
 
	// Define the ownership weare interested in
	var sOwnership = ""; // "vendor", "user"
 
	// Collect the container paths
	var aPaths = getAssetContainerPath( oContainer, sOwnership, true );
 
	// Provide feedback
	print( aPaths.join("\n") );
 
	// Let the user know we are done
	clearBusyCursor();
 
// Finalize the function and invoke
})();