[Closed] Problem when trying to save and reimport objects
Hi there…
i´m trying to write a little script to save every single object in a selection into a single max-file and import it as XRef-Scene again.
Doesn´t sound too hard and i came up with this rather quick:
for s in selection do
(
selName = s.name
saveNodes s ((GetDir #scene) + "\\" +selName)
delete s
xrefs.addNewXRefFile ((GetDir #scene) + "\\" +selName + ".max") #noLoad
)
The problem is, that this script seems to forget a few objects in the selection. My guess would be, that it takes too long to save a file to disk, which then stalls the write-buffer. So MXS is faster with traversing through the selection then with writing it to disk.
Is that really the problem? Is there a way to solve that?
The later plan is to save very complex models to single max-files that will have a filesize of about 50 – 100 MB each. So saving them will take quite some time. Not to mention loading them in as XRef again.
I hoped for max being as intelligent enough to wait until one save- or load-operation is finished before executing a new line in the script.
So…i hope that someone can guide me here…Thanks
the answer is NO, IMHO. It’s not technically possible to be save/load unsynced. That might be an another reason to not save some nodes. Does the max save those ignored nodes? Can you do it manually?
I’ve ran into issues somewhat similar to this… although it was a counter issue and not saving of a file. My counter would be going along just fine, then randomly skip a beat, and move from something like 22 to 24. But it would still save the file correctly, just name it 24 instead of 23.
My guess was also that it was going too fast and just couldn’t keep up, but that seems odd. But I found a work around.
But it is odd that it would miss some objects and not save them…
Edit:
What you probably should try and do is… save the files. Then once they are all saved, do another loop and add them back in. It might be that it’s having a hard time saving/deleting/loading stuff in that fast? Although Dennis would know alot better than me…
Thanks for the replies.
Saving them in one loop and loading them in another also doesn´t help.
The funny thing is…that when i select all nodes (geometry, lights, helper) and run the script…it forgets around 2-4 Objects out of 11-12…but they stay selected. So…when i run it again, it saves and loads the rest…most of the time. Sometimes there are still 1 or 2 nodes left.
The objects i am talking about right now are simple cubes, spheres, point helper. Done nothing to them except creating them from the command pannel.
I can save all of them manually
EDIT:
Got it now. The problem was the selection. I used the scene-collection “selection” and that seems to loose some things while saving and loading and deleting all together.
I simply copied that selection into an array and made it a non-live-collection that way. Now everything seems to work like i´m expecting it to.
Very cool you got it fixed… That’s very odd… I’ll have to keep that in mind though from now on.
Edit: Unless it was from deleting objects that were in that Selection array… but max should pick up on that/ shouldn’t matter.
I you are deleting objects from an array that array shrinks, that’s what the odd behaviour is.
You can also itterate backwards over an array like:
sel = selection as array
for i = sel.count to 1 by -1 do
(
delete sel[i]
)
This will make sure the array shrinks the right way, from back to front, no possible way to skip an entry.
-Johan