How to change material preset of Stingray material in python

How to change material preset of Stingray material in python

hansyuan.yang
Contributor Contributor
2,290 Views
6 Replies
Message 1 of 7

How to change material preset of Stingray material in python

hansyuan.yang
Contributor
Contributor

Hi, I use python to create a Stingray material. But I want to change the material preset from "Standard" to "Standard_Masked". How do I do it?  Thank you.

 639.png

0 Likes
Accepted solutions (2)
2,291 Views
6 Replies
Replies (6)
Message 2 of 7

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Hi,

Try This....

import maya.cmds as cmds
cmds.optionMenuGrp("ShaderFXMenuGrpPresetMaterial", edit=True, select = 3)

The select index is as follows

1 "Custom"
2 "presets/Standard"
3 "presets/Standard_Masked"
4 "presets/Standard_Transparent"

Message 3 of 7

hansyuan.yang
Contributor
Contributor

Hi, just found out when I use this command it can select different preset successfully.  But when I click any other place , the selection jumps back to the default value. And it's not pop out the warning "

Loading a preset or switching to custom deletes the old shader graph. This action cannot be undone. Continue?

" as manual select.  I think I need one more "update" or something after selecting it?   Thank you

0 Likes
Message 4 of 7

hansyuan.yang
Contributor
Contributor

I end up to use this:

import maya.mel as mel
cmds.optionMenuGrp("ShaderFXMenuGrpPresetMaterial", edit=True, select = 3)
mel.eval("ShaderFXChangeMenuPresetMaterial")
Message 5 of 7

hansyuan.yang
Contributor
Contributor
Accepted solution

The previous one is not the correct method and causes some issue. This one is better. It actually set presets type and no need for the update.

import maya.mel as mel
mel.eval('shaderfx -sfxnode {0} -edit_stringlist 1 "presets" {1};'.format(_newMat,2))
Message 6 of 7

laise.medroom
Explorer
Explorer

I'm curious what did you put in _newMaterial? I tried putting the name of my shader FX mterial, but it gives me the error # Error: RuntimeError: file <maya console> line 6: Error occurred during execution of MEL script
# line 1: Invalid argument:

Message 7 of 7

hansyuan.yang
Contributor
Contributor
Hi
It's been a long time I can't really recall it. But I guess is the ShadingNode:
self
.stingrayMat = cmds.shadingNode('StingrayPBS', asShader=True, name = "StingrayPBS_Preview" )