SME Get Selected Materials

3 votes
Date Updated: 
Author Name: 

This script is useful only for script writers.

This is just simple function to get selected materials / textures / controllers from active view in SME.

Function returns materials :) - not names of materials.

function SMEGetSelMats = (    
	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 do append smeSelMats m
	return smeSelMats
-- do something here
print (SMEGetSelMats())

I've got message - it doesn't work with 2012. If anybody has 2012, please test and let me know



Comment viewing options

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

Just to expand on this more

Just to expand on this more :)

notes to comment:

ar_smeSel = #()
ar_smeSelFCtrl = #()
ar_smeSelMaps = #()
ar_smeSelMats = #()
getActiveViewSME = sme.GetView (sme.activeView)
viewNodeCount = getActiveViewSME.GetNumNodes()
smeViewMaterials = for n = 1 to viewNodeCount where isProperty trackViewNodes[#sme][sme.activeView][n] "reference" do
	maxObj = trackViewNodes[#sme][(sme.activeView)][n].reference -- collect entire curent views: materials, maps, etc.
	b = getActiveViewSME.GetNodeByRef maxObj -- GetNodeByRef of entire current view
	-- collect everything if selected
	if b.selected == true do append ar_smeSel maxObj
	-- get materials from ar_smeSel array
	ar_smeSelMats = for o in ar_smeSel where (superclassOf o == material) collect o
	-- get texture maps from ar_smeSel array
	ar_smeSelMaps = for o in ar_smeSel where (superclassOf o == textureMap) collect o
	-- get floatControllers from ar_smeSel array
	ar_smeSelFCtrl = for o in ar_smeSel where (superclassOf o == floatController) collect o
pixamoon's picture


hey hey,

I saw that on AD forum and CGSociety forum but it didn't work for me because:

view.GetNode n
"n" index is different than "n" index in:

I noticed that index can be the same on beginning only - till double click on node (to load it into right panel). After that index is moved.

That's why we can't get selected material from selected node by
if (view.GetNode n).selected do mat = trackViewNodes[#sme][v][n].reference

But your post was a big step to find this solution :) Thanks!


lightcube's picture

Thanks for sharing. I've used

Thanks for sharing. I've used a similar set of logic for a while but ended up simply abandoning it. You might want to look at because the results seem to be bugged in many cases. I noticed that the results were sometimes correct, but just as often totally wrong.

AD has confirmed the bug. It's annoying, but at least as of June it was still broken in all versions of Max. I haven't tested in 2016 SP1 yet.


Shawn Olson

Developer of Wall Worm

Comment viewing options

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