SME: Get selected nodes (but only materials and that are not applied to scene)

if MatEditor.isOpen() != false AND maxOps.mtlDlgMode == #advanced then (
	viewNode = sme.GetView (sme.activeView)
	view = trackViewNodes[#sme][(viewNode.name)]
	selNodeInterface = viewNode.getSelectedNodes() --get selected node in SME
	selNodeNames = sort(for m in selNodeInterface collect m.name) --collect all selected node/s names in SME
	selNodeMatsInSceneNames = sort(for o in sceneMaterials where o.name != undefined and FindItem selNodeNames o.name > 0 collect o.name) --collects only the names of materials in the scene
 
	theViewMats = for n = 1 to view.numsubs where (superClassOf view[n].reference == material) collect view[n].reference -- collects all mats in SME view
)
viewNode
view
selNodeInterface
selNodeNames
selNodeMatsInSceneNames
theViewMats

I've managed to get the names of selected nodes that are a scene material with:
selNodeMatsInSceneNames

And all the materials in the view in an array with:
theViewMats

I was wondering if it's possible to collect the selected nodes but only materials and also not applied to scene (that will be easy once I can only get the selected nodes and not the entire view)

The output of above code is:

<IObject:IFP_NodeViewImp>
SubAnim:View1
#(<MixinInterface:Node>, <MixinInterface:Node>, <MixinInterface:Node>, <MixinInterface:Node>)
#("02 - Default", "Map #4", "Material #47", "Material #48")
#("Material #47")
#(02 - Default:Standard, Material #47:Composite, Material #48:Standard, Material #74:Standard, Material #75:Standard, Material #76:Shell_Material)

Comments

Comment viewing options

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

Perfect. Here's that code in a different format

clearlistener()
	viewNode = sme.GetView (sme.activeView)
	smeSelMats = #()
	smeSelMatsNonScene = #()
 
	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 and FindItem scenematerials m == 0 do append smeSelMats m
	)
 
	for i= 1 to smeSelMats.count do (
		mb = format "smeSelMats\t' % '\n" smeSelMats[i]
	)
 
	smeSelMats as array
 
	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 smeSelMatsNonScene m
	)
 
	for i= 1 to smeSelMatsNonScene.count do (
		mb = format "smeSelMatsNonScene\t' % '\n" smeSelMatsNonScene[i]
	)
 
	smeSelMatsNonScene as array 

I shall incorporate this in my script and give you credit. I think you're the first one to get this done.. Others have tried ;)

3dwannab's picture

This was my way..

Dirty as hell but it works 60% of the time all the time ;)

v = sme.activeView
view = sme.GetView v
numNodes = view.GetNumNodes()
selNodeInterface = view.getSelectedNodes() --get selected node <MixinInterface:Node>
 
viewMatNames = 	for i = 1 to trackViewNodes[#sme][sme.activeView].numsubs where isProperty trackViewNodes[#sme][sme.activeView][i] "reference" AND superclassof trackViewNodes[#sme][sme.activeView][i].reference == material collect try(trackViewNodes[#sme][sme.activeView][i].reference.name)catch()
selNodeNames = sort(for m in selNodeInterface collect m.name) --collect all selected node/s names
selNodeMatsInSceneNames = sort(for o in sceneMaterials where o.name != undefined and FindItem selNodeNames o.name > 0 collect o.name) --collect only the names of materials in the scene
 
--copy across arrays
viewMatNames_1 = copy viewMatNames #nomap
selNodeMapNames = copy selNodeNames #nomap
selNodeMatNames = copy selNodeNames #nomap
 
--gets selected non material nodes only
for i in viewMatNames_1 do (id = finditem selNodeMapNames i if id != 0 then (deleteItem selNodeMapNames id))
sort selNodeMapNames
 
--gets selected material nodes only
for i in selNodeMapNames do (id = finditem selNodeMatNames i if id != 0 then (deleteItem selNodeMatNames id))
sort selNodeMatNames
theNonSceneMat = copy selNodeMatNames #nomap
 
--the non scene material nodes
for i in selNodeMatsInSceneNames do (id = finditem theNonSceneMat i if id != 0 then (deleteItem theNonSceneMat id))
sort theNonSceneMat

I shall test that more. It will be more reliable that just having to rely on finditem / deleteItem :)

You're a star for helping me out.

pixamoon's picture

`

oki, finaly I think I found the way to get materials (not only names) :)

To get all selected materials in SME (in current view)

    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
    )
 
    print smeSelMats

To get selected materials in SME but not used in scene:

    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 and FindItem scenematerials m == 0 do append smeSelMats m
    )
 
    print smeSelMats

let me know if this works in your scene

cheers,
Pixamoon

Comment viewing options

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