ScriptSpot

Forum topic · General Scripting

Select objects in layer and change object ID

By scottparris · 2014-07-07

Description

I need a script that will loop through all of the scene layers, select all of the objects in the layer and change the g-Buffer Object ID. Go to the next layer and do the same, and so on, and so on.

This is what I got so far:

for i = 0 to layerManager.count-1 do
(
layer = ILayerManager.getLayerObject i
)
layer.select true
$.gbufferChannel = 1

Thanks guys!

Comments (7)

scottparris · 2014-07-07

Sorry, I misunderstood the run and evaluate. It works great.

Thank you sir!

scottparris · 2014-07-07

Same issue. All of the Object ID's are still at 0.

barigazy · 2014-07-07

You not run fn correctly. I suggest you to read some topics about functions in MaxScript Help. Anyway...
Firs run fn and then line that I posted as explanation.

--run function
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)
)
)
--evaluate fn with next line
setLayerObjID() -- this will ignore empty layer (id order 1,2,3,4,5 ...)
-- or evaluate fn with next line
setLayerObjID ignoreEmpy:off -- this will ignore empty layer (id order 1,2,4,6 ...)

scottparris · 2014-07-07

I tried your attached script but the Object ID is still at 0

Attachments

barigazy · 2014-07-07

I corrected the fn. Try again

barigazy · 2014-07-07

Now explanation about "ignoreEmpty" argument
If "ignoreEmpty" is set to "on" ei. you run this line...


setLayerObjID()

...script will ignore all empty layers and use ID order 1,2,3,4,5,6 etc.
But if you run line where "ignoreEmpty" is set to "off" ei. ...


setLayerObjID ignoreEmpty:off

... script will ignore also all empty layers and skip layer number.
So if 3rd layer and 5th layer in the Layer Manager is empty then ID order looks like this: 1,2,4,6 etc.

barigazy · 2014-07-07

Try this fn


fn setLayerObjID ignoreEmpy:off =
(
	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)
	)
)