MACROSCRIPT SMES tooltip:"Super MatEditor Switcher" category:"Medit Tools" ( TRY ( cui.UnRegisterDialogBar MatEditorSwitcherRoll destroyDialog MatEditorSwitcherRoll ) CATCH() struct matPage --This class represents a "page" with 24 materials ( materials, --Array to hold materials treeNode, --The corresponding node in the TreeView name, --The name of the page displayed on the TreeView fn putMaterialsInMatEd = ( FOR matIndex = 1 to 24 DO ( setMeditMaterial matIndex materials[matIndex] ) ), fn storeMaterials = ( materials =#() FOR matIndex = 1 to 24 DO ( treeNode.nodes.item[matIndex-1].text = (getMeditMaterial matIndex).name--((getMeditMaterial matIndex).name+" : "+(classOf (getMeditMaterial matIndex)) as string) append materials (getMeditMaterial matIndex) ) ) ) global MatEditorSwitcherRoll global extraMatData global SMEScurrentPage --Stores the currently selected page global SMESmatPages --Stores all the page objects with the materials rollout MatEditorSwitcherRoll "MatEditor Switcher 8000" width:230 ( local freeToUpdate = true --A flag used to keep the AfterSelect event on the TreeView from firing local previousNode --Used to store the previously selected node to change the backColor property local danceState = 0 --Used by the GUI to make de ASCII guy dance button btn_addPage "+" width:20 height:20 pos:[5,5] label lbl_danceGuy "=D\-<" pos:[30,9] align:#left dropDownList ddl_matType items:#("Standard","Vray","Mental Ray","fRender") selection:2 width:100 pos:[126,5] editText et_search width:224 pos:[1,30] dotNetControl tv_matPageList "treeView" width:220 height:600 pos:[5,50] timer tm_danceTimer interval:200 fn paintNodesBackColor newNode= --Paints the black the background in the supplied node and makes the text white. If a previous node was painted the same way, it returns it to the "normal" status ( IF previousNode != undefined DO ( previousNode.backColor = previousNode.backColor.white previousNode.foreColor = previousNode.foreColor.black ) newNode.backColor = newNode.backColor.black newNode.foreColor = newNode.foreColor.white previousNode = newNode ) fn loadMatPages = --Initial loading of material pages, takes data from matPage classes and populates the treeView ( FOR matPageIndex = 1 to SMESmatPages.count DO ( local newNode = TRY (tv_matPageList.nodes.Add SMESmatPages[matPageIndex].name) CATCH("Page "+matPageIndex as string) SMESmatPages[matPageIndex].treeNode = newNode IF matPageIndex != SMEScurrentPage THEN ( FOR matIndex = 1 to 24 DO newNode.nodes.add SMESmatPages[matPageIndex].materials[matIndex].name--(SMESmatPages[matPageIndex].materials[matIndex].name+" : "+(classOf SMESmatPages[matPageIndex].materials[matIndex]) as string) ) ELSE ( FOR matIndex = 1 to 24 DO newNode.nodes.add (getMeditMaterial matIndex).name--((getMeditMaterial matIndex).name+" : "+(classOf (getMeditMaterial matIndex)) as string) ) ) tv_matPageList.selectedNode = tv_matPageList.nodes.item[SMEScurrentPage-1] paintNodesBackColor tv_matPageList.selectedNode ) ON MatEditorSwitcherRoll OPEN DO --Initial setup and loading of materials ( tv_matPageList.labelEdit = true freeToUpdate = false IF SMEScurrentPage == undefined THEN ( IF (isProperty rootnode "SMESMatPage") THEN ( print "Loading Materials from Custom Attributes" SMEScurrentPage = rootNode.SMESMatPage SMESmatPages = #() FOR theNameIndex = 1 to rootNode.SMESMatPageNames.count DO ( local newPage = matPage name:rootNode.SMESMatPageNames[theNameIndex] materials:#() FOR matIndex = 1+(24*(theNameIndex-1)) to 24+(24*(theNameIndex-1)) DO ( print (newPage.name+" - Index: "+matIndex as string) append newPage.materials rootNode.SMESMats[matIndex] ) append SMESmatPages newPage ) loadMatPages() ) ELSE ( SMEScurrentPage = 1 SMESmatPages = #() local pageNode1 = tv_matPageList.nodes.add "Page 1" local newPage = matPage materials:#() treeNode:pageNode1 name:"Page 1" FOR matIndex = 1 to 24 DO ( append newPage.materials (getmeditMaterial matIndex) pageNode1.nodes.add (getMeditmaterial matIndex).name--((getMeditmaterial matIndex).name+" : "+(classOf (getMeditmaterial matIndex)) as string) ) append SMESmatPages newPage tv_matPageList.selectedNode = pageNode1 paintNodesBackColor pageNode1 ) ) ELSE ( loadMatPages() ) tv_matPageList.focus() freeToUpdate = true ) ON MatEditorSwitcherRoll RESIZED arg DO ( tv_matPageList.height = arg.y-55 ) ON et_search changed arg DO --Looks for string matches in the TreeViews. Positive matches have their background set to orange, negative ones to white ( FOR theNodeIndex = 0 to (tv_matPageList.nodes.count-1) DO ( local libNode = tv_matPageList.nodes.item[theNodeIndex] IF tv_matPageList.selectedNode != libNode DO libNode.backColor = libNode.backColor.white FOR subNodeIndex = 0 to (libNode.nodes.count-1) DO ( local matNode = libNode.nodes.item[subNodeIndex] IF (matchPattern matNode.text pattern:("*"+arg+"*")) AND arg != "" THEN ( matNode.backColor = matNode.backColor.orange IF tv_matPageList.selectedNode != libNode DO libNode.backColor = libNode.backColor.orange ) ELSE ( matNode.backColor = matNode.backColor.white ) ) ) ) ON btn_addPage PRESSED DO --Creates a new page on the treeview, setting it as the current one. Materials on the MatEditor ar saved to the preciously selected page. ( SMESmatPages[SMEScurrentPage].storeMaterials() --Store the materials currently in the MatEditor in the current page SMEScurrentPage = (SMESmatPages.count+1) local newPageNode = tv_matPageList.nodes.add ("Page "+SMEScurrentPage as string) --Create a new page node in the treeView local newMatPage = matPage treeNode:newPageNode materials:#() name:("Page "+SMEScurrentPage as string)--Create a new page object append SMESmatPages newMatPage --Add the new page object to the page array FOR matIndex = 1 to 24 DO ( CASE ddl_matType.selection OF --Populate the MatEditor with new materials. Material type is determined by rollDownList control. ( 1: ( setMeditMaterial matIndex (StandardMaterial name:("Standard "+matIndex as string)) --Clear the Material Editor ) 2: ( setMeditMaterial matIndex (VRayMtl name:("VRayMtl "+matIndex as string)) --Clear the Material Editor ) 3: ( setMeditMaterial matIndex (Arch___Design__mi name:("Arch & Design (mi) "+matIndex as string)) --Clear the Material Editor ) 4: ( setMeditMaterial matIndex (fR_Architectural name:("fR Architectural "+matIndex as string)) --Clear the Material Editor ) ) newPageNode.nodes.add (getmeditmaterial matIndex).name--((getmeditmaterial matIndex).name+" : "+(classOf (getmeditmaterial matIndex)) as string) ) tv_matPageList.selectedNode = newPageNode ) ON tv_matPageList AfterSelect arg DO --Loads the page by putting the materials on the MatEditor. Current materials are saved before switching. If a material node is selected, it's set as active slot in the Material Editor ( IF freeToUpdate == true DO ( local oldMatPage = SMEScurrentPage IF arg.node.level == 0 THEN ( SMEScurrentPage = (arg.node.index+1) IF oldMatPage != SMEScurrentPage DO --Only load materials if the page has changed ( SMESmatPages[oldMatPage].storeMaterials() SMESmatPages[SMEScurrentPage].putMaterialsInMatEd() ) paintNodesBackColor arg.node ) ELSE ( SMEScurrentPage = (arg.node.parent.index+1) IF oldMatPage != SMEScurrentPage DO --Only load materials if the page has changed ( SMESmatPages[oldMatPage].storeMaterials() SMESmatPages[SMEScurrentPage].putMaterialsInMatEd() ) activeMeditSlot = (arg.node.index+1) paintNodesBackColor arg.node.parent ) ) ) ON tv_matPageList AfterLabelEdit arg DO --Handles renaming of materials and pages ( IF arg.label != undefined DO ( IF arg.node.level == 0 THEN ( SMESmatPages[arg.node.index+1].name = arg.label ) ELSE ( (getmeditMaterial (arg.node.index+1)).name = arg.label --arg.node.text = (arg.label+" : "+(classOf (getmeditMaterial (arg.node.index+1))) as string) ) ) ) ON tm_danceTimer TICK DO --Handles dancing ASCII guy ( CASE danceState OF ( 0: ( lbl_danceGuy.text = "=D|-<" danceState = 1 ) 1: ( lbl_danceGuy.text = "=D/-<" danceState = 2 ) 2: ( lbl_danceGuy.text = "=D|-<" danceState = 3 ) 3: ( lbl_danceGuy.text = "=D\-<" danceState = 0 ) ) ) ) createDialog MatEditorSwitcherRoll style:#(#style_titlebar, #style_border, #style_sysmenu,#style_resizing) lockWidth:true cui.RegisterDialogBar MatEditorSwitcherRoll minSize:[238,200] maxSize:[238,1200] style:#(#cui_dock_vert,#cui_floatable,#cui_handles) callbacks.removeScripts id:#SuperMaterialSwitcher callbacks.addScript #filePreSave " custAttributes.delete rootNode extraMatData extraMatData = attributes extraMatEdData ( parameters SMES ( SMESMatPage type:#integer SMESMatPageNames type:#stringTab tabSizeVariable:true SMESMats type:#materialTab tabSizeVariable:true ) ) custAttributes.add rootNode extraMatData --Add Custom Attributes rootNode.SMESMatPage = SMEScurrentPage rootNode.SMESMatPageNames = #() rootNode.SMESMats = #() FOR thePage in SMESmatPages DO ( append rootNode.SMESMatPageNames thePage.name FOR theMat in thePage.materials DO append rootNode.SMESMats theMat ) " id:#SuperMaterialSwitcher callbacks.addScript #filePostOpen " TRY ( cui.UnRegisterDialogBar MatEditorSwitcherRoll destroyDialog MatEditorSwitcherRoll ) CATCH() callbacks.removeScripts id:#SuperMaterialSwitcher SMEScurrentPage = undefined SMESmatPages = undefined " id:#SuperMaterialSwitcher callbacks.addScript #systemPostNew " TRY ( cui.UnRegisterDialogBar MatEditorSwitcherRoll destroyDialog MatEditorSwitcherRoll ) CATCH() callbacks.removeScripts id:#SuperMaterialSwitcher SMEScurrentPage = undefined SMESmatPages = undefined " id:#SuperMaterialSwitcher callbacks.addScript #systemPostReset " TRY ( cui.UnRegisterDialogBar MatEditorSwitcherRoll destroyDialog MatEditorSwitcherRoll ) CATCH() callbacks.removeScripts id:#SuperMaterialSwitcher SMEScurrentPage = undefined SMESmatPages = undefined " id:#SuperMaterialSwitcher )