def walk_material_hierarchy(cls, node): """Walks through the material hierarchy through their parameters :param node: :return: """ for p in node.ParameterBlock.Parameters: # decide what to do by looking at the parameter type of the p param param_type_name = MaxPlus.FPTypeGetName(p.GetParamType()) value = p.Value if param_type_name in ['MtlTab', 'TexmapTab']: # it contains multiple materials for i, v in enumerate(value): yield (node, p, v, i) try: v.GetName() for pp in cls.walk_material_hierarchy(v): yield pp except (RuntimeError, AttributeError): pass else: try: value.GetName() yield (node, p, value, -1) if isinstance(value, MaxPlus.MtlBase): for pp in cls.walk_material_hierarchy(value): yield pp except (RuntimeError, AttributeError): pass
def export_basic_material_attibutes(self, node): """exports basic material attributes to a json file. :return: """ import os import tempfile json_file_path = os.path.join( tempfile.gettempdir(), 'basic_material.json' ) data = {} exportable_types = ['Texmap', 'Int', 'PercentFraction', 'Float', 'FRgb', 'Rgb', 'Point3', 'BOOL', 'World'] param_types = [] for p in node.ParameterBlock.Parameters: param_type_name = MaxPlus.FPTypeGetName(p.GetParamType()) #print(p.GetName(), ) # data[p.GetName()] = p.Value; param_types.append(param_type_name) print(set(param_types))
# print str(selected_nodes[i].GetName()) MaxPlus.SelectionManager.ClearNodeSelection() MaxPlus.SelectionManager.SelectNodes(myList) # Example accesing param blocks in a modifier for each in selected_nodes: mod = MaxPlus.Factory.CreateObjectModifier(MaxPlus.Class_ID(0x9c92c88, 0x13d466dc)) MaxPlus.ModifierPanel.AddToSelection(mod) i = 0 for p in mod.ParameterBlock: type_name = MaxPlus.FPTypeGetName(p.Type) try: print ' parameter', i, p.Name, p.Type, type_name, p.Value i += 1 except: etype, evalue = sys.exc_info()[:2] print 'error '. etype, evalue # Get access to a modifier selected_nodes = (MaxPlus.SelectionManager.GetNodes()) for each in selected_nodes: n = each.GetNumModifiers() mod = each.GetModifier(n - 1) #accedo al último de la lista print str(mod)