Write array to file

Is there any way to write a two-dimensional array to a file, maintaining all its intndernal structure and content (in this case, a series of structs)?

I have a script that handles a 2-d array of structs, each of which contains quite a bit of information inclus ding references to scene geometry. It is not practical to convert all this to strings in order to save it as a text file.

Is there some way using Maxscript to save the entire array as a file, and then read it in recreating the entire array? Maybe even with the geometry?

Comments

Comment viewing options

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

Hi there, you can provide a

Hi there, you can provide a function inside your structure to output data from something like this

struct SomeStruct (

field1, field2, field3,   --some data fields

fn A = (...),               --some functions

...

--Here is the output  function call this with a valid file handle

fn fnOutput stream = (

   format "% % %" field1 field2 field3 to:stream

)

)

then simply run a loop calling this output function on all structures 

This would work if you do not have references to scene geometry. I would suggest that you store geometry indices within structure and save the actual geometry seperately in the file like this

--Start of ur file

--Your geometry descriptions here

--All structures here

--End of file

Hope this helps

take care

Mobeen

Proud to be a PAKISTANI.

signal's picture

Thanks for your prompt and

Thanks for your prompt and thorough reply.

One question, you say "I would suggest that you store geometry indices within structure and save the actual geometry seperately in the file like this". Do you mean to save the geometry as a 3ds or Max file?

 Thanks again,

signal 

 

mobeen's picture

BY this I mean that u store

BY this I mean that u store the geometry info (the vertex , face indices and uv coords) of all objects in the output file first. then when you refer to the geometry simple pass in the index.Let me elaborate with a diagram

---------------------------start of file

vertex info of object 1

face info of object 1

uv info of object 1

-------------------------

...

...

...

-------------------------- 

vertex info of object n

face info of object n

uv info of object  n

 ---------------------------- start of structure output here

...

 ---------------------------- end of structure output

------------------------------end of file 

Hope its clear now

Regards

Mobeen 

Proud to be a PAKISTANI.

Comment viewing options

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