Is automatically saving the opened file as scene if the rendered image gets saved possible?

Hi, I'm currently fixing my biggest issue that I constantly have:
"rendering a few dozens different poses of a character only to then want to go back and edit a few things in one of them and because I forgot to save the final version with that pose I have to recreate it again"
It literally happens twice daily, so now I am looking to create a script for DAZ that runs in the background and notices if I save a rendered image and then saves that open file under the same name that gave the just saved image. 
Is this even possible and if yes can you point me in the right direction? Or do I have to find another way of doing things? 
I have prior knowdledge of C# btw so you don't have to overly simplify explanations :)

Thanks in advance <3

Comments

  • Richard HaseltineRichard Haseltine Posts: 80,539
    edited September 2020
    Post edited by Richard Haseltine on
  • Thank you very much for your answer, in the meantime I searched a bit more and stumbled upon this right here:
    http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/rendering/render_post_process/start
    Could I just insert a script there that saves the scene which is open now under the name of the finished render?

  • Probably, I thought ypu wanted to save before the render in case of problems during.

  • I tried to do it with my very limited javascript knowledge and kind of failed...
    Most of the code posted below is from here I just added 1 Line (marked by the comment "Directly below is the Line I added and which doesn't seem to work") hoping it would just save the scene under the name of the image but instead of doing that it literally does nothing with this line of code. It opens the image just fine (the line directly above) but it just won't save the scene. 

    (function( aArgs ){		// Declare working variables	var vArg;	var sType, sAbsolutePath;		// If the application version is 4.9.3.29 or newer	var bUseNewAPI = (App.version64 &gt;= 0x000400090003001d);		// Create a new file info object	var oFileInfo = new DzFileInfo( "" );			// Iterate over the arguments passed to the script	for( var i = 0, nArgs = aArgs.length; i &lt; nArgs; i += 1 ){		// Get the 'current' argument		vArg = aArgs[ i ];				// Get the 'current' type		sType = typeof( vArg );				// If the argument is not a string		if( sType != "object" ){			// Next!!			continue;		}				// If we are using the new API		if( bUseNewAPI ){			oFileInfo.setFile( vArg );		// Otherwise		} else {			// Clean up; do not leak memory			oFileInfo.deleteLater();			// Create a new file info object			oFileInfo = new DzFileInfo( vArg );		}				// If the file exists on disk		if( oFileInfo.exists() ){			// If we are using the new API			if( bUseNewAPI ){				// Get the absolute path of the file				sAbsolutePath = oFileInfo.absoluteFilePath();			// Otherwise			} else {				// Get the absolute path of the file				sAbsolutePath = oFileInfo.absFileName();			}						// Prompt the operating system to perform its default handling of the given file type			App.showURL( String("file:///%1").arg( sAbsolutePath ) );			//Directly below is the Line I added and which doesn't seem to work			saveScene( String(oFileInfo.completeBaseName))						}	}		// Clean up; do not leak memory	oFileInfo.deleteLater();	// Finalize the function and invoke})( getArguments() );

    Can anyone of you guys please help me out?

  • I think you need to use App.getSaveFilterManager() to get (a pointer to) the Save Filter Manager, then you can use saveScene( name ) on that - at the moment you are trying to use a global saveScene function, which doesn't exist.

  • Sorry, I pointed you to the wrong object for saving - that is for the older formats, and DS no longer writes .daz files. I should have sent you to DzAssetIOMgr http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/assetiomgr_dz . Rob has posted a sample for saving a scene http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/save_duf_scene/start

  • I don't know if I'm just confused, but the post processing script seems to open itself again when saving the preview thumbnail picture for the scene and I seem to get thrown into an endless loop. :)

  • Well, the thumbnail is a render. Looking at the dSaveWithOptions method there is a Boolean that can be used to save only the .duf file, with no thumbnail. http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/assetiomgr_dz#a_1a583b7d4a01c5dc84e3b80729636badab

  • OmnifluxOmniflux Posts: 250
    edited September 2020

    Here's a quick example script to do this, it does not automatically save in the same location as the render, as the rendered image filename and the scene thumbnail filename will be the same.

     

    
    // DAZ Studio version 4.12.1.118 filetype DAZ Script
    
    // To prevent processing thumbnails recursively we use a global variable.
    if (typeof (g_nPostProcessScriptInProgress) === typeof (undefined))
    	g_nPostProcessScriptInProgress = 0;
    
    (function () {
    	var sSaveDirectory = &quot;E:/&quot;;
    
    	try {
    		if (g_nPostProcessScriptInProgress++ &gt; 0) {
    			debug (&quot;Render post process script skipping apparent thumbnail (recursive depth: &quot; + g_nPostProcessScriptInProgress + &quot;)&quot;);
    			return;
    		}
    	
    		// Get the filename of the first saved render
    		var sFileName = getArguments()[0];
    		var oFileInfo = new DzFileInfo (sFileName);
    		oFileInfo.setFile (sFileName);		// Constructor is not doing this - why?
    		sFileName = oFileInfo.completeBaseName();
    
    		// Get the filename of the scene to save
    		sFileName = sSaveDirectory + &quot;/&quot; + sFileName;
    	
    		// Setup infrastructure to save a scene		
    		var oAssetIOMgr = App.getAssetIOMgr();
    		var oAssetIOFilter = oAssetIOMgr.getFilter (oAssetIOMgr.findFilter (&quot;DzSceneAssetFilter&quot;));
    		var oSettings = new DzFileIOSettings();
    		oAssetIOFilter.getDefaultOptions (oSettings);
    		oSettings.setBoolValue (&quot;RunSilent&quot;, true);
    
    		// Save the scene
    		var oError = oAssetIOMgr.doSaveWithOptions (oAssetIOFilter, oSettings, false, sFileName);
     		if (oError.valueOf() != 0)
    			throw (getErrorMessage (oError));
    		App.log (&quot;Render post process script saved scene: &quot; + sFileName)
    
    	} catch (oError) {
    		App.warning (&quot;Render post process script error: &quot; + oError)
    	} finally {
    		g_nPostProcessScriptInProgress--;
    	}
    })();

     

    Post edited by Omniflux on
  • I just realized I missed an important use case. This script will not work correctly when saving a scene directly, so don't use as is! :)

  • I'd really like a way to tell if the post process script is being called for a thumbnail. Without being able to do so, I think this is the closest I can get...

    // DAZ Studio version 4.12.1.118 filetype DAZ Script// To prevent processing thumbnails recursively we use a global variable.if (typeof (g_nPostProcessScriptInProgress) === typeof (undefined))	g_nPostProcessScriptInProgress = 0;(function () {	var sSaveDirectory = "E:/";	try {		// Get the filename of the first saved render		var sFileName = getArguments()[0];		var oFileInfo = new DzFileInfo (sFileName);		oFileInfo.setFile (sFileName);		// Constructor is not doing this - why?		sFileName = oFileInfo.completeBaseName();		// Abort if it looks like a thumbnail		if (g_nPostProcessScriptInProgress++ &gt; 0 || sFileName.endsWith (".duf")) {			debug ("Render post process script skipping apparent thumbnail (recursive depth: " + g_nPostProcessScriptInProgress + ")");			return;		}			// Get the filename of the scene to save		sFileName = sSaveDirectory + "/" + sFileName;			// Setup infrastructure to save a scene				var oAssetIOMgr = App.getAssetIOMgr();		var oAssetIOFilter = oAssetIOMgr.getFilter (oAssetIOMgr.findFilter ("DzSceneAssetFilter"));		var oSettings = new DzFileIOSettings();		oAssetIOFilter.getDefaultOptions (oSettings);		oSettings.setBoolValue ("RunSilent", true);		// Save the scene		var oError = oAssetIOMgr.doSaveWithOptions (oAssetIOFilter, oSettings, false, sFileName); 		if (oError.valueOf() != 0)			throw (getErrorMessage (oError));		App.log ("Render post process script saved scene: " + sFileName)	} catch (oError) {		App.warning ("Render post process script error: " + oError)	} finally {		g_nPostProcessScriptInProgress--;	}})();

     

  • Omniflux said:

    I'd really like a way to tell if the post process script is being called for a thumbnail. Without being able to do so, I think this is the closest I can get...

    // DAZ Studio version 4.12.1.118 filetype DAZ Script// To prevent processing thumbnails recursively we use a global variable.if (typeof (g_nPostProcessScriptInProgress) === typeof (undefined))	g_nPostProcessScriptInProgress = 0;(function () {	var sSaveDirectory = "E:/";	try {		// Get the filename of the first saved render		var sFileName = getArguments()[0];		var oFileInfo = new DzFileInfo (sFileName);		oFileInfo.setFile (sFileName);		// Constructor is not doing this - why?		sFileName = oFileInfo.completeBaseName();		// Abort if it looks like a thumbnail		if (g_nPostProcessScriptInProgress++ &gt; 0 || sFileName.endsWith (".duf")) {			debug ("Render post process script skipping apparent thumbnail (recursive depth: " + g_nPostProcessScriptInProgress + ")");			return;		}			// Get the filename of the scene to save		sFileName = sSaveDirectory + "/" + sFileName;			// Setup infrastructure to save a scene				var oAssetIOMgr = App.getAssetIOMgr();		var oAssetIOFilter = oAssetIOMgr.getFilter (oAssetIOMgr.findFilter ("DzSceneAssetFilter"));		var oSettings = new DzFileIOSettings();		oAssetIOFilter.getDefaultOptions (oSettings);		oSettings.setBoolValue ("RunSilent", true);		// Save the scene		var oError = oAssetIOMgr.doSaveWithOptions (oAssetIOFilter, oSettings, false, sFileName); 		if (oError.valueOf() != 0)			throw (getErrorMessage (oError));		App.log ("Render post process script saved scene: " + sFileName)	} catch (oError) {		App.warning ("Render post process script error: " + oError)	} finally {		g_nPostProcessScriptInProgress--;	}})();

     

    You literally made my day, thank you so much, it works flawlessly from what I can tell :)

Sign In or Register to comment.