How to Save a rendered image & Add Canvases

Hello, I have just started with Daz scripting. I'm trying to load a file, add a canvas and save the rendered image as a png. I have been able to load a file, start the render and activate the canvases but I can't find out how to add an Emission or Glossy canvases. I have been able to render an image but I can't activate the render to file. Here is the current code:
 

var TempFile = "Z:/01Test.duf";	var oContentMgr = App.getContentMgr();oContentMgr.openFile(TempFile, false);print("scene Loaded");var TempRenderer = App.getRenderMgr();var TempRenderOptions = TempRenderer.getRenderOptions();TempRenderOptions.renderImgFilename = "Z:/01TestSave.png";TempRenderOptions.renderImgTarget = 2; // Direct to file (doesn't work)TempRenderOptions.applyChanges();//TempRenderOptions.renderImgTold = 2; // Tried this but also doesn't seem to workprint(TempRenderOptions.renderImgFilename);if (!TempRenderer.doRender(TempRenderOptions))	{		MessageBox.critical("Render Canceled. ","Render","&OK","");	}else	{		//TempRenderer.saveLastRender(); // Manual save	}var TempData = App.getRenderMgr().getRenderElementObjects();if(TempData[1].name == "NVIDIA Iray Render Options")	{	if(TempData[1].getProperty(3).name == "Max Time")		{		var TempProperty = TempData[1].getProperty(3); // Max Time		TempProperty.setValue(200);		print("Max Time:"+TempProperty.getValue());		TempData[1].renderToCanvases = true;        // I have manually added a canvas for testing how to add one and this gives me it's name but I can't add one by script		print("Canvas:"+TempData[1].getCanvasDefinition(0).name);		//TempData[1].clearCanvasDefitions();		}	else		{			MessageBox.critical("Property 'Max Time' not found.","Render","&OK","");		}	}else	{		MessageBox.critical("Could not find 'NVIDIA Iray Render Options'.","Render","&OK","");	}print("Script Ended.");

This thread has helped a lot but I'm missing information on how to add a canvas: https://www.daz3d.com/forums/discussion/196346/how-to-access-advanced-section-in-iray-render-settings

Thanks.

Comments

  • findCanvasDefition with second parameter set to true adds new canvas ! ;-)

  • XiaojingXiaojing Posts: 14

    Hi, I tried the findCanvasDefition code.

    var TempData = App.getRenderMgr().getRenderElementObjects();if(TempData[1].name == "NVIDIA Iray Render Options"){		TempData[1].renderToCanvases = true;		TempData[1].findCanvasDefition("Depth", true)}

    I want add depth canvas,  it raised error.

    Script Error: Line 8TypeError: Result of expression 'TempData[1].findCanvasDefition' [undefined] is not a function.Stack Trace: ()@:8

    Is it my fault?

    BTW, I am new to DAZ script, so I want to how to find these api information.

    Thanks!

  • SimonJMSimonJM Posts: 5,942
    edited July 2020

    Is it not spelled Definition?

    Post edited by SimonJM on
  • XiaojingXiaojing Posts: 14
    SimonJM said:

    Is it not spelled Definition?

    Yes, Thank youyes. It is ok. I just copy, not check. Now I face another problem, how to change the canvas type. 

    The class is DzIrayCanvasDefinition. Where can I find its function members? I can't find it in api reference. So I want to know how you use these APIs. 

    Thank you for your reply.

  • XiaojingXiaojing Posts: 14

    Hi everyone, I find how to know one class's members and how to change canvas type.

    var TempData = App.getRenderMgr().getRenderElementObjects();if(TempData[1].name == "NVIDIA Iray Render Options"){		TempData[1].renderToCanvases = true;		var oCanvas = TempData[1].findCanvasDefinition("Canvas", true)		var oCanvas = TempData[1].getCanvasDefinition(0)		for(name in oCanvas){      // print its members			print(name)			print(oCanvas[name])		}       oCanvas.canvasType = 10   // depth is 10}

    I’m not familiar with JavaScript, otherwise I can know how to do it earlier

  • privatepixels99privatepixels99 Posts: 35
    edited January 2022

    This works for me to dump the render straight to a file:

    renderOptions.renderImgTold = "DirectToFile";

     

    Post edited by privatepixels99 on
  • privatepixels99 said:

    This works for me to dump the render straight to a file:

    renderOptions.renderImgTold = "DirectToFile";

    The type of value that DzRenderOptions.renderImgToId holds is DzRenderOptions::RenderImgTarget (i.e., an enumerated value - which can be substituted with the Number represented by the named value), not String - see http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/renderoptions_dz.

  • Xiaojing said:

    Hi everyone, I find how to know one class's members and how to change canvas type.

    var TempData = App.getRenderMgr().getRenderElementObjects();if(TempData[1].name == "NVIDIA Iray Render Options"){		TempData[1].renderToCanvases = true;		var oCanvas = TempData[1].findCanvasDefinition("Canvas", true)		var oCanvas = TempData[1].getCanvasDefinition(0)		for(name in oCanvas){      // print its members			print(name)			print(oCanvas[name])		}       oCanvas.canvasType = 10   // depth is 10}

    I’m not familiar with JavaScript, otherwise I can know how to do it earlier

    Note that undocumented features which you figure out by diging are not at all gur=aranteed to be safe - they may eb chnaged as any time, without notice - so don't rely on them in work you are doing for others or which you need to work reliably over an extended period.

Sign In or Register to comment.