How to loop the materials in the Slate Material Editor ?
Forum topic · General Scripting
How to loop the materials in the Slate Material Editor ?
By Rodman · 2012-09-22
Forum topic · General Scripting
By Rodman · 2012-09-22
How to loop the materials in the Slate Material Editor ?
Comments (18)
Comment policy
Thanks for this thread. Very useful.
I was wondering if it possible to only get material nodes in SME and not maps, controllers?
Exampe how to add and then assigne mtl to objects from SME
--create 10 random mtl's to SME
ActiveSMEView = sme.GetView (sme.activeView)
tempObj = TargetObject isHidden:on
mtlpos = [0,0]
for m in 1 to 10 do
(
tempObj.material = Standard name:("StdMtl_"+m as string) diffuse:(random black white)
ActiveSMEView.CreateNode tempObj.material &mtlpos
mtlpos.x = 180*m
)
delete tempObj
--create 10 teapots
teapotsArr = for i in 1 to 10 collect Teapot radius:10 pos:[0, 20*i, 0]
fn assigneMtltoSelection selArr mtlName: = if selArr.count != 0 and mtlName != unsupplied do
(
local numViews = trackViewNodes[#sme].numsubs
local mtlArr = #()
if numViews > 0 do
(
for v in 1 to numViews where (numNodes = trackViewNodes[#sme][v].numsubs) > 0 do
(
for n in 1 to numNodes do append mtlArr trackViewNodes[#sme][v][n].reference
)
)
if (mtlArr.count) != 0 do
(
mtlArr = for m in mtlArr where m.name == mtlName collect m
if (mtlArr.count) != 0 do for o in selection do o.material = mtlArr[1]
)
)
assigneMtltoSelection teapotsArr mtlName:"StdMtl_5"
Thank you !
Thanks barigazy ! I will study your script when I am available for this. How did you find this ? The help in maxscript is not always friendly.
*****
Patience always pays off, and in the end it always finds a solution
;)but you have to be persistent.
Try it and tell me what you think
Cheers!
Can you better explain "loop the materials".
Do you want to find and collect all materials in SME current view
Yes exactly
To collect names of sme active view materials you can try
Note:Theses materials are not assigned.
If you want trackView Nodes:
If materials are assigned then to collect all mtls you can use
this code
sceneMtls = for m in sceneMaterials do collect m
Thanks but...
Thanks for this, but the array smeViewMaterials seems not useful to get an equivalent of this exemple :
meditMaterials[i]= standard()
I would like to create a list of materials directly inside the SME.
The only way to create mtl in SME you need to use this procedure:
Thank you !
Yes, you must do it with an object.
Yes because you need maxObject material to create node inside SME View. But after creation you can delete tempObject
ActiveSMEView = sme.GetView (sme.activeView)
mtl = Standard name:"TestMat" diffuse:green
mtlpos = [0,0]
tempObj = TargetObject material:mtl isHidden:on
ActiveSMEView.CreateNode tempObj.material &mtlpos
delete tempObj
edit
Also you can use this if you need more then one material
ActiveSMEView = sme.GetView (sme.activeView)
tempObj = TargetObject isHidden:on
mtlpos = [0,0]
for m in 1 to 10 do
(
tempObj.material = Standard name:("StdMtl_"+m as string) diffuse:(random black white)
ActiveSMEView.CreateNode tempObj.material &mtlpos
mtlpos.x = 180*m
)
delete tempObj
I have a new question
I have now my materials in the SME. It's great !
But now I wonder how to assign one to an object. How to recognize it as a material, one material can have multiple nodes. How I can choose the Parent node ?
The documentation has no exemples. It's really hard to use it.
I don't know.This is not exposed in mxs.
SME is bed solution for your script,obviously.
Anyway, why do you need this?
.
No limitation
I don't want to be limited with the number of slot in meditMaterials[i]
That's why I wanna loop through SME.
For that people store your materials in material library.
That is better solution than SME.Here on scriptspot you can find very cool scipts for that and one of them is http://www.scriptspot.com/3ds-max/scripts/smes-super-material-editor-swi…
I know it. The code can't help to do the job I need.