User Tools

Site Tools


Save a Render Settings Preset

Summary

Below is an example demonstrating how you can use script accessible settings to control the saving of a Render Settings Preset..., without causing the output options or file save dialogs to be displayed.

API Areas of Interest

Example

Save_Render_Settings_Preset.dsa
// DAZ Studio version 4.5.0.40 filetype DAZ Script
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function( bShowOptions ){
 
	// Get the asset IO manager
	var oAssetIOMgr = App.getAssetIOMgr();
	// Define the class name of the asset filter we want to use
	var sClassName = "DzRenderSettingsAssetFilter";
	// Find the index of the asset filter with the class name we want
	var nAssetIOFilter = oAssetIOMgr.findFilter( sClassName );
	// If we didn't find an asset filter with the class name we wanted
	if( nAssetIOFilter < 0 ){
		var sMessage = qsTr("An asset filter with the class name " +
			"\"%1\" could not be found.").arg( sClassName );
		// Inform the user
		MessageBox.critical( sMessage, qsTr("Not Found"), qsTr("&OK") );
 
		// We're done...
		return;
	}
 
	// Get the asset filter at the prescribed index
	var oAssetIOFilter = oAssetIOMgr.getFilter( nAssetIOFilter );
	// If we do not have a valid asset filter
	if( !oAssetIOFilter ){
		// We're done...
		return;
	}
 
	// Create a settings object
	var oSettings = new DzFileIOSettings();
 
	// Get the default settings
	//oAssetIOFilter.getDefaultOptions( oSettings );
 
	// Get the content manager
	var oContentMgr = App.getContentMgr();
 
	// Get the base path - the first mapped content directory
	var sBasePath = oContentMgr.getContentDirectoryPath( 0 );
 
	// If we are showing options, we can override the last saved state
	// by passing in the settings we want to override
	if( bShowOptions ){
		// Set the initial state of the compress file checkbox
		oSettings.setBoolValue( "CompressOutput", false );
	}
 
	// If we cannot get the default/saved options for the asset filter,
	// without displaying the options dialog.
	if( !oAssetIOFilter.getOptions( oSettings, bShowOptions, "" ) ){
		// We're done...
		return;
	}
 
	// If we are not showing options
	if( !bShowOptions ){
		// Don't compress the file
		oSettings.setBoolValue( "CompressOutput", false );
	}
 
	// Don't show the file save dialog
	oSettings.setBoolValue( "RunSilent", true );
 
	// Inspect the settings that will be passed to the asset filter
	print( oSettings.toString() );
 
	// Construct the name of the file to save to
	var sFile = String("%1/%2 Test").arg( sBasePath ).arg( sClassName );
 
	// Use the asset filter to save a file, using the defined settings
	//oAssetIOFilter.doSave( oSettings, sFile, sBasePath );
 
	// Use the asset manager to save a file, using the filter and defined settings
	oAssetIOMgr.doSaveWithOptions( oAssetIOFilter, oSettings,
		false, sFile, sBasePath, "" );
 
// Finalize the function and invoke
})( false );