macroScript NS_CoronaProxyLister category:"Nik Scripts" tooltip:"Corona Proxy Lister" buttontext:"Corona Proxy Lister" ( -- Corona Proxy Lister -- Author: Nick Gushchin -- Email: nik.gushchin@gmail.com -- Website: hqdetails.com -- VARIABLES global NS_ProxyListerRol proxiesAll SettingsFolder = "$temp/NikScripts" SettingsIni = SettingsFolder + "/NS_CoronaProxyLister_settings.ini" dialogPos = [100,100] uiStateAutoSelect = true fn LoadSettings = ( posArr = filterString (getINISetting SettingsIni "settings" "dialogPos") "," dialogPos = point2 (posArr[1] as float) (posArr[2] as float) uiStateAutoSelect = (getINISetting SettingsIni "settings" "autoSelect") as booleanClass ) fn SaveSettings = ( if doesFileExist SettingsIni == false then ( makedir SettingsFolder createFile SettingsIni ) position = (windows.getWindowPos NS_ProxyListerRol.hwnd).x as string + "," + (windows.getWindowPos NS_ProxyListerRol.hwnd).y as string uiStateAutoSelect = (NS_ProxyListerRol.btn_autoSelect.state as string) setIniSetting SettingsIni "settings" "dialogPos" position setIniSetting SettingsIni "settings" "autoSelect" uiStateAutoSelect ) fn HelpTooltip id = ( if id == "UpdateList" then return "Update proxies list." if id == "AutoSelect" then return "Get list selection from scene selection." if id == "AffectAll" then return "Affect all proxies in the scene." if id == "CacheInRam" then return "Do not flush the model from RAM between renders. Increases scene parsing speed and memory consumption when enabled" if id == "Select" then return "Select highlighted unhidden proxy instances." if id == "Hide" then return "Hide highlighted proxy instances." if id == "Show" then return "Unhide highlighted proxy instances." ) fn SortByProxyname v1 v2 = stricmp (getFilenameFile v1.filename) (getFilenameFile v2.filename) fn GetProxiesAll = for obj in objects where classof obj == CProxy collect obj fn GetCorrectProxyInstances obj = ( InstanceMgr.GetInstances obj &instArray for obj in instArray where iskindof obj CProxy collect obj ) fn GetProxiesInstances objsArr = ( resultArr = #() for obj in objsArr do ( instArray = GetCorrectProxyInstances obj join resultArr instArray ) resultArr ) fn GetProxiesUnique prxArr = ( proxiesUniqueArr = #() while prxArr.count > 0 do ( instArray = GetCorrectProxyInstances prxArr[1] append proxiesUniqueArr instArray[1] for inst in instArray do ( item = findItem prxArr inst if item != 0 then deleteItem prxArr item ) ) qsort proxiesUniqueArr SortByProxyname proxiesUniqueArr ) fn ChangeProxyProperty objsArr prop val = ( for obj in objsArr do ( if hasProperty obj prop == true then setProperty obj prop val ) ) fn StopCallbacks = ( callbacks.removescripts id:#CProxyListerCallback gc light:true ) fn StartCallbacks = ( callbacks.addscript #filePostOpen "NS_ProxyListerRol.ListInitiate()" id:#CProxyListerCallback callbacks.addscript #filePostMerge "NS_ProxyListerRol.ListInitiate()" id:#CProxyListerCallback callbacks.addscript #selectedNodesPostDelete "NS_ProxyListerRol.ListInitiate()" id:#CProxyListerCallback callbacks.addscript #selectionSetChanged "NS_ProxyListerRol.SceneSelectionToList()" id:#CProxyListerCallback ) --------------------------------------------------------------------- CREATE DIALOG try ( SaveSettings() destroyDialog NS_ProxyListerRol )catch() fn NS_CProxyLister_OpenUI = ( try (LoadSettings())catch() CreateDialog NS_ProxyListerRol 705 320 dialogPos.x dialogPos.y style:#(#style_titlebar,#style_minimizebox,#style_sysmenu) ) --------------------------------------------------------------------- ROLLOUT Rollout NS_ProxyListerRol "CProxyLister v1.1" ( button btn_refreshList "Update List" width:80 height:20 pos:[0,0] tooltip:(HelpTooltip "UpdateList") checkbutton btn_autoSelect "AutoSelect" width:80 height:20 pos:[90,0] tooltip:(HelpTooltip "AutoSelect") checked:uiStateAutoSelect checkbutton btn_affectAll "Affect All" width:80 height:20 pos:[180,0] tooltip:(HelpTooltip "AffectAll") edittext edt_prxCount "Proxies:" text:"" fieldWidth:60 height:20 readOnly:true pos:[388,0] edittext edt_unqCount "Unique:" text:"" fieldWidth:60 height:20 readOnly:true pos:[499,0] checkbox chkbx_cacheInRam "RAM Cache" align:#right offset:[0,-5] tooltip:(HelpTooltip "CacheInRam") radiobuttons rad_previz "Previz Type:" labels:#("Solid Box","Wire Box","Point Cloud","Full mesh") columns:1 align:#right spinner spn_cloudDensity "Dens:" range:[0.1,100,2] type:#float fieldWidth:40 align:#right button btn_selectPrx "Select" width:80 height:20 align:#right offset:[0,96] tooltip:(HelpTooltip "Select") button btn_hidePrx "Hide" width:80 height:20 align:#right tooltip:(HelpTooltip "Hide") button btn_showPrx "Show" width:80 height:20 align:#right tooltip:(HelpTooltip "Show") dotNetControl lv "system.windows.forms.listView" width:600 height:300 pos:[0,20] fn GetProxiesFromList = ( if btn_affectAll.state then proxiesAll else for i=0 to lv.selectedIndices.count-1 collect proxiesAll[lv.selectedIndices.item[i]+1] ) fn CheckProperty objsArr prop = ( testArr = for i=1 to objsArr.count collect getProperty objsArr[1] prop propsArr = for obj in objsArr collect getProperty obj prop with PrintAllElements on testArr as string == propsArr as string ) fn UpdateUI = ( selIndices = lv.SelectedIndices prxArr = GetProxiesFromList() if prxArr.count != 0 then ( if selIndices.count == lv.items.count then btn_affectAll.state = true else btn_affectAll.state = false if CheckProperty prxArr "cacheInRam" == false then chkbx_cacheInRam.triState = 2 else chkbx_cacheInRam.state = prxArr[1].cacheInRam if CheckProperty prxArr "previzType" == false then rad_previz.state = 0 else rad_previz.state = (prxArr[1].previzType)+1 if CheckProperty prxArr "pointcloudDensity" == false then spn_cloudDensity.indeterminate = true else spn_cloudDensity.value = prxArr[1].pointcloudDensity controlsEnabled = true ) if rad_previz.state == 3 or rad_previz.state == 4 then chkbx_cacheInRam.enabled = false else chkbx_cacheInRam.enabled = true edt_prxCount.text = (GetProxiesAll()).count as string edt_unqCount.text = proxiesAll.count as string ) fn SceneSelectionToList = if btn_autoSelect.state == true then ( for x=1 to lv.items.count do lv.items.item[x-1].selected = false selectedPrxs = for obj in selection where classof obj == CProxy collect obj prxArr = GetProxiesUnique selectedPrxs for i=1 to prxArr.count do ( itemNum = findItem proxiesAll prxArr[i] if itemNum != 0 then lv.items.item[itemNum-1].selected = true ) UpdateUI() ) fn ListPopulate = ( rows=#() proxiesAll = GetProxiesUnique (GetProxiesAll()) for prx in proxiesAll do ( li = dotNetObject "System.Windows.Forms.ListViewItem" (prx.name as string) if doesFileExist prx.filename then ( li.subitems.add (getFilenamePath prx.filename) li.subitems.add (getFilenameFile prx.filename) ) else li.subitems.add "Missing" append rows li ) lv.items.addRange rows ) fn ListInitiate = ( try (lv.Clear()) catch() lv.view=(dotNetClass "system.windows.forms.view").details lv.FullRowSelect = true lv.GridLines = true lv.MultiSelect = true lv.HideSelection = false lv.AllowColumnReorder = true lv.columns.add "Instance Name" 150 lv.columns.add "Proxy Folder" 280 lv.columns.add "Proxy Filename" 140 ListPopulate() SceneSelectionToList() ) on NS_ProxyListerRol open do ( ListInitiate() StartCallbacks() ) on NS_ProxyListerRol close do ( StopCallbacks() SaveSettings() ) on lv mouseup arg do UpdateUI() on btn_autoSelect changed theState do ( if theState == true then SceneSelectionToList() uiStateAutoSelect = theState ) on btn_affectAll changed theState do ( for i=0 to lv.items.count-1 do lv.items.item[i].selected = theState setFocus lv UpdateUI() ) on btn_refreshList pressed do ListInitiate() on chkbx_cacheInRam changed theState do ChangeProxyProperty (GetProxiesFromList()) "cacheInRam" theState on rad_previz changed theState do ( ChangeProxyProperty (GetProxiesFromList()) "previzType" (theState-1) UpdateUI() ) on spn_cloudDensity changed val do ChangeProxyProperty (GetProxiesFromList()) "pointcloudDensity" val on btn_selectPrx pressed do ( prxArr = GetProxiesInstances (GetProxiesFromList()) prxArr = for p in prxArr where p.ishidden == false collect p select prxArr ) on btn_hidePrx pressed do hide (GetProxiesInstances (GetProxiesFromList())) on btn_showPrx pressed do unhide (GetProxiesInstances (GetProxiesFromList())) ) NS_CProxyLister_OpenUI() )