Surface Selection Script

13»

Comments

  • TotteTotte Posts: 13,525

    Thank you!

        oShape.clearMaterialSelection();


    This did the trick, as I comes back to each material  from the outside through the object -> shape tree, it kept the previously selected material even though I did call select(false) on the material before I exited that call.

    / Totte

     

  • TotteTotte Posts: 13,525
    edited September 2022

    Omniflux said:

    @Totte

    I cannot reproduce. Does the following not work for you, or do I not understand what you are trying to do?

    (function(){	setBusyCursor();	var oShape = Scene.getPrimarySelection().getObject().getCurrentShape();	oShape.clearMaterialSelection();	for (var i = 0; i < oShape.getNumMaterials(); i++)	{		var oMaterial = oShape.getMaterial(i);		oMaterial.select(true);		sleep (1000);		oMaterial.select(false);	}	clearBusyCursor();})();

     

    Thanks once again, and here is a stripped down version of my code where it does not work as expected as I apply a shader between select(true) and select(false)

     Try it and you see, adding that magic oShape.clearMaterialSelection();  solved it!


     

    // DAZ Studio version 4.5.0.0 filetype DAZ Script( function() {	// setBusyCursor();	var oNode = Scene.getPrimarySelection();	var oShape = oNode.getObject().getCurrentShape();	var aMatNames = [];	var oMaterial;	var sNameName;	var oCntMgr = App.getContentMgr();	var sFullPath = oCntMgr.findFile ("Shader Presets/Iray/DAZ Uber/!Iray Uber Base.duf" );	if (sFullPath==undefined || sFullPath.length == 0) {		print("Cant find test Uber shader");	}		for (var i=0; i<oShape.getNumMaterials(); i++) {		oMaterial = oShape.getMaterial(i);		aMatNames.push(oMaterial.name);		print(oMaterial.name);	}		aMatNames.sort( function(a,b) { return a.localeCompare(b); });	for (var index=0; index<aMatNames.length; index++) {		oNode.select(true);		sNameName = aMatNames[index];		oMaterial = oShape.findMaterial(qsTr(sNameName));		if (oMaterial == undefined) {			continue;		}		oMaterial.select(true);		if (!oCntMgr.openFile(sFullPath, true )) {			print("Failed to apply Shader.");		}		sleep(500);		oMaterial.select(false);		oNode.select(false);	}	clearBusyCursor();})();


    / Totte

     

    dsa
    dsa
    test-1.dsa
    1K
    Post edited by Totte on
  • TotteTotte Posts: 13,525

    And now it works when I figured out the underlaying issue (the DzMaterial object is replacd when the shader is uopdated, not updated.


    Attached test-1.dsa now working doing shader apply, so you now the basic issue.
     

    // DAZ Studio version 4.5.0.0 filetype DAZ Script( function() {	// setBusyCursor();	var oNode = Scene.getPrimarySelection();	var oShape = oNode.getObject().getCurrentShape();	var aMatNames = [];	var oMaterial;	var sNameName;	var oCntMgr = App.getContentMgr();	var sFullPath = oCntMgr.findFile ("Shader Presets/Iray/DAZ Uber/!Iray Uber Base.duf" );	if (sFullPath==undefined || sFullPath.length == 0) {		print("Cant find test Uber shader");	}		for (var i=0; i&lt;oShape.getNumMaterials(); i++) {		oMaterial = oShape.getMaterial(i);		aMatNames.push(oMaterial.name);		print(oMaterial.name);	}		aMatNames.sort( function(a,b) { return a.localeCompare(b); });	for (var index=0; index&lt;aMatNames.length; index++) {		oNode.select(true);		sNameName = aMatNames[index];		oMaterial = oShape.findMaterial(qsTr(sNameName));		if (oMaterial == undefined) {			continue;		}		oMaterial.select(true);		if (!oCntMgr.openFile(sFullPath, true )) {			print("Failed to apply Shader.");		}		sleep(500);		oMaterial = oShape.findMaterial(qsTr(sNameName));		oMaterial.select(false);		oNode.select(false);	}	clearBusyCursor();})();

     

    dsa
    dsa
    test-1.dsa
    1K
  • Yes, I thought I recalled that applying a new preset created a new DzMaterial-derived object and Rob confirms. In general the preset might completely change everything (from an MDL or RSL shader DzShaderMaterial to a Shade Mixer DzBrickMaterial, for example) so trying to safely maintain continuity would not be practical

  • KarenKaren Posts: 81
    edited January 2023

    Hi, I so love the searchsurfaces script (a real life saver) - but does anyone know a script to search and rename a lot! of surfaces of some selected objects?

    For example, I name 50 surfaces "stone", but want to change them into "rock", or if I have a typo and do not want to go through aaaall these nodes one by one.

    I know, it can be done through text editor, but that is so ... I never know, if it will save properly or corrupt the file.

     

    Post edited by Karen on
Sign In or Register to comment.