PDA

View Full Version : Move ojbects in a group to a specified layer


JeremyJessup
12-28-2007, 04:48 PM
Is there a way to automate this process after selecting the group:

Select a group - Open the group (and any subgroups so that there are no closed groups in the selection) - select all objects within the group - move all selected objects from whatever layer they are on to the active layer (or a specified layer)?

I'm still pretty new to MaxScript, and am picking up a bit at a time as I am able and trying to decipher code through Max Listener, but I am kind of stumped on this one. It sounds (to me) like it ought to be something pretty simple, but I'm just not finding (or understanding) the relevant info in the help file.

____________

Example of the problem - I have no problem moving a group into a new layer if all the objects in the group are in the same layer to begin with. However, if I have a group of objects (with objects on several different layers within the group) and I try to add the entire group to a layer (new or existing) either some of the objects will be added or none of the objects will be added.

JeremyJessup
12-31-2007, 06:10 PM
Okay, I think I'm halfway there, I have a code that will open a group and select it's components as well as opening nested groups till there are no closed groups and all the objects in that group are selected;

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

This seems to work for the first part of the problem. Does anyone know how to get a selection assigned to a specific layer (ideally, to give a pop-up that lets you select a layer to place the selection into)?

SnipeyX
12-31-2007, 07:14 PM
I'll preface this response by saying I realize I'm not necessarily being helpful and it's just a workaround....

but it seems to me like you're looking to create a dialog that would display available layers and then pick one of those to assign your current selection to, which is basically what the layer manager already does, if i were in your situation (which I halfway am because I deal with this same issue, moving all group members to a new layer, all the time) I'd just use what you have already written to open/select the group members properly, then I'd just press the "add selected objects to highlighted layer" button.

is there a reason, besides just wanting to learn how to script it, not to do it that way?

JeremyJessup
12-31-2007, 08:13 PM
SnipeyX - Yeah, part of this is just me wanting to know how to do it as I am learning (I've used Max for years but am just getting into scripting).

I'm basing the requirements of the script on what one of my bosses wants... basically shortening the process by a step or two without changing which layer is active or which is the highlighted layer. He wants to select a group that has objects in different layers and move them all to a specified layer and then continue on right where he left off originally with as few extra steps as possible. This will work, but he will be happier if I can automate the whole process.

RustyKnight
12-31-2007, 10:58 PM
SnipeyX - Yeah, part of this is just me wanting to know how to do it as I am learning (I've used Max for years but am just getting into scripting).

I'm basing the requirements of the script on what one of my bosses wants... basically shortening the process by a step or two without changing which layer is active or which is the highlighted layer. He wants to select a group that has objects in different layers and move them all to a specified layer and then continue on right where he left off originally with as few extra steps as possible. This will work, but he will be happier if I can automate the whole process.I haven't played around with anything, so I can't give you feedback on your groups, but, you will want to take a look at "Interface: LayerManager", in particular, getLayer, getLayerFromName (and possible newLayerFromName)...these return a reference to "Interface: LayerProperties" that represents the layer in question.

This interface has a wounderful method call "addNode"

Don't know if you were up to speed with that or not...

Shane

RustyKnight
12-31-2007, 11:22 PM
Is there a way to automate this process after selecting the group:

Select a group - Open the group (and any subgroups so that there are no closed groups in the selection) - select all objects within the group - move all selected objects from whatever layer they are on to the active layer (or a specified layer)?

I'm still pretty new to MaxScript, and am picking up a bit at a time as I am able and trying to decipher code through Max Listener, but I am kind of stumped on this one. It sounds (to me) like it ought to be something pretty simple, but I'm just not finding (or understanding) the relevant info in the help file.

____________

Example of the problem - I have no problem moving a group into a new layer if all the objects in the group are in the same layer to begin with. However, if I have a group of objects (with objects on several different layers within the group) and I try to add the entire group to a layer (new or existing) either some of the objects will be added or none of the objects will be added.Hi Jessup3D.

I've just had a quick play around trying a few things...now I don't know if I fully understand your problem, so this is what I did...

I create a number of layers....
I create a number of objects, spread across those layers
I grouped a small number of the objects together
I grouped the remaining objects and the first group together

I then run a script, which basically, located all the group heads, opened all the groups, moved ALL the objects to the target layer and then reclosed all the groups.

This worked fine for me, indeed, I discovered, I didn't even need to open the groups, I could move all the objects to the target layer without issue.
(

local lstGrpHeads = #()

-- Scan all objects for the group heads in the scene
-- You might need to change this to match your selection...
for node in objects do (

if (isGroupHead node) then (

append lstGrpHeads node

)

)

-- Open all the group heads
for gHead in lstGrpHeads do (

format "Openning %\n" gHead
setGroupOpen gHead true

)

-- Locate our target layer...
local target = LayerManager.getLayerFromName "Layer05"
-- Depending on what you need, you will need to
-- change the reference to the "objects" collection
for node in objects do (

-- Add all the objects in the scene to the target layer
target.addNode node

)

-- Re-close the heads...
for gHead in lstGrpHeads do (

setGroupOpen gHead false

)
)

JeremyJessup
12-31-2007, 11:25 PM
I've been messing around with the addNode method, but my understanding of the logic of the scripting language is lacking, so I'm not using it correctly (getting lots of errors).

In an older post on this forum, I found this code;

LayerManager.newLayerFromName "testLayer";
addNodesToLayer "testLayer" (selection as array);

Which should create a layer and add the selection to the layer, but as yet I have not been able to get that to work. If I can make that work, I'd like to at least be able to assign the new layer name manually, but the best option would be to have a pop-up menu that I could choose the destination layer from.

RustyKnight
12-31-2007, 11:30 PM
Okay, one more update...I've tried it with the selection collection as well...

This will basically scan the selection for all the group heads, open the groups, scan the selection again, moving all the "group members" to the target layer.

This has the interesting effect of moving the sub-groups head node to the target layer, but not the main groups...thought that was kinda cool, but not sure if that is what you want...
(

local lstGrpHeads = #()

-- Scan all objects for the group heads in the scene
-- You might need to change this to match your selection...
for node in selection do (

if (isGroupHead node) then (

append lstGrpHeads node

)

)

-- Open all the group heads
for gHead in lstGrpHeads do (

format "Openning %\n" gHead
setGroupOpen gHead true

)

-- Locate our target layer...
local target = LayerManager.getLayerFromName "Layer05"
-- Depending on what you need, you will need to
-- change the reference to the "objects" collection
for node in selection do (

if (isGroupMember node) then (
-- Add all the objects in the scene to the target layer
target.addNode node
)

)

-- Re-close the heads...
for gHead in lstGrpHeads do (

setGroupOpen gHead false

)
)

So, if you want to move "everything" in the selection to the new layer...you could do
for node in selection do (

if (isGroupMember node) or (isGroupHead node)then (
-- Add all the objects in the scene to the target layer
target.addNode node
)

)
Else, if you only wanted to move the physical objects and NOT effect the group nodes...
for node in selection do (

if (isGroupMember node) and not (isGroupHead node) then (
-- Add all the objects in the scene to the target layer
target.addNode node
)

)Should work.

I hope that gives you some ideas...

Shane

ps I'm using max9

RustyKnight
12-31-2007, 11:48 PM
I've been messing around with the addNode method, but my understanding of the logic of the scripting language is lacking, so I'm not using it correctly (getting lots of errors).

In an older post on this forum, I found this code;

LayerManager.newLayerFromName "testLayer";
addNodesToLayer "testLayer" (selection as array);

Which should create a layer and add the selection to the layer, but as yet I have not been able to get that to work. If I can make that work, I'd like to at least be able to assign the new layer name manually, but the best option would be to have a pop-up menu that I could choose the destination layer from.I could be very mistaken, but "addNodesToLayer" is not a function that is native to maxscript...obviously if you have the code then it should be fine...

I'd imagine it would look something like this...
mapped fn addNodesToLayer node layerName (

local target = LayerManager.getLayerFromName layerName
if target != undefined do (
target.addNode node
)

)Now I'm assuming a lot here...

I've only ever used mapped a couple of times, so my understanding of it may not be correct.

I've switch the parameters, because, as I read it, the docs say Using the mapped prefix on a function definition marks this function to be automatically mapped over collections. This means the function will be automatically called repeatedly on the elements of a collection if the collection is given as the first argument to the function. This allows you to define scripted functions that behave in a similar manner to the mapped built-in functions, such as copy, delete, move, and so on, which can be applied to an object set, path name pattern, or array. See Collections (http://forums.cgsociety.org/Collections.htm) for more information.This basically says, that if the first parameter to the function is an array/collection, then this function will be automatically called for each element in the array.

This allows you specify either a single node or an array for nodes...this is un-tested, so it may not work...but what's life without a little adventure...

Hope all this is helping...

Shane

JeremyJessup
01-02-2008, 03:56 PM
First off, I really appreciate the help. I've tried several combinations of code like you've listed and I'm just not getting things to work right (most likely because I'm not sure how MaxScript needs to be worded).

I either get an error stating "-- Syntax error: at ), expected <factor>"
or "-- Unknown property: "addNode" in undefined"

I really need some help with knowing what I'm looking at and why it works the way it does.
(Also Using Max9)

________________________
Edit:
Okay... what am I doing wrong here?

Here's what I've got so far;
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
function addNodesToLayer str_layerName inputNodes =
(
if str_layerName == undefined or inputNodes == undefined then return undefined;
if (classof inputNodes) != array then inputNodes = #(inputNodes);

local inputLayer = (LayerManager.getLayerFromName str_layerName);

for eachObj in inputNodes do
(
inputLayer.addnode eachObj;
);
);
LayerManager.newLayerFromName "New Layer"; addNodesToLayer "New Layer" (selection as array);

If I run just the first part of the code that says;

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

I get my group and all nested groups to open and I retain all of it as a selection.

When I add the rest of the script, it does generate a new layer, but the group stays closed and nothing gets added to the new layer. I also get an error that says;

<MixinInterface:LayerProperties>
-- Type error: Call needs function or class, got: undefined

I new enough to scripting that I'm probably missing something that's glaringly obvious, but I have no idea what it is.

RustyKnight
01-02-2008, 09:22 PM
I either get an error stating "-- Syntax error: at ), expected <factor>"
This is a complete pain to track down, cause you need to count all the brackets in your script and determine which one you've missed...pain


or "-- Unknown property: "addNode" in undefined"
This would suggest that the layer you've specified does not exist. In your "addNodesToLayer" function you should add a check:

if inputLayer != undefined then (
-- Continue adding nodes to the layer
) else (
-- Handle the error in what ever way you see fit...I like throwing an exception
)

I run your script, as you presented, and it worked fine for me ... I even tried and empty selection and it worked fine...

I might suggest adding some additional brackets around your where statement, eg:
for GroupedObj in Selection where (isGroupMember GroupedObj) AND (NOT isOpenGroupMember GroupedObj) do setGroupOpen GroupedObj.parent true
But otherwise I did not have any problems...


I new enough to scripting that I'm probably missing something that's glaringly obvious, but I have no idea what it is.We're all noods at some level ;)

Shane

edt: I'm using max 9 64, I need to reinstall the 32bit to test, but it shouldn't make any difference...do you have a test scene I might be able to work against?!

RustyKnight
01-02-2008, 09:33 PM
I run your script, once again, but I took out the pre-amble about openning the group and it works fine....

I spread a series of objects over a number of layers, grouped them and run
function addNodesToLayer str_layerName inputNodes =
(
if str_layerName == undefined or inputNodes == undefined then return undefined;
if (classof inputNodes) != array then inputNodes = #(inputNodes);

local inputLayer = (LayerManager.getLayerFromName str_layerName);

for eachObj in inputNodes do
(
inputLayer.addnode eachObj;
);
);
LayerManager.newLayerFromName "New Layer"; addNodesToLayer "New Layer" (selection as array);And had no problems. Everything move to the "New Layer"

Shane

JeremyJessup
01-02-2008, 09:52 PM
Again, I really appreciate the help and I'm trying the advice you've posted but for some reason or other I'm just not getting it to work (I know... my noob-ness is showing). I'm not only trying to get this to work, but I'm trying to understand what is going wrong when it doesn't work. For example, every time I place a ) on it's own line, it gives me an error that says;
-- Syntax error: at ), expected <factor>
-- In line: )

I tried running the code you provided on a test scene (just a bunch of boxes with nested groups several layers deep) and I got a a 'False" response in the listener. I tried it with the group closed as well as with all groups open and got the same result. The new layer didn't show up and nothing seems to have changed in my scene.

My latest stab at this was using this code;
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
(
LayerOne = LayerManager.NewLayer()
LayerOne.addnode Selection

Two of the three seperate parts of this code seem to work - running the part about opening all the groups in the selection works by itself and creating a new layer works by itself. The part about adding the selection to the new layer doesn't work, but I'm not sure why.

Running it all at the same time gives me an error stating that "addnode is undefined" or "Unable to convert: $selection to type: <node>"

I figure your code should work, but I must still be missing something in there too. I don't understand your code as clearly as what I've currently got (not because yours is confusing, but because my maxscript vocabulary is limited)

RustyKnight
01-02-2008, 10:34 PM
-- Syntax error: at ), expected <factor>
-- In line: )This problem is really hard to track down, adding and removing brackets randomly won't help, you need to find out which one you're missing, and open bracket or a closed bracket. I find cutting my code it segements and testing it usually works...

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
(
LayerOne = LayerManager.NewLayer()
LayerOne.addnode Selection
Running it all at the same time gives me an error stating that "addnode is undefined" or "Unable to convert: $selection to type: <node>"

This won't work because addNode expects a single node, not a collection or array...besides, if it was that simple, then you wouldn't need to go to all the hassels you are...also, you are creating a new layer for each object in the selection and then, I assume, adding that object to it's own layer by it self...

I figure your code should work, but I must still be missing something in there too. I don't understand your code as clearly as what I've currently got (not because yours is confusing, but because my maxscript vocabulary is limited)That's okay, I don't always understand it either ;)

Here's a simple one for ya. I took your sample scene and run this script on it:-- Create a new layer
-- Keep a copy of the newly created interface
layer = LayerManager.newLayerFromName "Testing..."

-- Loop through the selection and add each node in the selection to the new layer
for node in selection do (
layer.addNode node
)This worked fine...All the objects and the group helpers moved to the dynamically created layer...See if that helps

Shane

edt: Works in both max 9 x32 and x64

JeremyJessup
01-02-2008, 10:50 PM
You da' Man!

I made a slight modification based on one of the other code strings (so that a new layer was created to avoid problems with putting everything in another 'set of groups' in the same layer if this script has to be run more than once in a scene)

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)

For some reason, the line breaks were causing problems as well, so removing the line break and just adding a ; seemed to make Max read it just fine.

RustyKnight
01-03-2008, 01:02 AM
You da' Man!

I made a slight modification based on one of the other code strings (so that a new layer was created to avoid problems with putting everything in another 'set of groups' in the same layer if this script has to be run more than once in a scene)

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)

For some reason, the line breaks were causing problems as well, so removing the line break and just adding a ; seemed to make Max read it just fine.Ahhh, progress...What I typically do is copy the code over to something like textpad and back again into max. Max's script editor is actually capable of some formatting, which can really screw you around...but that's just me

JeremyJessup
01-03-2008, 03:51 PM
Okay... I'm not sure if this will be biting off more than I can chew, but how would I go about replacing the bit where it says "LayerManager.NewLayer();" with something that would allow me to either select an existing layer from a list?

Ideally, I'd like to be able to have a list to select from with the option of creating a new layer as well, but if this is going to be a nightmare to figure out code for I may just stick with what I've got.

It looks like "listbox" may be my answer, but I can only find info on how to make the list box select an array of items from the scene. How do I get it to list the layers in the Layer Manager?
__________________
Edit:

Okay, now I have this;

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
PickLayer = (rollout DestLayer "Destination Layer"
(
dropdownlist Layers "Select Layer"
on dropdownlist selected do LayerManager.getLayerName
)
createDialog DestLayer
)
LayerOne = layermanager.getlayerfromname "PickLayer"
for node in selection do (layer.addNode node)

It creates an empty dropdown list at the moment. What am I doing wrong that is keeping it from populating the list with the layer names?
(by the way, thanks for the tip about Max's script editor... that was the source of several issues)

RustyKnight
01-03-2008, 09:33 PM
Okay... I'm not sure if this will be biting off more than I can chew, but how would I go about replacing the bit where it says "LayerManager.NewLayer();" with something that would allow me to either select an existing layer from a list?

Ideally, I'd like to be able to have a list to select from with the option of creating a new layer as well, but if this is going to be a nightmare to figure out code for I may just stick with what I've got.

It looks like "listbox" may be my answer, but I can only find info on how to make the list box select an array of items from the scene. How do I get it to list the layers in the Layer Manager?
__________________
Edit:

Okay, now I have this;

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
PickLayer = (rollout DestLayer "Destination Layer"
(
dropdownlist Layers "Select Layer"
on dropdownlist selected do LayerManager.getLayerName
)
createDialog DestLayer
)
LayerOne = layermanager.getlayerfromname "PickLayer"
for node in selection do (layer.addNode node)

It creates an empty dropdown list at the moment. What am I doing wrong that is keeping it from populating the list with the layer names?Think of it this way...the list is an idiot. Unless you tell exactly what you want, it has no idea of what you want...just like me, it can't read your mind...oh, if only it could, how easy would that be :)

What you need to do is initalise it with a list of values

Now I believe you could do something like this....
-- Create a new empty array
layerList = #()
-- Make sure there is at least 1 layer avaliable, otherwise we might
-- cause an error
if (LayerManager.count > 0) then (
-- Loop through the layer list
-- This must be one of the few collections to be zero indexed?!
for i = 0 to LayerManager.count - 1 do (
-- Add each new layer to the array...we only want the NAMES!!
-- This is important, because this is what will be displayed to the
-- user in the dropdown list...
append layerList (LayerManager.getLayer i).name
)
)

-- Place holder for the selected layer
selectedLayer = undefined

rollout DestLayer "Destination Layer" (

dropdownlist Layers "Select Layer" items:layerList

on dropdownlist selected index do (

local layerName = layerList[index]
selectedLayer = (getLayerFromName layerName)

-- Close the dialog automatically when the user selects a new layer...
-- This may not be the best solution, but it will do for the momement
-- and demonstrates how to dismiss a dialog
DestroyDialog DestLayer

)

)

-- Create a MODEL dialog. This will stop the script execution here
-- until the dialog is dismissed or closed by the user...
createDialog DestLayer width:100 heigh:100 model:true

if (selectedLayer != undefined) then (
-- Continue with the script, moving the objects to the new layer...
) else (
-- User did not select a layer!??
-- In this example, the only way this can occur is if the user manually closes the dialog
-- by hitting the nice big red "x"
)
Okay, I've not tested any of this, but try JUST this code and see where it gets you BEFORE incorprating it into the rest of the script...

JeremyJessup
01-03-2008, 10:17 PM
alright, the code you put up does display a list of the active layers, but does not seem to dismiss the dialog for some reason (I looked up the destroyDialog topic in the help file and it looks like what you have there should have worked... so I'm scratching my head a bit there).

I tried adding in my code a piece at a time, and it seems like when I get the dialog, I make a selection, the dialog stays up and nothing else changes. I'm supposing that if the dialog can be sucessfully dismissed, it will complete the process and populate the layer selection with the selected objects (I hope).

Presumably, once I have that working could I add an 'else' clause that would give the option of adding a new layer? That may be too much, so if it is I'll be happy with what I've got.

RustyKnight
01-03-2008, 10:34 PM
alright, the code you put up does display a list of the active layers, but does not seem to dismiss the dialog for some reason (I looked up the destroyDialog topic in the help file and it looks like what you have there should have worked... so I'm scratching my head a bit there).

I tried adding in my code a piece at a time, and it seems like when I get the dialog, I make a selection, the dialog stays up and nothing else changes. I'm supposing that if the dialog can be sucessfully dismissed, it will complete the process and populate the layer selection with the selected objects (I hope).

Presumably, once I have that working could I add an 'else' clause that would give the option of adding a new layer? That may be too much, so if it is I'll be happy with what I've got.Sorry, my bad...the event handler should actually read
on Layers selected index do (

local layerName = layerList[index]
selectedLayer = (LayerManager.getLayerFromName layerName)

-- Close the dialog automatically when the user selects a new layer...
-- This may not be the best solution, but it will do for the momement
-- and demonstrates how to dismiss a dialog
DestroyDialog DestLayer

)That'll teach me not to test my code...

And yes, if the user does not select a layer and dismisses the dialog, you could create another one asking for the new layer...or you could supply a textfield to collect the new name and use a button to dismiss the dialog...

I tend to like getting as few dialogs as possible...but that's cause I'm lazy...

Shane

JeremyJessup
01-03-2008, 10:58 PM
I think I'll curl up into a ball then sit in the corner and cry for a few hours when this is all said and done.... and have MaxScript nightmares for the next few years.

It seems like every time I get a piece of code to work, there's another bit that is blowing up on me, and I'm so new to this stuff that I'm sure I'm just missing some really basic steps along the way.
___________________________
Edited -
Here's what I've got...

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 DestinationLayer "Layers"
(
dropdownlist Layers "Select Layer" items:layerList
on Layers selected index do
(
local layerName = layerList[index]
selectedLayer = (LayerManager.getLayerFromName layerName)
)
)
)
createDialog DestinationLayer width:100 heigh:100 model:true;


--if (selectedLayer != undefined) then (for node in selection do (selectedLayer.addNode node))
--DestroyDialog DestinationLayer

--actionMan.executeAction 0 "40143"


This shows everything open and has a list of layers to select from. That means that whay I've messed up is the last part of the code here, right? What do I need in order to accept the selection from the user, close the dialog, and close the group?

RustyKnight
01-04-2008, 12:19 AM
Okay...a couple of quick things...

(
rollout DestinationLayer "Layers"
(
dropdownlist Layers "Select Layer" items:layerList
on Layers selected index do
(
local layerName = layerList[index]
selectedLayer = (LayerManager.getLayerFromName layerName)
)
)
)
)This isn't going to work the way you appear to think it will...

The rollout clause is a "defination", not a "script" per say (for the moment, you don't need to understand)...You've also enclosed it within in it's own context, which hides it from the rest of the script...not what you want...


createDialog DestinationLayer width:100 heigh:100 model:true;This is wrong, sorry, my bad, it's modal not model...

I still don't understand why you feel the need to open the groups...I can do it without the need to.

If, however, you feel that you have to, collect the group head's into an array and close them at the end of the script, don't use the action manager, it is contextual...

This is the script I've been able to come up with. It works quite well on the sample scene you provided...try it as it stands....

-- Used to specify the layer of choice...
selectedLayer = undefined

-- Define the rollout for later use...it's a special kind of function...but not a function...
rollout DestLayer "Layers"
(
dropdownlist Layers "Select Layer" items:layerList
on Layers selected index do (
local layerName = layerList[index]
selectedLayer = (LayerManager.getLayerFromName layerName)
DestroyDialog DestLayer
)
)

-- Get a list of all the layers
layerList = #()
if (LayerManager.count > 0) then (
for i = 0 to LayerManager.count - 1 do (
append layerList (LayerManager.getLayer i).name
)
)

-- Create our modal dialog
createDialog DestLayer width:100 heigh:100 modal:true

-- If the user selected a layer, then move the objects
if (selectedLayer != undefined) then

--Then comes the part of the script I expected to have move my objects to the chosen layer
(for node in selection do (selectedLayer.addNode node)


) else (
--not sure what to put here
-- Print nasty messages about the user...;)
-- The user has failed to select a layer...do what ever you think you need to do...
)
Shane

JeremyJessup
01-04-2008, 04:56 PM
Excellent, it works! I had to swap two chunks of the code around (it gave a compile error if I didn't define what the 'layerlist' was before doing the rollout), but it works great otherwise.

It may work differently if it's processed in MaxScript rather than straight through Max itself (and not consistantly either), but we frequently find that when you try to assign a grouped selection with nested groups to a new layer, only portions of the selection will transfer to the new layer... some items stay put for some reason (hence the need to first open the groups). If the way things are processed when running that command as a script works differently, I'm all for it. I've got some more files to test it on first.

RustyKnight
01-04-2008, 10:01 PM
Excellent, it works! I had to swap two chunks of the code around (it gave a compile error if I didn't define what the 'layerlist' was before doing the rollout), but it works great otherwise.
Yep, should have seen that - must have still had layerlist defined in my global context when I was finalising the script...I ususally work with a local context for this reason, but seen as you figured it out, that's all the matters

It may work differently if it's processed in MaxScript rather than straight through Max itself (and not consistantly either), but we frequently find that when you try to assign a grouped selection with nested groups to a new layer, only portions of the selection will transfer to the new layer... some items stay put for some reason (hence the need to first open the groups). If the way things are processed when running that command as a script works differently, I'm all for it. I've got some more files to test it on first.I think I might have to do with the way max treats it's layers. In maxscript, you can access ALL the objects in the group without doing anything special, but the UI tends to treat or differently...so long as it works...

Shane

CGTalk Moderation
01-04-2008, 10:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.