How to read or set the Ambient Strength of a Material

This is where I got...but missing the way to read or set the value (like 0.1 or 10%)


if(!(node = Scene.getPrimarySelection())){	 return;};print ("node= "+node.name);shellObject = node.getObject();print ("Object= "+shellObject.name);shape = shellObject.getCurrentShape();print ("Shape= "+shape.name);var iMat = shape.getNumMaterials();	for( j = 0; j < iMat; j++){		mMaterial = shape.getMaterial ( j);		print ("Material= "+mMaterial.name);		oProperty = mMaterial.findProperty( "Ambient Strength" );		print ("Property= "+oProperty.name);		oProperty.setValue = ( 0.12 );		print("Value= " + oProperty.value);	};

...but oProperty.value appears to be the wrong thing.  Tried name, getValue , as well...the last two lines to read or set the value don't seem to work.

What am I missing, or where in the docs am I missing it?  :)

Comments

  • jag11jag11 Posts: 885

    Same code with minor corrections:

    (function () {    var node = null;    if (!(node = Scene.getPrimarySelection())) {        return; // notify user    };    print("node= " + node.name);    var shellObject = node.getObject();    if (!shellObject) {        return; // notify user    }    print("Object= " + shellObject.name);    var shape = shellObject.getCurrentShape();    if (!shape) {        return; // notify user    }    print("Shape= " + shape.name);    var materialCount = shape.getNumMaterials();    for (var i = 0; i < materialCount; i++) {        var material = shape.getMaterial(i);        var property = material.findProperty("Ambient Strength");        if (!property) {            continue;        }        property.setValue(0.12);        print("Value= " + property.getValue());    }})();

    HTH

  • 3dOutlaw3dOutlaw Posts: 2,471

    It's the little syntax overlooks that get me.  I literally had to paste your setValue line next to mine to notice the equal sign.  My mind had obfuscated it, lol  :)

    Thanks so much!

     

     
  • This sample should help http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/properties/material_properties/start

    Also bear in mind that not all shaders have Ambient Strength as a property.

  • 3dOutlaw3dOutlaw Posts: 2,471

    OK, thanks!  I was not actually interested in that particular property (it was a decoy), but "how" to do it.  The actual stuff I am working on is top secret cheeky

     

     

Sign In or Register to comment.