How to append "...save a render as a PNG" to a sample script?

Hi, I'm coming from Python hacking, and am a beginner trying to undertand how DAZ scripts do some very simple things.

How do I add a line or two, perhaps at the end of a render-settings setup script, to tell DAZ....

"OK, now make a render of the scene, and save this render into C:\A_Named_Directory as a .PNG file"

I can find many sample DAZ scripts, but none show how to do this simple task.

Ideally, the saved PNG also has transparency (an alpha) around the rendered scene object (e.g. a simple cube against an empty background).

In Python and Poser, invoking a render and save is as simple as giving the commands:

scene.Render()

scene.SaveImage("png", r"C:\render.png")

 

Comments

  • MartirillaMartirilla Posts: 67
    edited December 2020

    That looks like it's do the job, thanks - I would never have found it if you hadn't pointed me to "Render To Asset Icon".

    Wow, but... 110 lines of code just to save a render! It's a bit different from Poser! :-)

    Post edited by Martirilla on
  • MartirillaMartirilla Posts: 67
    edited December 2020

    Ok, the simplest I can refine it all down to is the following three lines...

    // Set the path.
    oRenderOptions.renderPath = "C:/";
    // Set full path and filename, note that forward slashes are needed in the path.
    oRenderOptions.renderImgFilename = "C:/render.png";
    // Do the render.
    oRenderMgr.doRender();
    
    })();


    To be appended just before the end of the function section, in a script which sets the render options. In the above snippet I'm assuming that the larger script has already set the oRenderMgr and oRenderOptions variables being used, and has set things like DirectToFile and other settings, and has also made sure we are rendering a frame only (not an animation or movie).

    Post edited by Martirilla on
  • algovincianalgovincian Posts: 2,224

    I'm on my phone at the moment, but I believe IIRC you would have to need to pass oRenderOptions in the doRender() call: oRenderMgr.doRender(oRenderOptions), or call oRenderOptions.applyChanges() before calling oRenderMgr.doRender().

    Another approach may be to use presets. For example, if you save out a Render Settings preset (choosing which options to save in the dialog that pops up), then you can do something like:

    var oRenderMgr = App.getRenderMgr();
    var oContentMgr = App.getContentMgr();
    oContentMgr.openFile("myDir/myFile.duf", true);
    oRenderMgr.doRender();

    You can do this with all sorts of presets - it's very powerful.

    HTH.

    - Greg

     

Sign In or Register to comment.