[Closed] edit shader parameters
Be warned – I’m a scripting noob. And here is my question:
I want to create a script which sets certain parameters of the currently selected shader to certain values. Here is what the maxscript listener gives me:
rootScene[#SME][#View1][#Map__1325____Mighty_Tiles_Pro_Map_Selector].Properties.reference.MightyTilesProMap.wallWidth = 10
rootScene[#SME][#View1][#Map__1325____Mighty_Tiles_Pro_Map_Selector].Properties.reference.MightyTilesProMap.wallHeight = 10
rootScene[#SME][#View1][#Map__1325____Mighty_Tiles_Pro_Map_Selector].Properties.reference.MightyTilesProMap.lockRealWorldScale = on
rootScene[#SME][#View1][#Map__1325____Mighty_Tiles_Pro_Map_Selector].Properties.reference.MightyTilesProMap.patternTileable = on
Now there is the reference to #Map__1325, in this case. Can this be altered so that this will work with the currently selected Shader?
This function will return the instance of the selected material. From there you can modify its properties.
In Compact mode it returns the current selected slot, in Slate mode it returns the material opened in the Parameter Editor.
In Max 2014+ there is a new function GetSelectedNodes() to get all the selected nodes in the Slate Editor.
(
fn GetCurrentMaterial =
(
case MatEditor.mode of
(
#basic: medit.GetCurMtl()
#advanced: sme.GetMtlInParamEditor()
)
)
mtl = GetCurrentMaterial()
showproperties mtl
)
this is great, thank you! Now, how do I start if I want to change some values of a procedural texture node?
For example, if I have selected a noise node in the slate editor, how do I change – let’s say – its Size parameter to 50 and put that script on a toolbar button.
Would you mind to write a short example?
(
fn GetCurrentMaterial =
(
case MatEditor.mode of
(
#basic: medit.GetCurMtl()
#advanced: sme.GetMtlInParamEditor()
)
)
mtl = GetCurrentMaterial()
if isKindOf mtl noise do
(
-- Change Color 1
mtl.color1 = red
-- Change Color 2
mtl.color2 = blue
-- Change Size
mtl.size = 50.0
-- Change Noise Type to Fractal
mtl.type = 1
-- Change Threshold
mtl.thresholdLow = 0.25
mtl.thresholdHigh = 0.75
-- Change Noise Levels
mtl.levels = 6
)
-- Print the properties to the Listener (for reference)
showproperties mtl
)
That did it! Yeaaah, no more endless parameter changes! PolyTools3D, you are my hero!
I am reviving this old thread with one more question:
This little script changes values of a shader, very handy. The only thing is that I have to select (doubleclick) the shader in slate mode and run the script, but I have many of them and all need to be changed.
Is there a possibility to drag select multiple shaders of the same type and run the script so it changes the values of all selected shaders?
(
(
fn GetCurrentMaterial =
(
case MatEditor.mode of
(
#basic: medit.GetCurMtl()
#advanced: sme.GetMtlInParamEditor()
)
)
mtl = GetCurrentMaterial()
if isKindOf mtl MightyTilesPro do
(
-- set breite
mtl.Wall_width = 1000
-- set höhe
mtl.Wall_Height = 1000
-- Real world scale true
mtl.Sync_real_world_scale = true
--Filtering an
mtl.Filtering = true
)
-- Print the properties to the Listener (for reference)
--showproperties mtl
)
)
fn getSMEselectedMtls = (
viewNode = sme.GetView (sme.activeView)
smeSelMats = #()
for n = 1 to trackViewNodes[#sme][(sme.activeView)].numSubs do (
m = trackViewNodes[#sme][(sme.activeView)][n].reference
b = viewNode.GetNodeByRef m
if b.selected and superclassof m == material do append smeSelMats m
)
smeSelMats
)
if MatEditor.mode == #advanced then (
for mtl in getSMEselectedMtls() where classof mtl == MightyTilesPro do (
-- set breite
mtl.Wall_width = 1000
-- set höhe
mtl.Wall_Height = 1000
-- Real world scale true
mtl.Sync_real_world_scale = true
--Filtering an
mtl.Filtering = true
)
)
Note that above script will only affect materials selected in current view of slate material editor
If you need to process all instances of that type of material in scene you can use next code
for mtl in getclassinstances MightyTilesPro do (
-- set breite
mtl.Wall_width = 1000
-- set höhe
mtl.Wall_Height = 1000
-- Real world scale true
mtl.Sync_real_world_scale = true
--Filtering an
mtl.Filtering = true
)