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
Description
Comments (18)
3dwannab · 2015-08-28
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
barigazy · 2012-09-24
--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 !
Rodman · 2012-09-26
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.
*****
barigazy · 2012-09-26
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!
barigazy · 2012-09-22
Can you better explain "loop the materials".
Do you want to find and collect all materials in SME current view
Rodman · 2012-09-22
Yes exactly
barigazy · 2012-09-22
To collect names of sme active view materials you can try
Note:Theses materials are not assigned.
getActiveViewSME = sme.GetView (sme.activeView)
viewNodeCount = getActiveViewSME.GetNumNodes()
smeViewMaterials = for n = 1 to viewNodeCount collect ((getActiveViewSME.GetNode n).name)
If you want trackView Nodes:
viewMtls = refs.dependsOn (refs.dependents rootnode)[1].SME.View1
If materials are assigned then to collect all mtls you can use
this code
sceneMtls = for m in sceneMaterials do collect m
Thanks but...
Rodman · 2012-09-22
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.
barigazy · 2012-09-22
The only way to create mtl in SME you need to use this procedure:
--first get active SME View
ActiveSMEView = sme.GetView (sme.activeView)
--create mtl and assigne to some object
mtl = Standard name:"TestMat" diffuse:green
tempObj = Box material:mtl
--then you need to devine point2 value
mtlPos = [0,0]
--and last create SME Node
ActiveSMEView.CreateNode tempObj.material &mtlPos
Thank you !
Rodman · 2012-09-22
Yes, you must do it with an object.
barigazy · 2012-09-22
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
barigazy · 2012-09-22
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
Rodman · 2012-09-22
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.
barigazy · 2012-09-22
I don't know.This is not exposed in mxs.
SME is bed solution for your script,obviously.
Anyway, why do you need this?
Rodman · 2012-09-22
.
No limitation
Rodman · 2012-09-22
I don't want to be limited with the number of slot in meditMaterials[i]
That's why I wanna loop through SME.
barigazy · 2012-09-22
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…
Rodman · 2012-09-23
I know it. The code can't help to do the job I need.