Select objects in layer and change object ID

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
scottparris's picture

Sorry, I misunderstood the

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

Thank you sir!

scottparris's picture

Same issue. All of the Object

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

barigazy's picture

...

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 ...)

barigazy

scottparris's picture

I tried your attached script

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

AttachmentSize
screenshot.jpg 627.48 KB
barigazy's picture

...

I corrected the fn. Try again

barigazy

barigazy's picture

...

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

barigazy's picture

...

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)
	)
)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.