/****************** by Marco Brunetta mbrunetta@gmail.com *******************/ 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 8500" 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 local textColor local backColor button btn_addPage "+" width:20 height:20 pos:[5,5] label lbl_danceGuy "=D\-<" pos:[31,9] align:#left button btn_removePage "-" width:20 height:20 pos:[65,5] 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 = backColor previousNode.foreColor = textColor ) 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 ) ELSE ( FOR matIndex = 1 to 24 DO newNode.nodes.add (getMeditMaterial matIndex).name ) ) tv_matPageList.selectedNode = tv_matPageList.nodes.item[SMEScurrentPage-1] paintNodesBackColor tv_matPageList.selectedNode ) ON MatEditorSwitcherRoll OPEN DO --Initial setup and loading of materials ( local theTextColor = ((colorman.getColor #text)*255) as color textColor = (dotNetClass "System.Drawing.Color").fromARGB theTextColor.r theTextColor.g theTextColor.b local theBackColor = ((colorman.getColor #window)*255) as color backColor = (dotNetClass "System.Drawing.Color").fromARGB theBackColor.r theBackColor.g theBackColor.b tv_matPageList.backColor = backColor tv_matPageList.foreColor = textColor tv_matPageList.labelEdit = true freeToUpdate = false IF SMEScurrentPage == undefined THEN ( IF (isProperty rootnode "SMESMatPage") THEN ( 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 ( 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 ) 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 tv_matPageList.width = arg.x-10 ddl_matType.pos = [arg.x-104,5] et_search.width = arg.x-10 ) 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 = backColor 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 = backColor ) ) ) ) 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. ( undo off ( 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 ) tv_matPageList.selectedNode = newPageNode ) ) ON btn_removePage PRESSED DO ( undo off ( IF tv_matPageList.selectedNode != undefined AND SMESmatPages.count > 1 DO ( local currentPage local currentPageIndex IF tv_matPageList.selectedNode.level == 0 THEN ( currentPage = SMESmatPages[tv_matPageList.selectedNode.index+1] currentPageIndex = tv_matPageList.selectedNode.index+1 ) ELSE ( currentPage = SMESmatPages[tv_matPageList.selectedNode.parent.index+1] currentPageIndex = tv_matPageList.selectedNode.parent.index+1 ) IF queryBox ("You are about to delete the page: "+currentPage.name+"\nTHIS ACTION IS NOT UNDOABLE.\n\nAre you sure you wish to continue?") title:"YOU THINK YOU ARE MAN ENOUGH?" DO ( IF currentPageIndex == 1 THEN ( tv_matPageList.selectedNode = tv_matPageList.nodes.item[1] ) ELSE ( tv_matPageList.selectedNode = tv_matPageList.nodes.item[currentPageIndex-2] ) currentPage.treeNode.remove() SMEScurrentPage = (tv_matPageList.selectedNode.index+1) deleteItem SMESmatPages currentPageIndex gc light:true ) ) ) ) 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 ( undo off ( 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) cui.RegisterDialogBar MatEditorSwitcherRoll minSize:[238,200] maxSize:[1200,1200] style:#(#cui_dock_vert,#cui_floatable,#cui_handles) callbacks.removeScripts id:#SuperMaterialSwitcher callbacks.addScript #filePreSave " extraMatData = attributes extraMatEdData ( parameters SMES ( SMESMatPage type:#integer SMESMatPageNames type:#stringTab tabSizeVariable:true SMESMats type:#materialTab tabSizeVariable:true ) ) TRY (custAttributes.delete rootNode extraMatData) CATCH() 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 )