Scripting help - Uber Iray copy and layer texture.

CaptJeebusCaptJeebus Posts: 21

So I'm trying to write a script for Daz3d which will 

1) copy a surface (all materials/properties/maps etc) from one figure to another (the selected figure to a defined geograft which will be a child of the selected figure with a known name)

2) Convert the following textures to a layered texture and import a second transparent texture on top of all the textures already copied from the above step. (It's important the second texture be on top of the existing texture, so I may need to save the original textures with a Get...() command then add the transparent first and then the stored Get()?

Base Color

Translucency Color

Dual Lobe Specularity Reflectivity

Base Bump

Normal Map

Top Coat Color

Top Coat Roughness

Top Coat Bump

I've been looking at the API but I can't find any of these specific properties available in the dzMaterial  - does anybody have any updated API including the UberIray object and properties?

even a source of examples of scripts which work with the shaders.  

 

The only example is the deep copy script and it doesn't really go into individual properties within the material/texture/shader.

Thanks in advance.

Post edited by CaptJeebus on

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,871

    This sample script may help https://www.daz3d.com/forums/discussion/503461/scripting-help-uber-iray-copy-and-layer-texture

    There is a dedicated scripting forum, here https://www.daz3d.com/forums/categories/daz-script-developer-discussion - you might want to edit your opening post to move this thread there

  • OmnifluxOmniflux Posts: 377

    This may be a good starting point for step 1

    // DAZ Studio version 4.14.0.10 filetype DAZ Script// Copy materials on specified surfaces from a figure to its selected geograft.// Author: Omniflux// Version: 1// Date: 2020-12-31(function(){	// Define surfaces to copy materials between [[source, destination], ...]	var asSurfaces = [['Torso', 'Surface 1'], ['Torso', 'Surface 2']];	// Ensure destination node is the correct type and has the required surfaces	function validateDestinationNode (oNode)	{		try		{			if (!oNode.inherits ("DzFigure")) throw true;			var oShape = oNode.getObject().getCurrentShape();			asSurfaces.forEach (function (x) { if (!oShape.findMaterial (x[1])) throw true });		}		catch (e)		{			throw new Error (qsTr ("Incorrect node selected."));		}	}	// Ensure source node exists and has the required surfaces	function validateSourceNode (oNode)	{		try		{			if (!oNode.isGraftFollowing()) throw true;			var oShape = oNode.getFollowTarget().getObject().getCurrentShape();			asSurfaces.forEach (function (x) { if (!oShape.findMaterial (x[0])) throw true });		}		catch (e)		{			throw new Error (qsTr ("Geograft not fit to correct figure."));		}	}	// This function is a derivative of the "Material Deep Copy" sample by Daz Productions, Inc,	// used under the CC Attribution 3.0 Unported license - http://creativecommons.org/licenses/by/3.0/	// http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/material/deep_copy/start	function copySurfaces (oNode)	{		var oSrcNode = oNode.getFollowTarget();		var oDstShape = oNode.getObject().getCurrentShape();		var oSrcShape = oSrcNode.getObject().getCurrentShape();		asSurfaces.forEach (function (asSurfaces) {			var oDstMaterial = oDstShape.findMaterial (asSurfaces[1]);			var oSrcMaterial = oSrcShape.findMaterial (asSurfaces[0]);			var oContext = new DzElementDuplicateContext();			var oNewMaterial = oSrcMaterial.doDuplicateElement (oContext);			oNewMaterial.name = oDstMaterial.name;			oNewMaterial.setLabel (oDstMaterial.getLabel());			if (oNewMaterial.setMaterialName)				oNewMaterial.setMaterialName (oSrcMaterial.getMaterialName());						oContext.createAlaises();			oContext.createERC();			oContext.doResolve();			oContext.doFinalize();			var oError = oDstShape.replaceMaterial (oDstMaterial, oNewMaterial);			App.log (qsTr ('Copied material from surface "%1" on "%2" to "%3" on "%4": %5')				.arg (asSurfaces[0])				.arg (oSrcNode.getLabel())				.arg (asSurfaces[1])				.arg (oNode.getLabel())				.arg (getErrorMessage (oError)));			if (oError.valueOf() != 0)				throw new Error (qsTr ("Error copying material(s)."));		});	}	try	{		// Get destination node		var oNode = Scene.getSelectedNode (0);		if (!oNode)			throw new Error (qsTr ("You must select a node to perform this action."));		validateDestinationNode (oNode);		validateSourceNode (oNode);		beginUndo();		copySurfaces (oNode);		acceptUndo (qsTr ("Copy Material(s) to Geograft"));		MessageBox.information (qsTr ("Material(s) copied successfully."), qsTr ("Success"), qsTr ("&OK"));	}	catch (e)	{		MessageBox.warning (qsTr (e.message), qsTr ("Error"), qsTr ("&OK"), "");	}})();

     

  • CaptJeebusCaptJeebus Posts: 21

    As always Richard is the MVP - set me up with the tutorials I needed to be able to complete the script I needed.

    Thanks!

Sign In or Register to comment.