macroScript NS_CoronaProxyLister category:"Corona Renderer" tooltip:"Corona Proxy
Lister" buttontext:"Corona Proxy Lister" (
-- Corona Proxy Lister
-- Author: Nick Gushchin
-- Email:
[email protected] -- Website: hqdetails.com
-- VARIABLES
-- dialog
global NS_ProxyListerRol
-- array of all proxies in the scene
proxiesAll
-- settings file path
SettingsFolder = "$temp/NikScripts"
SettingsIni = SettingsFolder + "/NS_CoronaProxyLister_settings.ini"
-- default dialog position
dialogPos = [100,100]
-- default autoselect state
uiStateAutoSelect = true
-- LOAD DIALOG SETTINGS
fn LoadSettings = (
-- dialog position
posArr = filterString (getINISetting SettingsIni "settings"
"dialogPos") ","
dialogPos = point2 (posArr[1] as float) (posArr[2] as float)
-- autoselect state
uiStateAutoSelect = (getINISetting SettingsIni "settings" "autoSelect")
as booleanClass
)
-- SAVE SETTINGS
fn SaveSettings = (
-- create ini file
if doesFileExist SettingsIni == false then (
makedir SettingsFolder
createFile SettingsIni
)
-- dialog position
position = (windows.getWindowPos NS_ProxyListerRol.hwnd).x as string +
"," + (windows.getWindowPos NS_ProxyListerRol.hwnd).y as string
-- autoselect state
uiStateAutoSelect = (NS_ProxyListerRol.btn_autoSelect.state as string)
-- add settings to ini
setIniSetting SettingsIni "settings" "dialogPos" position
setIniSetting SettingsIni "settings" "autoSelect" uiStateAutoSelect
)
-- HELP TOOLTIPS GENERATOR
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."
)
-- SORT BY PROXY FILENAME
fn SortByProxyname v1 v2 = stricmp (getFilenameFile v1.filename)
(getFilenameFile v2.filename)
-- GET ALL PROXIES IN SCENE
fn GetProxiesAll = for obj in objects where classof obj == CProxy collect obj
-- GET INSTANCES FOR OBJECTS IN ARRAY
fn GetProxiesInstances objsArr = (
resultArr = #()
for obj in objsArr do (
InstanceMgr.GetInstances obj &instArray
join resultArr instArray
)
resultArr
)
-- GET UNIQUE OBJECTS FROM ARRAY
fn GetProxiesUnique prxArr = (
proxiesUniqueArr = #()
while prxArr.count > 0 do (
InstanceMgr.GetInstances prxArr[1] &instArray
append proxiesUniqueArr instArray[1]
for inst in instArray do (
item = findItem prxArr inst
if item != 0 then deleteItem prxArr item
)
)
qsort proxiesUniqueArr SortByProxyname
proxiesUniqueArr
)
-- CHANGE PROXY PROPERTY
fn ChangeProxyProperty objsArr prop val = (
for obj in objsArr do (
if hasProperty obj prop == true then setProperty obj prop val
)
)
-- CALLBACKS STOP
fn StopCallbacks = (
callbacks.removescripts id:#CProxyListerCallback
gc light:true
)
-- CALLBACKS START
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.0" (
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]
-- UPDATE PROXY TO CHANGE ARRAY
fn GetProxiesFromList = (
if btn_affectAll.state then proxiesAll
else for i=0 to lv.selectedIndices.count-1 collect
proxiesAll[lv.selectedIndices.item[i]+1]
)
-- COMPARE PROPERTIES FOR OBJECTS
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
)
-- UPDATE UI CONTROL STATES
fn UpdateUI = (
selIndices = lv.SelectedIndices
prxArr = GetProxiesFromList()
if prxArr.count != 0 then (
-- affect all btn
if selIndices.count == lv.items.count then
btn_affectAll.state = true
else btn_affectAll.state = false
-- ram cache
if CheckProperty prxArr "cacheInRam" == false then
chkbx_cacheInRam.triState = 2
else chkbx_cacheInRam.state = prxArr[1].cacheInRam
-- previz type
if CheckProperty prxArr "previzType" == false then
rad_previz.state = 0
else rad_previz.state = (prxArr[1].previzType)+1
-- pointcloud density
if CheckProperty prxArr "pointcloudDensity" == false then
spn_cloudDensity.indeterminate = true
else spn_cloudDensity.value =
prxArr[1].pointcloudDensity
-- enable controls
controlsEnabled = true
)
-- disable ram cache if previz is pointcloud or mesh (i don't
know why)
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
)
-- SCENE SELECTION TO LIST SELECTION
fn SceneSelectionToList = if btn_autoSelect.state == true then (
-- deselect all items in list
for x=1 to lv.items.count do lv.items.item[x-1].selected = false
-- get unique proxies from selection
selectedPrxs = for obj in selection where classof obj == CProxy
collect obj
prxArr = GetProxiesUnique selectedPrxs
-- find and select corresponding items in list
for i=1 to prxArr.count do (
itemNum = findItem proxiesAll prxArr[i]
if itemNum != 0 then lv.items.item[itemNum-1].selected =
true
)
UpdateUI()
)
-- LISTVIEW POPULATE
fn ListPopulate = (
rows=#()
-- get all proxies in scene
proxiesAll = GetProxiesUnique (GetProxiesAll())
-- parse proxies to get rows
for prx in proxiesAll do (
-- proxy object name
li = dotNetObject "System.Windows.Forms.ListViewItem"
(prx.name as string)
if doesFileExist prx.filename then (
-- proxyfile path
li.subitems.add (getFilenamePath prx.filename)
-- proxyfile name
li.subitems.add (getFilenameFile prx.filename)
)
-- if proxyfile is missing
else li.subitems.add "Missing"
-- collect rows
append rows li
)
-- add rows to listview
lv.items.addRange rows
)
-- LISTVIEW INITIATE
fn ListInitiate = (
try (lv.Clear()) catch()
-- list settings
lv.view=(dotNetClass "system.windows.forms.view").details
lv.FullRowSelect = true
lv.GridLines = true
lv.MultiSelect = true
lv.HideSelection = false
lv.AllowColumnReorder = true
-- add columns
lv.columns.add "Instance Name" 150
lv.columns.add "Proxy Folder" 280
lv.columns.add "Proxy Filename" 140
-- list populate
ListPopulate()
SceneSelectionToList()
)
-- DIALOG EVENTS
-- dialog open
on NS_ProxyListerRol open do (
ListInitiate()
StartCallbacks()
)
-- dialog closed
on NS_ProxyListerRol close do (
StopCallbacks()
SaveSettings()
)
-- list mouseUp
on lv mouseup arg do UpdateUI()
-- autoselect
on btn_autoSelect changed theState do (
if theState == true then SceneSelectionToList()
uiStateAutoSelect = theState
)
-- affect all
on btn_affectAll changed theState do (
for i=0 to lv.items.count-1 do lv.items.item[i].selected =
theState
setFocus lv
UpdateUI()
)
-- refresh list
on btn_refreshList pressed do ListInitiate()
-- cache in ram
on chkbx_cacheInRam changed theState do ChangeProxyProperty
(GetProxiesFromList()) "cacheInRam" theState
-- previz type
on rad_previz changed theState do (
ChangeProxyProperty (GetProxiesFromList()) "previzType"
(theState-1)
UpdateUI()
)
-- pointcloud density
on spn_cloudDensity changed val do ChangeProxyProperty
(GetProxiesFromList()) "pointcloudDensity" val
-- select proxies instances
on btn_selectPrx pressed do (
prxArr = GetProxiesInstances (GetProxiesFromList())
prxArr = for p in prxArr where p.ishidden == false collect p
select prxArr
)
-- hide proxies instances
on btn_hidePrx pressed do hide (GetProxiesInstances
(GetProxiesFromList()))
-- show proxies instances
on btn_showPrx pressed do unhide (GetProxiesInstances
(GetProxiesFromList()))
)
-- start UI
NS_CProxyLister_OpenUI()
)