macroScript IDTool category:"IllusionBoxStudio" tooltip:"IDTool" ( local ver = "v2.34c" -- v2.34c - Add Corona maskingID support (by Nik684 from Corona Forum) -- v2.34 - Add "Assign ID by Layers" button -- v2.33 - Add Option to Assign Wirecolor by ID -- v2.32 - Add "Create Vray MultiMatteElement" button -- v2.31 - Add "Assign Incremental ID" button --Closedialog try(destroydialog IDToolDialogTEST)catch() --Globals global IDToolDialogTEST global ShowIDFn --Locals if (getfiles ((GetDir #plugcfg) + "\\requiem_id_tool.ini")).count == 0 then ( setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "pos_x" "300" setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "pos_y" "300" setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "id" "1" setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "autocolor" "true" ) local getIEdir = getFilenamePath sysInfo.windowsdir + "Program Files\\Internet Explorer\\iexplore.exe" local DPosX = getinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "pos_x" as integer local DPosY = getinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "pos_y" as integer local getIDNum = getinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "id" as integer -- local InfoLineCount = 15 local getAutoColor = if (getinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "autocolor") != "" then ( (getinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "autocolor") as BooleanClass ) else (true) --FN -- Collect ObjectsID fn getObjectsIDArray sel = ( local GBufferArray = #() for o in (if sel == false then objects else selection) where o.gbufferchannel != 0 do ( if (findItem GBufferArray (o.gbufferchannel as string)) == 0 then append GBufferArray (o.gbufferchannel as string) ) if GBufferArray.count > 1 then ( fn sort_array p1 p2 = ( local check_value = (p2 as integer) - (p1 as integer) case of ( (check_value < 0.): 1 (check_value > 0.): -1 default: 0 ) ) qsort GBufferArray sort_array ) return GBufferArray ) fn getIDGroupColor arr = ( if arr.count == 1 then return arr[1].wirecolor else if arr.count > 1 then ( local CheckArrNum = 0 local ArrNum = 1 local Res = 0 local CheckRes = 0 for i in arr do ( Res = 0 for a in arr do ( if i.wirecolor == a.wirecolor then Res += 1 ) if Res > CheckRes then ( CheckRes = Res CheckArrNum = ArrNum ) ArrNum += 1 ) return arr[CheckArrNum].wirecolor ) ) --Rollout rollout IDToolDialogTEST ("IDTool " + ver) width:200 ( Group "" ( multiListBox mlb_IDList "" height:10 width:75 across:2 button btn_HighlightID "Highlight" width:95 height:20 offset:[0,0] tooltip:"Highlight ID by Selected Objects" button btn_ClearSelectionID "Clear Sel. ID" width:95 height:20 offset:[43,-117] tooltip:"Clear ID on Selected Objects" button btn_ClearAllID "Clear All ID" width:95 height:20 offset:[43,1] button btn_ShowID "Show ID Viewport" width:95 height:20 offset:[43,1] tooltip:"Show Info on VIEWPORT" button btn_HideID "Hide ID Viewport" width:95 height:20 offset:[44,1] button btn_Refresh "Refresh List" width:175 height:20 offset:[0,14]--align:#right ) Group "Assign ID" ( spinner spn_IDValue "ID: " range:[1,65535,getIDNum] align:#left type:#integer scale:1 button btn_AssignID "Assign ID" width:140 height:24 across:2 align:#left button btn_AssignIncrementalID "+" height:24 width:32 offset:[0,0] align:#right button btn_AssignIDByLayer "Assign ID by Layers" width:175 height:16 align:#center ) Group "Wirecolor by ID" ( checkbox chk_AssignWirecolorByID "Auto Assign Wirecolor by ID" checked:getAutoColor button btn_ReassignWirecolorByID "Reassign Wirecolor by ID" width:175 height:16 ) Group "Assign Random ID" ( spinner spn_RandomMin "min:" range:[1,65534,1] across:2 type:#integer align:#left spinner spn_RandomMax "max:" range:[2,65535,6] type:#integer align:#left offset:[-15,0] button btn_AssignRandomID "Assign Random ID" width:175 height:16 button btn_AssignToSelCount "Assign ID To Selection Count" width:175 height:16 ) Group "Render Elements" ( button btn_CreateVrayElements "Create Vray MultiMatteElement" height:16 width:175 button btn_CreateCoronaElements "Create Corona Masks" height:16 width:175 ) button btn_Help "info..." height:16 width:40 across:2 align:#left -- Open Dialog on IDToolDialogTEST open do ( mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) -- Close Dialog on IDToolDialogTEST close do ( getIDNum = spn_IDValue.value setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "id" (spn_IDValue.value as string) setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "autocolor" (chk_AssignWirecolorByID.state as string) setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "pos_x" ((GetDialogPos IDToolDialogTEST).x as string) setinisetting ((GetDir #plugcfg) + "\\requiem_id_tool.ini") "IDTool" "pos_y" ((GetDialogPos IDToolDialogTEST).y as string) ) -- Reassign Wirecolor By ID on btn_ReassignWirecolorByID pressed do ( undo "IDTool" on ( if mlb_IDList.items.count != 0 then ( ClearSelection() for i in mlb_IDList.items do ( local Arr = for o in objects where (o.gbufferchannel == i as integer) collect o local getColor = getIDGroupColor Arr for i in Arr do i.wirecolor = getColor ) ) completeRedraw() ) ) -- Vray MultiMatteElements on btn_CreateVrayElements pressed do ( if matchpattern (renderers.current as string) pattern:"v_ray*" == true or matchpattern (renderers.current as string) pattern:"vray*" == true then ( get_elements = maxOps.GetCurRenderElementMgr() if (getObjectsIDArray false).count != 0 then ( get_elements_count = get_elements.NumRenderElements() num = 1 check_element_count = 3 for i in (getObjectsIDArray false) do ( check_element_count += 1 if check_element_count > 2 do ( get_elements.AddRenderElement (MultiMatteElement elementname:("MME_IDTool_" + (num as string))) a = get_elements.GetRenderElement get_elements_count a.R_gbufIDOn = false a.G_gbufIDOn = false a.B_gbufIDOn = false a.MatID = false num += 1 check_element_count = 0 get_elements_count += 1 ) local a = get_elements.GetRenderElement (get_elements_count-1) case check_element_count of ( 0: ( a.R_gbufIDOn = true a.R_gbufID = i as integer ) 1: ( a.G_gbufIDOn = true a.G_gbufID = i as integer ) 2: ( a.B_gbufIDOn = true a.B_gbufID = i as integer ) ) ) ) ) else ( messagebox "Use Vray Render" ) ) on btn_CreateCoronaElements pressed do ( if matchpattern (renderers.current as string) pattern:"Corona*" == true then ( re = maxOps.GetCurRenderElementMgr() maskElms = for i=0 to re.NumRenderElements() where classof (re.GetRenderElement i) == CMasking_Mask collect re.GetRenderElement i for i in (getObjectsIDArray false) do ( exclude = false for m in maskElms where m.objectMono == (i as integer) do exclude = true if not exclude then re.AddRenderElement (CMasking_Mask elementname:("ObjectID_" + i) mode:0 objectMonoOn:true objectMono:(i as integer)) ) ) else messagebox "Use Corona Render" ) -- Assign ID Incremental on btn_AssignIncrementalID pressed do ( undo "IDTool" on ( if selection.count != 0 then ( for i in selection do i.gbufferchannel = spn_IDValue.value + 1 if chk_AssignWirecolorByID.state == true then ( wcolor = random white black for i in selection do i.wirecolor = wcolor ) mlb_IDList.items = (getObjectsIDArray false) spn_IDValue.value += 1 completeRedraw() ) ) ) -- Assign ID on btn_AssignID pressed do ( undo "IDTool" on ( if selection.count != 0 then ( for i in selection do i.gbufferchannel = spn_IDValue.value if chk_AssignWirecolorByID.state == true then ( wcolor = random white black for i in selection do i.wirecolor = wcolor ) mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) ) ) on btn_AssignIDByLayer pressed do ( undo "IDTool" on ( try ( disableSceneRedraw() num = 1 for i = 0 to layerManager.count-1 do ( getLayer = layerManager.getLayer i getLayer.select on getLayerName = getLayer.name if selection.count != 0 then ( for i in selection where superclassof i == GeometryClass do i.gbufferchannel = num ) num += 1 ClearSelection() ) enableSceneRedraw() completeRedraw() mlb_IDList.items = (getObjectsIDArray false) ) catch ( enableSceneRedraw() completeRedraw() ) ) ) -- Assign Random ID on btn_AssignRandomID pressed do ( undo "IDTool" on ( if selection.count != 0 then ( for i in selection do ( i.gbufferchannel = random spn_RandomMin.value spn_RandomMax.value ) mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) ) ) -- Assign Random ID To Selection Count on btn_AssignToSelCount pressed do ( undo "IDTool" on ( if selection.count != 0 then ( local IDArr = #() num = 0 for i in selection do ( append IDArr (num += 1) ) for i in selection do ( random_id = random 1 IDArr.count i.gbufferchannel = IDArr[random_id] deleteitem IDArr random_id ) ) mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) ) -- Random Spinner on spn_RandomMin changed val do ( if spn_RandomMin.value >= spn_RandomMax.value then ( spn_RandomMin.value = (spn_RandomMax.value - 1) ) ) on spn_RandomMax changed val do ( if spn_RandomMax.value <= spn_RandomMin.value then ( spn_RandomMax.value = (spn_RandomMin.value + 1) ) ) -- Refresh on btn_Refresh pressed do ( mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) -- Highlight on btn_HighlightID pressed do ( if selection.count != 0 then ( local getListboxPosition = #() if mlb_IDList.items.count != 0 then ( for i = 1 to mlb_IDList.items.count do ( for o in (getObjectsIDArray true) do ( if mlb_IDList.items[i] == o then ( append getListboxPosition i ) ) ) ) mlb_IDList.selection = getListboxPosition ) ) -- Clear All ID on btn_ClearAllID pressed do ( if queryBox "Clear All ID's?" beep:true then ( for i in objects do ( i.gbufferchannel = 0 ) mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) ) -- Clear Selected ID on btn_ClearSelectionID pressed do ( if queryBox "Clear Selected ID?" beep:true then ( if selection.count != 0 then ( for i in selection do ( i.gbufferchannel = 0 ) ) mlb_IDList.items = (getObjectsIDArray false) completeRedraw() ) ) -- Select ID on mlb_IDList selectionEnd do ( local SelectObjIDArray = #() for i in (mlb_IDList.selection as array) do ( for o in objects where (o.gbufferchannel == mlb_IDList.items[i] as integer) do append SelectObjIDArray o ) select SelectObjIDArray ) -- Viewport on btn_ShowID pressed do ( UnRegisterRedrawViewsCallback ShowIDFn --FN fn ShowIDFn = ( for i in objects where i.gbufferChannel != 0 do ( gw.setTransform i.transform gw.text [0,0,0] (i.gbufferChannel as string) color:white gw.enlargeUpdateRect #whole gw.updateScreen() ) ) ShowIDFn() RegisterRedrawViewsCallback ShowIDFn completeRedraw() -- UnRegisterRedrawViewsCallback ShowIDFn -- fn ShowIDFn = -- ( -- gw.setTransform(Matrix3 1) -- gw.wtext [50,((getViewSize()).y/2)-10,0] "IDTool Info:" color:yellow -- num = 1 -- for i in mlb_IDList.items do -- ( -- if num < InfoLineCount then -- ( -- local count = 0 -- for o in objects where o.gbufferchannel == (i as integer) do count += 1 -- gw.wtext [50,((getViewSize()).y/2)+(num*16),0] ("ID " + i + " - " + (count as string) + " Objects") color:yellow -- num += 1 -- ) -- ) -- if mlb_IDList.items.count > InfoLineCount then -- ( -- count = 0 -- gw.wtext [50,((getViewSize()).y/2)+(InfoLineCount*16),0] ("......") color:yellow -- for o in objects where o.gbufferchannel == ((mlb_IDList.items[mlb_IDList.items.count]) as integer) do count += 1 -- gw.wtext [50,((getViewSize()).y/2)+((InfoLineCount+1)*16),0] ("ID " + (mlb_IDList.items[mlb_IDList.items.count]) + " - " + (count as string) + " Objects") color:yellow -- ) -- ) -- RegisterRedrawViewsCallback ShowIDFn -- completeRedraw() ) on btn_HideID pressed do ( UnRegisterRedrawViewsCallback ShowIDFn completeRedraw() ) on btn_Help pressed do ( ShellLaunch getIEdir "http://www.illusionboxstudio.com" ) ) createdialog IDToolDialogTEST pos:[DPosX, DPosY] )