SetMaterial

How we can assign Uber material with default setting on all objects in the scene?

 

 

var obj;

var shape;

var mat;

 

for(var i = 0; i < Scene.getNumNodes(); i += 1)

{

node = Scene.getNode(i);

obj = node.getObject();

if(obj != null)

{

shape = obj.getCurrentShape();

for( var j = 0; j < shape.getNumMaterials(); j += 1 )

{

/* I need to set material to Uber with default parameters, something like this:

shape.setMaterial(new DzUberIrayMaterial())

*/

}

}

}

Post edited by MehdiZangenehBar on

Comments

  • What is this thing with posting a question and ascript? Is the script meant to be a solution, and you are posting for infromation? Or is the script not working and you want to know why? Please take the time to add some more explanation and context to your post.

  • I think my question was clear, anyway, Yes the code is the process that I tried to achieve what I was looking for, And I commented the part that I expected should work : 
     

    //shape.setMaterial(new DzUberIrayMaterial())

    And, sorry I'm new in this forum. why my above code shows in single line? (I'm sure I posted with Insert Code)

  • And is it possible to get an notification email, when someone reply to my question?

  • The formatting has been an issue for some time, I don't know of a workaround - other than using quote instead, which is less than ideal.

    Personally I would seelct the models adn surfaces, then use ContentManager to run the Iray Uber base preset.

  • MehdiZangenehBar said:

    And is it possible to get an notification email, when someone reply to my question?

    You should, by default, get reply notififcations for your own threads.

  • The problem is running preset will override some parts of the material and some parts will stay untouched. For example if material has base color, running Uber preset will not remove that. I'm actually looking for a way to assign a Uber material with empty maps and default parameters.

  • You could save a preset that does what you want, then aply that through the script.

  • Well... , I'm pretty sure it could be done using script, no need to create a preset.

  • MehdiZangenehBarMehdiZangenehBar Posts: 5
    edited December 2023

    OK, I figure it out myself, this is the script:

    var node;

    var obj;

    var shape;

    var mat;

    var uber_mat;

     

    for(var i = 0; i < Scene.getNumNodes(); i += 1)

    {

    node = Scene.getNode(i);

    obj = node.getObject();

    if(obj != null)

    {

    shape = obj.getCurrentShape();

    for(var j = 0; j < shape.getNumMaterials(); j += 1)

    {

    mat = shape.getMaterial(j);

    uber_mat = new DzUberIrayMaterial;

    uber_mat.setName(mat.name);

    uber_mat.setLabel(mat.getLabel());

    shape.replaceMaterial(mat, uber_mat);

    }

    }

    }

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