Create Render Element for each layer
Hi all,
I would like to create a script which add automaticaly a C_Masking render Element for each layer composed of this objects.
I already succed to create a render element for on layer but i don't know how create a loop which scan all layers in a scene.
Can you help me ? :)
Thank you in advance
Comments
Hi! I want some help to do the same thing.
I manage to add render elments for all the layers with Gbuffer Id name for all the layers but i don't know how to add layer name to the render element. I will put below the code with what i manage to do 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)
)
.
check the answer on cgs
Thank you for the replay!
I checkd the CGS and think that the problem is that im a super beginner and i use just simple maxscript lines and make some minor modifications on other scripts,i will need to learn more to make this modification by my self . Simply said, the only answer for me is that if you can help me to make him work. Thank you very much in advance!
.
I didn't test it in max. Hope it works
Could you make this work with
Could you make this work with V-Ray MultiMattes? It works great with Corona but I can't find the problem writing it for V-Ray.
.
Check your matchpattern pattern
Sorry, one more. Instead of
Sorry, one more. Instead of ignoring empty layers, would it be possible to ignore layers that are turned off or frozen?
It works! Much appreciated.
It works! Much appreciated.
Thank you very much, its working perfectly!
You saved me a lot of time from adding manually all that layers on the CMasking render elements. The problem was that i work with large scenes with many layers and i have to be very organize with all the assets.
Thank you one more time for your time and patience to help me and other people.
Why not share this script?
Why not share this script?, it could be very useful! Thank