Page 1 of 1

Need a little help with the proper syntax for modifying the IOR Value in a material

Posted: Wed Sep 15, 2021 3:07 pm
by Forester
Here is a little, simple script I am trying to write, but I must be making numerous errors.
I just need the proper syntax for changing the IOR Value of the first BSDF in the first layer.

I've managed to read the first layer, and the first BSDF in the first layer. But I'm having problems writing a correct statement to change the IOR Value. Can anyone help me with this?)


Also, I sure could use some help in understanding how to write the "Set" commands so that the script signals back if the Set command fails.

################################################################
# Edit just the IOR Value of the first Opacity and Ghost BSDF layer
################################################################

from pymaxwell5 import *

def edit_multilayer_material(inPath,outFolder,outMxs):
# Read scene from disk
scene = Cmaxwell(mwcallback_cb)
ok = scene.readMXS(inPath)

if ok == 0:
print("Error reading scene from file")
return 0

# Read material
material = scene.getMaterial( 'Glass' )
if material.isNull():
print("Wrong material name?")
return 0

# Get first layer
layer = material.getLayer(0)

# Get first BSDF
bsdf = layer.getBSDF(0)

# Get/set BSDF IOR value
Creflectance_getIOR(0)
Creflectance_setIOR(1.51,0.0)


if not os.path.exists(outFolder):
os.mkdir(outFolder)

# Save changes
outPath = outFolder+'/'+outMxs
ok = scene.writeMXS(outPath)
if ok == 0:
print("error saving",outPath)
return 0
else:
print(outPath)

return 1

if __name__ == "__main__":
inPath = 'd:/mr_scenes/GlassTesting_sdrevision1.mxs'
outFolder = 'd:/mr_scenes/GlassTesting_sdrevision2.mxs'
outMxs = 'sample_scene_mat_edited.mxs'
edit_multilayer_material(inPath,outFolder,outMxs)

Re: Need a little help with the proper syntax for modifying the IOR Value in a material

Posted: Thu Sep 16, 2021 1:36 am
by Harvey Fong
Hi

It looks like you are using Maxwell Render 5/scripts/python/edit_multilayer_material.py as your starting point which is good

this line in that script gives you a handle to the instance of the Creflectance class in your bsdf that you can manipulate
Code: Select all
reflectance = bsdf.getReflectance()
This is how you retrieve the current value
Code: Select all
nd,abbe,ok = reflectance.getIOR()
print('Nd',nd,'abbe',abbe)
This is how you set the value
Code: Select all
ok = reflectance.setIOR(1.9,100)
the ok variable stores success or failure

Re: Need a little help with the proper syntax for modifying the IOR Value in a material

Posted: Thu Sep 16, 2021 5:48 pm
by Forester
THANK YOU! THANK YOU! THANK YOU!

Just exactly what I needed. I'm so grateful to you! And thank you for the explanation for each segment of the code. Now, I can work out all the rest of this myself.

THANK YOU !!!!!!!!! :D

Re: Need a little help with the proper syntax for modifying the IOR Value in a material

Posted: Thu Sep 16, 2021 7:04 pm
by Harvey Fong
You are welcome ! :D