Script Iray Draw Settings?

Hello--

Is it possible to change Iray Draw Settings via script (not to be confused with Render settings)? Or better yet, is there a way to create and apply an iray draw settings preset?  For example, I would like to change Draw Settings->Drawing->Draw Mode from Photoreal to interactive via script

Thanks!

Comments

  • jag11jag11 Posts: 885

    It is possible by using the Pane Manager, find the pane named "DrawSettings", once you have the pane, grab the Element Editor, which contains the "NVIDIA Iray Draw Options" which is a DzDrawStylePropertyHolder. Although it only works if current draw style is Iray. to change that you need to access the MainWindow.getViewportMgr().getActiveViewport().get3DViewport()

    HTH

  • It looks like that works.  Thanks!

  • SasqwachSasqwach Posts: 25
    edited January 2018

    Hey,

    Curious how'd you manage to get this working as it's something I was trying to do also. I cylced thru all the draw styles, seeing what Get n Set's were available, as I couldnt find any mention of DzDrawSettingsPane in the object Index tho I can get the object and get the element editor for "NVIDIA Iray Draw Options"  I couldnt seem to see means of setting the draw mode, even tho I have switched to the Nvidia draw style. Couldnt find much on the mentioned DzDrawStylePropertyHolder, sorry I am a bit of a noob with scripting, care to share where I am going wrong?

    var oViewportMgr = MainWindow.getViewportMgr();var oViewport = oViewportMgr.getActiveViewport();var o3dViewport = oViewport.get3DViewport();var nDrawStyles = oViewportMgr.getNumUserDrawStyles();var oPaneMgr = MainWindow.getPaneMgr();var oDrawStyle;var oPane;var oIrayDrawOptions;//flip thru the drawstyles n find Irayfor( var i = 0; i < nDrawStyles; i += 1 ){	oDrawStyle = oViewportMgr.getUserDrawStyle( i );	if  (oDrawStyle.getDescription() == "NVIDIA Iray")	{		//lets see whats in here...		for ( var n in oDrawStyle ) 		{			print ( n );		}		//ok set the drawstyle to iray so I can set mode as mentioned by jag11		o3dViewport.setDrawStyle(oDrawStyle);		//get the pane 		oPane = oPaneMgr.findPane( "DzDrawSettingsPane" );		if ( oPane )		{			// get the elements						oIrayDrawOptions = oPane.getElementEditor ("NVIDIA Iray Draw Options");			//lets see whats in here...			for ( var n in oIrayDrawOptions ) 			{				print ( n );			}		   print ("Done");					}	}}

     

     

    Post edited by Sasqwach on
  • jag11jag11 Posts: 885

    Daz Studio Scripting API documentation is a work in progress, so Object Index contains a list of the most important classes. Even if you see a class listed, it is not fully documented as DS is under constant development, so the classes mentioned before are undocumented, what most developers do is inspect the objects to reveal the most up to date exposed interface.

    You can inspect objects by using the familiar "for(var name in objToDump) { print(name); }" code snippet.

    Another source of documentation is the ChangeLog. There you can see that the upcoming 4.11 version exposes the following draw style modes:

    DzPickStyle, DzDefaultStyle, DzUnshadedStyle, DzUserDrawStyle, DzWireBoxStyle, DzSolidBoxStyle, DzWireFrameStyle, DzLitWireFrameStyle, DzHiddenLineStyle, DzWireShadedStyle, DzSmoothShadedStyle, DzWireTexturedStyle, DzTexturedStyle, DzIrayDrawStyle, DzUserDrawStyleAction.

    ​As for the question, to change DrawStyle you need either the DrawSettingsPane or invoke any othe following actions:

    • DzWireBoxStyleAction
    • DzSolidBoxStyleAction
    • DzWireframeStyleAction
    • DzHiddenLineStyleAction
    • DzLitWireframeStyleAction
    • DzWireShadedStyleAction
    • DzSmoothShadedStyleAction
    • DzTexturedStyleAction
    • DzWireTexturedStyleAction
    • DzCartoonStyleAction
    • DzIrayDrawStyleAction

    Look here for a sample to invoke an action.

    HTH

  • Sasqwatch--not sure if this answers your question but I am setting DrawStyle like so:

     

    	// Get the viewport manager	var oViewportMgr = MainWindow.getViewportMgr();	// Get the active viewport	var oViewport = oViewportMgr.getActiveViewport();	// Get the 3D viewport	var o3dViewport = oViewport.get3DViewport();	// Find a DrawStyle by label, "Hidden Line" for example	var oDrawStyle = oViewportMgr.findUserDrawStyle( sDrawStyle );	// Set the DrawStyle	o3dViewport.setDrawStyle( oDrawStyle );

     

  • jag11 said:

    You can inspect objects by using the familiar "for(var name in objToDump) { print(name); }" code snippet.

    I also like "Object.keys(objToDump);"

  • jag11 said:

    It is possible by using the Pane Manager, find the pane named "DrawSettings", once you have the pane, grab the Element Editor, which contains the "NVIDIA Iray Draw Options" which is a DzDrawStylePropertyHolder. Although it only works if current draw style is Iray. to change that you need to access the MainWindow.getViewportMgr().getActiveViewport().get3DViewport()

    HTH

    It looks like I spoke too soon.  this only works if the DrawSettings Pane has been opened during your current session.  If DrawSettings is not part of your layout (not visible), fresh launch of DS, this will ERROR:

    // DAZ Studio version 4.9.3.166 filetype DAZ Script// Find the element first before we can set Propertiesfunction findDrawSettingsElement( sElement ) {    var oPaneMgr = MainWindow.getPaneMgr();    var oDrawSettingsPane = oPaneMgr.findPane("DzDrawSettingsPane");	//oDrawSettingsPane.showPane();    var oElement;    var oElementEditor = oDrawSettingsPane.getElementEditor();        for( var i = 0; i < oElementEditor.getNumElements(); i += 1 ){        oElement = oElementEditor.getElement(i);        if (oElement != null) {            print ("Elem", oElement.name);            if( !sElement.isEmpty() && oElement.name == sElement ){                return oElement;            }        }    }    return null;    }function main() {	var oDrawElement = findDrawSettingsElement("NVIDIA Iray Draw Options");	var oProperty = oDrawElement.findProperty( "Draw Mode" );	oProperty.setValue(0);}main();

    Once you open the DrawSettings pane, it will work.

    The $5mil question...how can I get this to work in one go if the pane has never been opened?

  • SasqwachSasqwach Posts: 25
    edited January 2018

    Hey Honourable Omni & jag11

    Thanks!

    I have found this does the trick to flick between Draw settings Draw mode between interactive & PhotoReal, it's a wee bit of a barbaric mash up between my last code & jag11's suggestions (AFAK it doesn't need the for to go thru nDrawStyles to set to Iray draw style, sure there must be a more elegant way, I just used the samples from Docs page...but as the old programmer adage goes..."works for me!")

    function findDrawSettingsElement( sElement ) {    var oPaneMgr = MainWindow.getPaneMgr();    var oDrawSettingsPane = oPaneMgr.findPane("DzDrawSettingsPane");	//oDrawSettingsPane.showPane();    var oElement;    var oElementEditor = oDrawSettingsPane.getElementEditor();        for( var i = 0; i < oElementEditor.getNumElements(); i += 1 ){        oElement = oElementEditor.getElement(i);        if (oElement != null) {            print ("Elem", oElement.name);            if( !sElement.isEmpty() && oElement.name == sElement ){                return oElement;            }        }    }    return null;    }function main() {	var oViewportMgr = MainWindow.getViewportMgr();	var oViewport = oViewportMgr.getActiveViewport();	var o3dViewport = oViewport.get3DViewport();	var nDrawStyles = oViewportMgr.getNumUserDrawStyles();	var oPaneMgr = MainWindow.getPaneMgr();	var oDrawStyle;	var oPane;	var oIrayDrawOptions;	//flip thru the drawstyles n find Iray	for( var i = 0; i < nDrawStyles; i += 1 )	{		oDrawStyle = oViewportMgr.getUserDrawStyle( i );		if  (oDrawStyle.getDescription() == "NVIDIA Iray")		{			//lets see whats in here...			for ( var n in oDrawStyle ) 			{				//print ( n );			}			//ok set the drawstyle to iray so I can set mode as mentioned by jag11			o3dViewport.setDrawStyle(oDrawStyle);		}	}		var oDrawElement = findDrawSettingsElement("NVIDIA Iray Draw Options");		var oProperty = oDrawElement.findProperty( "Draw Mode" );		var nIncProperty = oProperty.getValue();		print ( nIncProperty );		if ( nIncProperty == 0)		{			oProperty.setValue(1);		}		else if ( nIncProperty == 1)		{			oProperty.setValue(0);		}}main();

    Omni I dont know if this would be exactly what you are looking for because I am making the presumption that the draw settings pane is always open and present in a  session. I aint so au fait with Daz API, but surely there must be a way to invoke and startup the pane or at least instantiate the object without drawing the pane (Tho Jag11's suggestion is only means is to use the findpane method..so...hurrrum..that poses a tough question....no pun intended =D)

    Need to get me those tutorials by Winterbrose, tho they seem to be right from starter level...I used to be a coder in games industry..but man I couldnt keep up and as you both know each API has it's idiosyncrasies, now I am "Senior Technical Producer" that means

    Senior = Old guy
    Technical = Used to be a programmer
    Producer = Can't program anymore, schedules other programmers work

    =D

     

    Post edited by Sasqwach on
  • jag11jag11 Posts: 885

    Omnifreak, I heavily modified your code, now it works as it should without first open the Draw Settings Pane. Let me know if it works for you.

    // DAZ Studio version 4.9.3.166 filetype DAZ Script// Find the element first before we can set Propertiesfunction findDrawSettingsElement( sElement ) {    var oPaneMgr = MainWindow.getPaneMgr();    var oDrawSettingsPane = oPaneMgr.findPane("DzDrawSettingsPane");      	oDrawSettingsPane.showPane();	oDrawSettingsPane.setCurrentTab(0);	processEvents();	    var oElement;    var oElementEditor = oDrawSettingsPane.getElementEditor();        for( var i = 0; i < oElementEditor.getNumElements(); i += 1 ){        oElement = oElementEditor.getElement(i);        if (oElement != null) {            print ("Elem", oElement.name);            if( !sElement.isEmpty() && oElement.name == sElement ){                return oElement;            }        }    }        return null;}function main() {	var oDrawElement = findDrawSettingsElement("NVIDIA Iray Draw Options");	var oProperty = oDrawElement.findProperty( "Draw Mode" );	oProperty.setValue(0);}main();
  • jag11 said:

    Omnifreak, I heavily modified your code, now it works as it should without first open the Draw Settings Pane. Let me know if it works for you.

    Working so far.  Thanks!

Sign In or Register to comment.