-- V0.2 Change name from MatID Pallete to MatIDTools -- V0.3 Added Pick Selected -- V0.4 Bug Fixes -- V0.5 Add Auto Rename Material ID Modifier and Add instanced to Selection -- V0.6 Added SPREAD Source Slots function -- Working --V0.7 BugFix7 --V0.8 Smarter -- V0.9 Multi-Sub Rename Direction <- or -> -- V0.91 Added Apply Source MAterial to Selection -- V0.92 Apply Source Material to Selection on Double Click -- Delete all the older MaterialID Modifiers and Add a New One -- V0.92a -- V0.92b -- BugFixes -- V0.92c -- BugFixes -- V0.92d -- BugFixes -- V0.93 -- Great BugFix - The Script is not returning error if something is selected when running it, -- V1.04 -- Detect Multisub even if all slots are empty -- V1.05 -- Bugfix -- V1.05b -- Bugfix -- V1.06 -- New Custom ID Button -- V1.07 -- Changed all SceneMaterials for simpler and shorter code -- V1.08 -- Bug Running first time -- V1.10 -- Users Feature requests - Add option to apply instanced Modifiers -- V1.12 -- Users Feature requests - Add MID Modifier to other levels in stack with UI configuration -- Made by kumodot.com matid_uwidth = 220 matid_uheight = 590 nameIndex = 1 matid_modpos = 1 -- Set the default position for adding the Modifier 0 (baseObject/Bottom), 1 (Add to the Top of Modifiers/Default) matid_addtag = 1 -- Add IDTag to Object Name - Default ON matid_instance = 1 -- Instance MaterialModifiers applied to more than one object - Default ON mid_butsize = 120 valid_multisub = 0 spnID = 25 -- matsource_obj = undefined fn checkmaxfile = ( filebase = "kb" if maxfilepath != "" then ( if doesFileExist (maxfilepath + (getFilenameFile maxFileName)+".max") == true do ( ft_getfile = maxfilepath + (getFilenameFile maxFileName) +".max" ft_filename = getFilenameFile maxFileName + ".max" ft_flag_filename = maxfilepath + (getFilenameFile maxFileName) + "_FLAG" ) if doesFileExist (maxfilepath + (getFilenameFile maxFileName)+".mx") == true do ( ft_getfile = maxfilepath + (getFilenameFile maxFileName) +".mx" ft_filename = getFilenameFile maxFileName + ".mx" ) ) else ( ft_getfile = "Not Saved Yet" ft_filename = "Not Saved Yet" ) ft_maxrawfilesize = (getfilesize ft_getfile /1024) as integer if ft_maxrawfilesize > 1024 then ( ft_maxrawfilesize = ft_maxrawfilesize/1024 filebase = "Mb" ) else ( ft_maxrawfilesize = ft_maxrawfilesize filebase = "Kb" ) if ft_maxrawfilesize > 1048576 do ( ft_maxrawfilesize = ft_maxrawfilesize/1048576 filebase = "Gb" ) global ft_maxfilesize = "~" + (ft_maxrawfilesize as string) + filebase ) fn wipemID = ( -- Recursive Search and Destroy mID modifiers for x in selection do for i = x.modifiers.count to 1 by -1 where classof x.modifiers[i] == Materialmodifier do deleteModifier x i ) fn mID_addzeros nr = -- Decimal Padding Output STRING ( case of ( (nr < 10): ("0" + nr as string) (nr > 9): (nr as string) ) ) fn validatemat matsource_obj = ( if selection.count >= 1 and matsource_obj != undefined do ( if matsource_obj.material == undefined then valid_multisub = 0 else ( -- If it DOEN´S HAVE a Material then INVALID ELSE, go Next routine... if classof matsource_obj.material != Multimaterial then valid_multisub = 0 else ( -- If it HAS a Material but its not a MULTI SUB, then INVALID else go Next routine... -- testslots = for i = 1 to matsource_obj.material.count where sceneMaterials[matsource_obj.material.name].material[i] !=undefined collect i -- OLD Detection testslots = for i = 1 to matsource_obj.material.count where matsource_obj.material[i] !=undefined collect i if matsource_obj.material.count != 0 then valid_multisub = 1 else valid_multisub = 0 ) ) ) -- endi if more than one selected ) -- end function if selection.count >= 1 and superClassOf selection[1] == GeometryClass then ( matsource_obj = selection[1] validatemat matsource_obj source_label = matsource_obj.name picklist = (if valid_multisub == 1 then for c = 1 to matsource_obj.material.count where matsource_obj.material[c] !=undefined collect "ID "+c as string +" : "+matsource_obj.material[c].name else #("No MultiMaterial on Selected")) )else ( matsource_obj = undefined picklist = #("No MultiMaterial on Selected") source_label = "none" ) fn addIDtag newID = -- Output STRING ( for i = 1 to selection.count do -- LOOOOOOP ( if matchPattern selection[i].name pattern:"*_ID??_*" == false then -- Cant find _ID on nane, add IT ( selection[i].name = (selection[i].name + "_ID" + newID +"_") ) else ( tagpos = (findstring selection[i].name "_ID") n1 = replace selection[i].name tagpos 6 " " -- REMOVES _IDXX_ from name using tag position selection[i].name = replace n1 tagpos 1 ("_ID" + newID +"_") -- ADD new TAG on Tag position TAGPOS ) ) ) fn removeIDtag = -- Output as STRING ( if matchPattern selection[1].name pattern:"*_ID??_*" == true do -- Check if name has IDTAG and remove it ( tagpos = (findstring selection[1].name "_ID") n1 = replace selection[1].name tagpos 6 " " -- REMOVES _IDXX_ from name using tag position selection[1].name = replace n1 tagpos 1 ("") -- ADD new TAG on Tag position TAGPOS ) ) fn setIDbuttons newID = ( if subobjectlevel == 0 or subobjectlevel == undefined then ( -- If no subobject selected then wipemID() -- Clean all MatMod Modifiers on Stack for i = 1 to selection.count do ( local midMod = Materialmodifier () midMod.name = "New matID: "+ newID addModifier selection[i] midMod selection[i].modifiers[1].materialID = newID as integer if matid_addtag != 0 do addIDtag (mID_addzeros selection[i].modifiers[1].materialID) -- Search for _ID##_ and Rename OBJECT with the new ID status_label = "ID:"+newID+" Applied" ) ) else ( if selection.count == 1 do ( for x in selection do ( for i = x.modifiers.count to 1 by -1 where classof x.modifiers[i] == edit_poly do ( x.modifiers[i].SetOperation #SetMaterial x.modifiers[i].materialIDToSet = ((newID as integer)-1) x.modifiers[i].Commit () ) ) status_label = "ID:"+newID+" Applied to Selected Faces" wipemID() -- Clean all MatMod Modifiers on Stack removeIDtag() ) ) ) --- The ID LISTBOX ALWAYS shows the Material NAMES, not ROOT NAMES... source_label = "none" picklist = #() global status_label = "" fn getnewlist matsource_obj = ( if matsource_obj != undefined do ( validatemat matsource_obj if classof matsource_obj.material != multimaterial or valid_multisub == 0 then ( picklist = #("No MultiMaterial on Selected") status_label = "No MultiMaterial on Selected" ) else ( for c = 1 to matsource_obj.material.count do -- PickObject as valid material and list them ( if matsource_obj.material[c] !=undefined then picklist[c] = ("ID "+c as string +" :"+ matsource_obj.material[c].name) else picklist[c] = ("ID "+c as string +" :"+"----------- empty") -- Fill Picklist positions with undefined status_label = "2clicks to Apply Mat " ) ) ) ) try(DestroyDialog MatIDTools)catch() rollout MatIDTools "MatID Tools V1.12" ( group "Choose Source SubMaterials source :" ( label lbl_picked_obj "Source:" across:2 align:#left label picked_obj source_label align:#left pos:[55,24] pickbutton bt_pick "Pick Source Object (SubMaterial)" width:(matid_uwidth-20) button bt_picksel "Pick from Selected Object" width:(matid_uwidth-20) button bt_applySourcetoSel "Apply Source Material to Selection" width:(matid_uwidth-20) listbox matids "Materials List [NODES]" items:picklist height:10 checkbox matid_chk1 "Add IdTag Suffix" checked:on align:#left across:2 button bt_getlist "Get List" tooltip:"Get a formated list of Materials and IDS on Listener" align:#right height:15 checkbox matid_chk2 "Instanced MIds" checked:on align:#left across:2 tooltip:"Checked :Instance ModifierIDs if more than one object is selected\n Unchecked: Non-Instanced Modifiers" checkbox matid_chk3 "MIDonTop" checked:on tooltip:"Checked :Add ModifierIDs on top of Stack\n Unchecked: Add ModifiersID at the bottom of Stack" label sel1 status_label ) group "Mult-Sub Source RENAMER" ( button bt_spreadslots "NODES <- ROOT" width:(matid_uwidth/2.3) align:#left across:2 button bt_spreadnodes "NODES -> ROOT" width:(matid_uwidth/2.3) align:#right ) group "Set faceID or addIDTag + MatID Mod" ( button btnID01 "01" width:(mid_butsize/5) height:20 across:6 button btnID02 "02" width:(mid_butsize/5) height:20 button btnID03 "03" width:(mid_butsize/5) height:20 button btnID04 "04" width:(mid_butsize/5) height:20 button btnID05 "05" width:(mid_butsize/5) height:20 button btnID06 "06" width:(mid_butsize/5) height:20 button btnID07 "07" width:(mid_butsize/5) height:20 across:6 button btnID08 "08" width:(mid_butsize/5) height:20 button btnID09 "09" width:(mid_butsize/5) height:20 button btnID10 "10" width:(mid_butsize/5) height:20 button btnID11 "11" width:(mid_butsize/5) height:20 button btnID12 "12" width:(mid_butsize/5) height:20 button btnID13 "13" width:(mid_butsize/5) height:20 across:6 button btnID14 "14" width:(mid_butsize/5) height:20 button btnID15 "15" width:(mid_butsize/5) height:20 button btnID16 "16" width:(mid_butsize/5) height:20 button btnID17 "17" width:(mid_butsize/5) height:20 button btnID18 "18" width:(mid_butsize/5) height:20 button btnID19 "19" width:(mid_butsize/5) height:20 across:6 button btnID20 "20" width:(mid_butsize/5) height:20 button btnID21 "21" width:(mid_butsize/5) height:20 button btnID22 "22" width:(mid_butsize/5) height:20 button btnID23 "23" width:(mid_butsize/5) height:20 button btnID24 "24" width:(mid_butsize/5) height:20 -- editText edtmID "" text:"25" width:90 height:20 tooltip:"Set Custom ID Number..." across:2 spinner spnmID "" width:90 height:20 range:[1,99,spnID] type:#integer across:2 align:#left button btnIDcustom "Apply" width:(matid_uwidth/2.3) align:#right button btnIDfaces "Edit Face IDs" across:2 width:(matid_uwidth/2.3) button btnmIDwipe "Wipe mID Mods" width:(matid_uwidth/2.3) ) label lab1 "© Kumodot tools - Marcelo Souza - 2015" -- Registry on btnID01 pressed do (setIDbuttons "01" -- Choose IDs sel1.text = status_label) on btnID02 pressed do (setIDbuttons "02" sel1.text = status_label) on btnID03 pressed do (setIDbuttons "03" sel1.text = status_label) on btnID04 pressed do (setIDbuttons "04" sel1.text = status_label) on btnID05 pressed do (setIDbuttons "05" sel1.text = status_label) on btnID06 pressed do (setIDbuttons "06" sel1.text = status_label) on btnID07 pressed do (setIDbuttons "07" sel1.text = status_label) on btnID08 pressed do (setIDbuttons "08" sel1.text = status_label) on btnID09 pressed do (setIDbuttons "09" sel1.text = status_label) on btnID10 pressed do (setIDbuttons "10" sel1.text = status_label) on btnID11 pressed do (setIDbuttons "11" sel1.text = status_label) on btnID12 pressed do (setIDbuttons "12" sel1.text = status_label) on btnID13 pressed do (setIDbuttons "13" sel1.text = status_label) on btnID14 pressed do (setIDbuttons "14" sel1.text = status_label) on btnID15 pressed do (setIDbuttons "15" sel1.text = status_label) on btnID16 pressed do (setIDbuttons "16" sel1.text = status_label) on btnID17 pressed do (setIDbuttons "17" sel1.text = status_label) on btnID18 pressed do (setIDbuttons "18" sel1.text = status_label) on btnID19 pressed do (setIDbuttons "19" sel1.text = status_label) on btnID20 pressed do (setIDbuttons "20" sel1.text = status_label) on btnID21 pressed do (setIDbuttons "21" sel1.text = status_label) on btnID22 pressed do (setIDbuttons "22" sel1.text = status_label) on btnID23 pressed do (setIDbuttons "23" sel1.text = status_label) on btnID24 pressed do (setIDbuttons "24" sel1.text = status_label) on spnmID changed spnIDvalue do spnID = spnIDvalue on btnIDcustom pressed do (setIDbuttons (spnID as string) sel1.text = status_label) on btnIDfaces pressed do ( -- Edit Face IDS if selection.count == 1 then ( wipemID() removeIDtag() status_label = " Editing Face IDs" sel1.text = status_label local epolymod = Edit_Poly() epolymod.name = "Edit FaceIDs Mod" addModifier selection[1] epolymod subobjectlevel = 4 ) else MessageBox "Select ONE object to Edit Face IDs" ) on btnmIDwipe pressed do ( -- Remove Material ID Mod and TAG v0.1 wipemID() removeIDtag() status_label = " matID Mod and IDTags Cleaned !" sel1.text = status_label ) on matids selected nameIndex do ( status_label = "" sel1.text = status_label if matids.items.count > 1 then ( sel1.text = status_label+ (matids.items[nameIndex]) as string ) else ( -- status_label = "No MultiMaterial on Selected" sel1.text = status_label ) ) on MatIDTools open do ( source_label = "none" if selection.count >= 1 do ( matsource_obj = selection[1] getnewlist matsource_obj ) sel1.text = status_label -- + (matids.items[nameIndex]) as string matids.items = picklist ) on matid_chk1 changed matid_chk1status do -- Check if the script should rename the MaterialID modifier or not ( if matid_chk1status == true then ( matid_addtag = 1 ) else matid_addtag = 0 ) on matid_chk2 changed matid_chk2status do -- Check if the Modifier will be instanced or not ( if matid_chk2status == true then ( matid_instance = 1 ) else matid_instance = 0 ) on matid_chk3 changed matid_chk3status do -- Check if the Modifier will be instanced or not ( if matid_chk3status == true then ( matid_modpos = 1 ) else matid_modpos = 0 ) on matids doubleClicked itm do ( if matids.items.count > 1 then ( -- Check if source material is a multimaterial if subobjectlevel == 0 or subobjectlevel == undefined then -- Apply material IDs per objects not subobjects ( wipemID() -- Delete all MaterialID modifiers in Stack if matid_instance == 0 then ( for i = 1 to selection.count do ( -- -- If you want to apply **** NOT **** Instanced mIDs -- modPanel.setCurrentObject selection[i].modifiers[selection[i].modifiers.count] local midMod = Materialmodifier () midMod.name = matids.items[itm] as string if matid_modpos == 1 then ( addModifier selection[i] midMod -- Add mID on TOP selection[i].modifiers[1].materialID = itm if matid_addtag != 0 do addIDtag (mID_addzeros selection[i].modifiers[1].materialID) -- Search for _ID##_ and Rename OBJECT with the new ID ) else (addModifier selection[i] midMod before:(selection[i].modifiers.count) -- Add mID on BOTTOM selection[i].modifiers[(selection[i].modifiers.count)].materialID = itm if matid_addtag != 0 do addIDtag (mID_addzeros selection[i].modifiers[(selection[i].modifiers.count)].materialID) -- Search for _ID##_ and Rename OBJECT with the new ID ) status_label = " Applied" sel1.text = status_label ) ) else ( -- If you want to apply Instanced mIDs - DEFAULT local midMod = Materialmodifier () midMod.name = matids.items[itm] as string for i = 1 to selection.count do ( if matid_modpos == 1 then ( addModifier selection[i] midMod -- Add mID on TOP selection[i].modifiers[1].materialID = itm if matid_addtag != 0 do addIDtag (mID_addzeros selection[i].modifiers[1].materialID) -- Search for _ID##_ and Rename OBJECT with the new ID ) else (addModifier selection[i] midMod before:(selection[i].modifiers.count) -- Add mID on BOTTOM selection[i].modifiers[(selection[i].modifiers.count)].materialID = itm if matid_addtag != 0 do addIDtag (mID_addzeros selection[i].modifiers[(selection[i].modifiers.count)].materialID) -- Search for _ID##_ and Rename OBJECT with the new ID ) status_label = " Applied" sel1.text = status_label ) ) ) else ( -- Apply material IDs to Subobjects setlevel = subobjectlevel if selection.count == 1 do ( for x in selection do ( for i = x.modifiers.count to 1 by -1 where classof x.modifiers[i] == edit_poly do ( x.modifiers[i].SetOperation #SetMaterial x.modifiers[i].materialIDToSet = (itm-1) x.modifiers[i].Commit () ) ) status_label = " Applied to Faces" sel1.text = status_label wipemID() -- Clean all MatMod Modifiers on Stack removeIDtag() subobjectlevel = setlevel ) ) -- END OF ELSE sel1.text = matids.items[itm] as string + status_label if matsource_obj.material != undefined then selection.material = matsource_obj.material else MessageBox "Source Material/Object doesn´t have Materials." ) else ( status_label = "Can´t Apply MaterialID" sel1.text = status_label ) ) on bt_pick picked obj do ( status_label = "" sel1.text = status_label global matsource_obj = obj source_label = matsource_obj.name picked_obj.text = source_label getnewlist matsource_obj if valid_multisub == 1 then (status_label = "2clicks to Apply Mat " sel1.text = status_label+ (matids.items[nameIndex]) as string) else sel1.text = status_label matids.items = picklist -- Populate ListBox matids.selection = 1 )--end on on bt_picksel pressed do ( global matsource_obj = selection[1] source_label = matsource_obj.name picked_obj.text = source_label status_label ="" sel1.text = status_label getnewlist matsource_obj if valid_multisub == 1 then (status_label = "2clicks to Apply Mat " sel1.text = status_label+ (matids.items[nameIndex]) as string) else sel1.text = status_label matids.items = picklist matids.selection = 1 if selection.count >= 2 do MessageBox "More than one object selected, using the first one." )--end on on bt_applySourcetoSel pressed do ( if matsource_obj.material != undefined then selection.material = matsource_obj.material else MessageBox "Source Material/Object doesn´t have Materials." )--end on on bt_getlist pressed do ( matids.items = picklist clearlistener() format ("This is the list of IDs from object: " + matsource_obj.name + "\n") if ft_filename != undefined do format ("project name : " + ft_filename + "\n") format "\n" -- pula linha for gl = 1 to matids.items.count do format (matids.items[gl] + "\n") -- format "\n" -- pula linha -- format (" Frame Range :" + firstframe as string +"-"+ lastframe as string +"\n") -- format (" Start Height : " + alturainicial + "\n") -- format (" End Height : " + alturafinal + "\n") -- format (" Lens : " + camLensvalue as string + "mm" + "\n") -- format "\n" -- format "----------------------------\n" )--end on on bt_spreadslots pressed do -- Rename from SLOTS to NODES ( if matsource_obj.material != undefined then ( actionMan.executeAction 0 "50048" for c = 1 to matsource_obj.material.count where matsource_obj.material[c] !=undefined do ( matsource_obj.material[c].name = matsource_obj.material.names[c] getnewlist matsource_obj -- Populate ListBox matids.items = picklist -- Populate ListBox status_label = "NODES RENAMED" sel1.text = status_label ) ) else MessageBox "No MultiMaterial on Selected to Spread." ) on bt_spreadnodes pressed do -- Rename from NODES to SLOTS ( if matsource_obj.material != undefined then ( actionMan.executeAction 0 "50048" for c = 1 to matsource_obj.material.count where matsource_obj.material[c] !=undefined do ( matsource_obj.material.name[c] = matsource_obj.material[c].name getnewlist matsource_obj -- Populate ListBox matids.items = picklist -- Populate ListBox status_label = "Root SLOTS RENAMED" sel1.text = status_label ) ) else MessageBox "No MultiMaterial on Selected to Spread." )--end on )--end rollout createDialog MatIDTools matid_uwidth matid_uheight fgcolor:yellow clearlistener() checkmaxfile()