DETECT SUBMATERIAL TREE

Unfortunatelly this script is not going deep enough!
Actually, I need to connect material tree with the Map Tree (second code)that Swordslayer created at http://www.scriptspot.com/forums/3ds-max/general-scripting/detect-map-ty...

	fn All_Submats onematerial =
	(
		Propertieses = (getPropNames onematerial)
		for SubProp in Propertieses do
		(
			if isProperty onematerial SubProp == true do
			(
				Insert = getproperty onematerial SubProp
				if superclassof Insert == material do
				(
					append All_SubMaterials Insert
					All_Submats Insert
				)
				if classof Insert == ArrayParameter do
				(
					for i in Insert do if superclassof i == material do 
					(
						append All_SubMaterials i
						All_Submats i
					)
				)
			)
		)	
	)