-- Original code for gp_collectByWirecolor by capitanred http://www.scriptspot.com/blog/capitanred/collectbywirecolor -- Comments, rollout addition and code changes by James Clarke, @SnipeyX ( try(destroyDialog rolCollectWireColor)catch() rollout rolCollectWirecolor "Collect Wirecolors" ( local gp_colorArr =#() global gp_selectedArr = #() local gp_sameColorArr =#() fn gp_collectByWirecolor makeMatsBool makeLayersBool matTypeStr = ( if (gp_selectedArr.count > 0) then( --build array of unique wirecolors for i in gp_selectedArr do( if findItem gp_colorArr i.wireColor == 0 then append gp_colorArr i.wireColor ) --iterate through each unique color for c = gp_colorArr.count to 1 by -1 do( myColor = gp_colorArr[c] --compare each selected object and see if it matches the current color for s = gp_selectedArr.count to 1 by -1 do( myObj = gp_selectedArr[s] if gp_selectedArr[s].wireColor.red == myColor.red then( if gp_selectedArr[s].wireColor.green == myColor.green then( if gp_selectedArr[s].wireColor.blue == myColor.blue then( --current object matches, so remove it and add it to the current same color array deleteItem gp_selectedArr s append gp_sameColorArr myObj ) ) ) ) -- at this point we've iterated through all selected objects -- and have an temporary array of objects whose colors match the 'current color' myObj = undefined deleteItem gp_colorArr c --grabbing values as integers to remove decimal characters local RedInt = gp_sameColorArr[1].wirecolor.red as integer local GreenInt = gp_sameColorArr[1].wirecolor.green as integer local BlueInt = gp_sameColorArr[1].wirecolor.blue as integer local newMat local newName = "R" + RedInt as string + " G" + GreenInt as String + " B" + BlueInt as string if makeMatsBool do ( case matTypeStr of ( "vray" : newMat = VrayMtl() "standard" : newMat = Standard() "arch" : newMat = Arch___Design__mi() ) newMat.name = newName if classOf newMat == Arch___Design__mi then newMat.diff_color = myColor else newMat.Diffuse = myColor ) local theNewLayer if makeLayersBool do ( theNewLayer = Layermanager.newLayerFromName newName if theNewLayer == undefined do theNewLayer = layermanager.getlayerfromname newName ) --assign the new unique color material to all objects in the same color array for a = gp_sameColorArr.count to 1 by -1 do ( if makeMatsBool do gp_sameColorArr[a].material = newMat if makeLayersBool do theNewLayer.addNode gp_sameColorArr[a] ) --clear out the same color array and start over on the next unique color gp_sameColorArr =#() ) gp_colorArr =#() gp_selectedArr =#() ) else ( Messagebox "No objects selected!" ) ) button btn_DiffToWire "Copy Diffuse to WireColor" checkbox chk_Layers "Create Layers" checked:true checkbox chk_Mats "Create Materials" checked:true radiobuttons rdo1 "Material Type:" labels:#("Standard", "Vray","Arch&&Design") button btn_runSel "Collect on Selected Objects" button btn_runAll "Collect on All Objects" on btn_DiffToWire pressed do ( for o in objects do ( if o.material != undefined do ( case classOf o.material of ( Standard : o.wirecolor = o.material.diffuse VrayMtl : o.wirecolor = o.material.diffuse Arch___Design__mi : o.wirecolor = o.material.diff_color default : print ("Material Type: " + (classOf o.material) as string + " on object: " + o.name + " is unsupported.") ) ) ) ) on btn_runSel Pressed do ( rdoVal = case rdo1.state of ( 1: "standard" 2: "vray" 3: "arch" ) origSel = selection as array gp_selectedArr = selection as array gp_collectByWirecolor chk_mats.checked chk_Layers.checked rdoVal clearselection() select origSel gc light:true ) on btn_runAll pressed do ( rdoVal = case rdo1.state of ( 1: "standard" 2: "vray" 3: "arch" ) max select all gp_selectedArr = selection as array gp_collectByWirecolor chk_mats.checked chk_Layers.checked rdoVal clearselection() gc light:true ) on chk_Mats changed state do rdo1.enabled = state ) createDialog rolCollectWireColor "Collect Wirecolors" )