How to loop the materials in the Slate Material Editor ?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
3dwannab's picture

Thanks for this thread. Very

Thanks for this thread. Very useful.

I was wondering if it possible to only get material nodes in SME and not maps, controllers?

barigazy's picture

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"

barigazy

Rodman's picture

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.

Rodman

barigazy's picture

*****

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

barigazy's picture

Can you better explain "loop

Can you better explain "loop the materials".
Do you want to find and collect all materials in SME current view

barigazy

Rodman's picture

Yes exactly

Yes exactly

Rodman

barigazy's picture

To collect names of sme

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

barigazy

Rodman's picture

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.

Rodman

barigazy's picture

The only way to create mtl in

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

barigazy

Rodman's picture

Thank you !

Yes, you must do it with an object.

Rodman

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.