Help Making Corona Masks element from 3dsmax scene layers!
Hello everyone! I have this idea from some time to make a script that creates corona masks element from scene layers with the layer name, the problem is that i'm a supper beginner in max script and i'm sure that this is to much for me . For now i manage to find some functions that is adding an unique Gbufer Object ID for every layer and after this adding a corona mask element with the object ID name that is corresponding to every single layer from the scene. My question is how can i make the corona mask elements to have the same name like the layer. I will post the script below with what i have so far. Sorry for my bad English!
Comments
This is what i have so far.
(
rollout CoronaMask_roll "Corona Mask"
(
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)
)
return GBufferArray
)
group "Render Elements"
(
button btn_go "Create Corona Mask" align:#right
on btn_go pressed do
(
-- this will add Gbuffer ID on layers
(
fn setLayerObjID ignoreEmpy:on =
(
local getlayer = LayerManager.getlayer, layer, idx = 0
if not ignoreEmpy then (for i = 0 to layerManager.count-1 where ((layer = getlayer i).nodes &objs ; objs).count > 0 do objs.gbufferChannel = (i+1)) else
(
for i = 0 to layerManager.count-1 where ((layer = getlayer i).nodes &objs ; objs).count > 0 do objs.gbufferChannel = (idx+=1)
)
)
setLayerObjID()-- this will ignore empty layer (id order 1,2,3,4,5 ...)
setLayerObjID ignoreEmpy:off -- this will ignore empty layer (id order 1,2,4,6 ...)
)
-------This lines will add CMasking_Mask render elements and Gbuffer id name to element
(
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:("Name of layer here_"+i)mode:0 objectMonoOn:true objectMono:( i as integer))
)
)
else messagebox "Use Corona Render"
)
)
)
) -- dialog
createdialog CoronaMask_roll width:150 height:160 style:#(#style_sysmenu, #style_toolwindow)
)