Move objects in group to a layer - 3DS

I'm old hat with Max but new to scripting - I'm looking for a way to select a group in 3DS Max (I'm using version 9 if that makes a difference) and have a script that will open the group (and any groups within that group until all groups in the original selection are open), select all objects in the group (regardless of what layer they were originally on), and move them to either the active layer, a new layer, or a layer of your choice (any of those 3 option would work).

In Max, as it is, I can select a group and move the whole thing to a new layer, but I cannot do this if some of the objects in the group are in different layers. Opening every group of objects (most have been built by several different artists with their own layer sets), isolating the selection, selecting all the individual objects, moving them all to the layer you want, closing the group, exiting isolation mode, and starting over with another group gets tedious, so if someone knows how to do this more efficiently it would be greatly appreciated.

Comments

Comment viewing options

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

cool man thanks for this

cool man thanks for this one...
this was really pissing me off

overseastom's picture

Hi Jessup and good luck with

Hi Jessup and good luck with your future scripting :) Regarding this new script you're working on - i tested it in Max 9 (64 bit) and in Max 2008 and the layer manager already moves every object in a group into the layer you want even if the top-level group contains other groups and objects on other layers... I made a sample scene if you want to check it out. Just select the group that you'll see contains other groups (each on other layers) and when you select Layer 1 and then click the + symbol it adds everything into that one layer and doesn't require that you open any groups or anything. Is this what you were looking for or did I misunderstand your design brief? Just in case it saves you some time is all.... :)
-- Tom

AttachmentSize
group and layer swap test.rar 14.51 KB
Jessup3D's picture

I finally got it working,

I finally got it working, and I figured out what the problem was too. This is not a problem in Max 9 specifically, but a problem in Max 9 if you are merging a grouped object with subobjects in different layers from an older version of Max (like version 6 or 7). That made the issue difficult to reproduce and so most folks thought it was a un-needed script (in most of the other forums I tried to search for an answer to this issue.

Here's the working script;

**************************
ActiveSelection = #()
GroupedObj = #()
for s = 1 to ActiveSelection.count do (if isGroupMember Selection[s] then (append GroupedObj ActiveSelection[s]) else false)
for GroupedObj in Selection where isGroupMember GroupedObj AND (NOT isOpenGroupMember GroupedObj) do setGroupOpen GroupedObj.parent true

layerList = #()
if (LayerManager.count > 0) then (
for i = 0 to LayerManager.count - 1 do (
append layerList (LayerManager.getLayer i).name
)
)
selectedLayer = undefined
rollout DestLayer "Layers"
(
dropdownlist Layers "Select Layer" items:layerList
on Layers selected index do (
local layerName = layerList[index]
selectedLayer = (LayerManager.getLayerFromName layerName)
DestroyDialog DestLayer
)
)

layerList = #()
if (LayerManager.count > 0) then (
for i = 0 to LayerManager.count - 1 do (
append layerList (LayerManager.getLayer i).name
)
)
createDialog DestLayer width:100 heigh:100 modal:true
if (selectedLayer != undefined) then
(for node in selection do (selectedLayer.addNode node)

) else (
-- Print nasty messages about the user...;)
-- The user has failed to select a layer
)
actionMan.executeAction 0 "40143"
**************************

jamoka's picture

Cool!

Thanks for sharing, running smoothly.
I'm using Max 2011 64bit.

---------------------------------
cgattack.com

Jessup3D's picture

I'm working on writing the

I'm working on writing the script that allows me to open a group and all it's nested groups and then add all of the selection to a specified layer.

Currently, I have the script working to where it will add the objects to a new layer, but I want to add the functionality of being able to select an existing layer from a list or creating a new layer to put the objects into.

I'm having trouble finding info on how to work with layers in MaxScript though. Anyone know how to do this or know where I can find tutorials on how to work with layers in MaxScript?

Currently this is what I have;

************************
ActiveSelection = #()
GroupedObj = #()
for s = 1 to ActiveSelection.count do (if isGroupMember Selection[s] then (append GroupedObj ActiveSelection[s]) else false)
for GroupedObj in Selection where isGroupMember GroupedObj AND (NOT isOpenGroupMember GroupedObj) do setGroupOpen GroupedObj.parent true
layer = LayerManager.NewLayer(); for node in selection do (layer.addNode node)
************************

Anyone know how to do this?

Comment viewing options

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