User Tools

Site Tools


List Product Files

Summary

Below is an example demonstrating how you can, using the identifier for the store and the token for the product, retrieve a list of files in the product.

API Areas of Interest

Example

DB_List_Product_Files.dsa
// DAZ Studio version 4.9.3.39 filetype DAZ Script
 
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( sStoreID, sToken ){
 
	// 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;
	}
 
	// Get whether we can use DzScriptHandle; i.e., 4.15.0.6+
	var bHaveScriptHandle = typeof( DzScriptHandle ) == "function";
 
	// Declare working variables
	var oProductHandle;
	var oProduct;
 
	// If we can use DzScriptHandle
	if( bHaveScriptHandle ){
		// Get the product, using the store identifier and product token (SKU);
		// wrap the object in a script handle to manage lifetime
		oProductHandle = new DzScriptHandle( oAssetMgr.findProductByStoreToken( sStoreID, sToken ) );
		// Get the product in the handle
		oProduct = oProductHandle.object;
	// If we cannot use DzScriptHandle
	} else {
		// Get the product, using the store identifier and product token (SKU)
		oProduct = oAssetMgr.findProductByStoreToken( sStoreID, sToken );
	}
 
	// If we do not have the product
	if( !oProduct ){
		// We are done...
		return;
	}
 
	// Declare working variables
	var oAssetHandle;
	var oAsset;
 
	// Get the list of assets in the product
	var aAssetList = oProduct.getAssets();
	// Get the number of assets
	var nAssets = aAssetList.length;
 
	// Pre-size an array to collect asset paths
	var aAssetPaths = new Array( nAssets );
 
	// Iterate over the assets
	for( var i = 0; i < nAssets; i += 1 ){
		// If we can use DzScriptHandle
		if( bHaveScriptHandle ){
			// Get the 'current' asset;
			// wrap the object in a script handle to manage lifetime
			oAssetHandle = new DzScriptHandle( aAssetList[ i ] );
			// Get the DzAsset in the handle
			oAsset = oAssetHandle.object;
		// If we cannot use DzScriptHandle
		} else {
			// Get the 'current' asset;
			oAsset = aAssetList[ i ];
		}
 
		// Capture the relative file path of the asset
		aAssetPaths[ i ] = oAsset.getRelativeFilePath();
	}
 
	// Define an object to hold our data
	var oData = {};
 
	// Capture the store identifier
	oData["store"] = oProduct.store;
 
	// Capture the token (SKU)
	oData["token"] = oProduct.token;
 
	// Capture the name of the product
	oData["name"] = oProduct.title;
 
	// Capture the (sorted) list of user-facing assets
	oData["assets"] = aAssetPaths.sort();
 
	// Capture the (sorted) list of support files
	oData["support_files"] = oProduct.getSupportFiles().sort();
 
	// Inspect the captured data
	print( JSON.stringify( oData, undefined, "\t" ) );
 
// Finalize the function and invoke
})( "DAZ 3D", "42071" );