[Closed] saveNodes and layers
Hey everyone, I have a problem and would appreciate some thoughts on how I might approach it
I want to save selected objects to their own max file but without the layer information I have in my current scene. I would also like to leave my current scene untouched.
What would you say is the best way to go about it? I can think of a few of solutions, none of which seem that great.
Option A
- save max file (or “Hold”)
- move all objects to layer 0 (default)
- delete empty layers
- save selected (saveNodes)
- reopen max file (or “Fetch”)
Pros: I leave my scene untouched
Cons: Very slow if my scene is big, and if I’m not using hold/fetch I lose my undo history (might not be that important but it is a side effect that could impact workflow)
Option B
- gather all properties of my layers (could be a lot – objs, name, frozen/hidden, general layer properties) and store them
- move all objects to layer 0 (default)
- delete empty layers
- recreate all layers and move all objects back
Pros: Should be a lot faster than saving and reopening a big scene
Cons: There could be quite a lot of layer properties to save
Option C
- save selected objects
- save the current scene
- open the file created by “save selected”
- move all objects to layer 0 (default)
- delete empty layers
- save
- reopen original scene
Pros: Similar to option A, fairly simple process
Cons: Even slower than option A because I am opening/reopening two files. I also lose my undo history
Can anyone think of a good solution to what should be a fairly simple job?
Thanks,
Ian
edit: Thought of another option:
Option D
- move selected objects to layer 0 (default)
- delete all unselected objects
- delete empty layers
- “save copy as…” to save entire scene to a separate file
- undo (using “max undo”) deleting layers, objects and the moving of selected objects
Pros: fairly simple
Cons: It could take a while to undo deletion of almost the entire scene? But hopefully take less time than doing a fetch or reopening entire file?
-- make a scene
(
resetmaxfile #noPrompt
b = layermanager.newLayerFromName "boxes"
for k=1 to 10 do b.addnode (box())
b.wireColor = red
s = layermanager.newLayerFromName "spheres"
for k=1 to 10 do s.addnode (sphere())
s.wireColor = green
s.current = on
)
fn work = -- save some nodes
(
savenodes $sphere* (getdir #temp + @"\spheres.max") quiet:on
savenodes $box* (getdir #temp + @"\boxes.max") quiet:on
)
fn tempUnderLayerWorks work: =
(
nodes = #()
current = LayerManager.current.name
-- open undo chunk
theHold.Begin()
(b = LayerManager.getLayer 0).current = on
for k = LayerManager.count-1 to 1 by -1 do
(
l = LayerManager.getLayer k
l.nodes &nodes
for n in nodes do b.addnode n
LayerManager.deleteLayerByName l.name
)
if work != unsupplied do work()
-- cancel undo chunk
if theHold.Holding() do
(
theHold.Restore()
theHold.Cancel()
)
(LayerManager.getLayerFromName current).current = on
)
/*
tempUnderLayerWorks work:work
*/
Thanks Denis – I think I should have read up on thehold a bit more.
I kind of assumed that it stores a snapshot of everything so I thought it would take a while to hold and “fetch”. But it looks like it just stores differences from that point on, right? Like the undo system. So restoring shouldn’t be that time consuming.
Thanks for your input and sample code, much appreciated