Need help trying to add suffix to materials of selected nodes

Hey folks,

I am currently trying to create a simple batch renamer. I basically have everything I need from some of the samples to go into my loop of iterating through each selected node, but I am not 100% sure how to access the material name so I can put this into a variable and then later write that back after I changed it with a simple string combine with my suffix variable. The string operation is no issue, that is simple, but reading out the correct data and then later writing it back, I really have no idea what I have to call.

This is my code snippet I have so far. I am on the right track as my little info output gives me correct number of materials and it is also doing it for each selected node, so in that regard all is good. I just dont know how to access the material name on that oMat, nor do I know how to write the data back afterwards. Please help me.

(function(){	var oNode;	var aNodes = Scene.getSelectedNodeList();	var nNodes = aNodes.length;	for( var i = 0; i < nNodes; i += 1 ){		oNode = aNodes[i];		var oObject = oNode.getObject();		if (! oObject) continue;		var nShapes = oObject.getNumShapes();		for (var j=0; j < nShapes; j++) {			var oShape = oObject.getShape(j);			var nMat = oShape.getNumMaterials();			for (var k=0; k < nMat; k++) {				var oMat = oShape.getMaterial(k);				// Info Output				print ( oMat, "num ", k);			}		}	}})();

 

Comments

  • PraxisPraxis Posts: 254

    I can't test this at present, but this should work?:

    var sNewName = oMat.getName() + '_MySuffix';oMat.setName( sNewName );

     

  • hzrhzr Posts: 207

    Ah thanks yeah it changes the name. Very nice. This will save me an enormous amount of time on exports and making sure to have unique material names by adding a random number to these. I would normally manually go through every surface and change it so the names would be unique, in order to properly re-use material assignments templates in c4d. Now this will just be a simple click and its done. Halleluja!

    For some reason it only applies to the surfaces when you look at them in the tool settings of the geometry editor tool. On the regular surfaces pane it keeps the old name. Could it be that this is split into property name and property label like on the nodes?

    It does not bug me all that much since it changes the property name and that is what is important to me on exporting the meshes, but it still seems weird that it is not also changed for the surfaces pane ;)

  • PraxisPraxis Posts: 254

    In case you want them, there are also getLabel() and setLabel() functions.

    This will show you more than you want to know about DzUberIrayMaterial:

    // DAZ Studio version 4.12.0.47 filetype DAZ Script// List Material propertiesvar oMat = Scene.getPrimarySelection().getObject().getCurrentShape().getMaterial(0);print( oMat.className(), oMat.getName(), oMat.getLabel() );print( ' ' );print( Object.keys( oMat ) );print( ' ' );var oProperty;var aProperties = oMat.getPropertyList();for( var j = 0; j < aProperties.length; j++ ) {  oProperty = aProperties[ j ];  print( oProperty.className(), oProperty.getName(), oProperty.getLabel(), oProperty.getPath() );}

     

  • hzrhzr Posts: 207

    Thanks alot. This is good information. I know my way around scripting in other languages and usually for web, but it is a bit overwhelming to dive into the daz scripting API as it seems to be not so very well or rather not so intuitively documented from the bits I looked at so far.

Sign In or Register to comment.