PDA

View Full Version : Saving data in a scene ....?


BakerCo
04-12-2007, 02:03 AM
Okay I am a bit confused I am trying to save info with a scene that will populate a rollout. It is a Macro btw. To do this do I use param blocks, globals, or what. I can't for some reason or another grasp the concept of an effcient way to do this. Basically I have a macro that creates a dialog and allows me to save sequence information and later use this to export data, however I want the data to remain in the rollout everytime I open it when I am in that scene unless I delete it. any help of course would be appreciated.

thanks

-Baker

Jon-Huhn
04-12-2007, 09:04 AM
There's others here that know alot more about this subject than me, but I'll chime in now anyway since no-one has answered yet, to at least get you going in the right direction until hopefully more knowledgeable folks give their input.

Don't mess with persistent globals... they can be hard to contain in one file and can "infect" other files with the variables during merge and xref operations. Even the Maxscript docs recommend against them.

Instead, I use Custum Attributes attached to the scene's rootNode object (or any other object if that design works better) for saving custom data with the scene. This method has it's own limitations, unfortunately. For instance, you can't save multidimensional arrays natively. However, there are a couple work arounds.

1) Save the multidimensional array as a string, and then to retrieve it again you use the Execute command to convert the string into an array again

2) If the data can't be stored as a string (for instance if you're storing references to controllers or nodes), then you can emulate mulitdimensional arrays by storing an array of modifiers or something (using #MaxObjectTab), and then attaching Custom Attributes to each of those modifiers and storing another array in each of those.

Hope this gets you started :)

arketip
04-12-2007, 09:07 AM
If I understood what you were talking about, you could use the 'Persistent Global Variables'


EDIT: Jon-Huhn> at the same time, sorry ;)

luigi
04-12-2007, 12:18 PM
persistent globals are good but got a few problem with them.the keep since you close max session, so it can keep in diferent files creating undesired result.

"If the variable being read from the scene file already exists as a persistent global variable, the value of the persistent global is not overwritten. (It was overwritten in versions prior to 3ds Max 8)"

but stil wil keep in new empty files.

I,ve been using them alot and know starting to migrate all my scripts to CA in the scene node

as in the help in persitent globals at the bottom is a link called how to do it better?.
"
Avoid using persistent global variables

A good idea gone bad.
Initially added to support scripted controllers and xrefs



Using scripted CAs for persistent data storage

Scripted Custom Attributes can be used instead of persistent global variables to store data with the scene file, avoiding the problems mentioned above.
"

JohnSwafford
04-12-2007, 01:33 PM
I'd recommend using setAppData()/getAppData() to the scene rootNode (if you're simply trying to save integers, floats, strings, etc.). As an example, saving and retrieving the float number 349.817 or true/false booleans could involve the following code:
setAppData rootNode -1000250 (349.817 as string)--Storing the number as "349.817"
((getAppData rootNode -1000250) as float)--Retrieving and converting back to float

setAppData rootNode -1000251 (false as string)--Storing the boolean as "false"
((getAppData rootNode -1000251)=="true")--Retrieving and converting back to boolean
Instead of loading these when your script loads and saving when your script closes, it is more stable to simply write to/from these AppData strings whenever these values are accessed or changed. I'm about 2 months away from finishing a large commercial script that uses AppData storage exclusively, and they've proven easy to use and completely stable.

You can also save small arrays of data by building a comma separated string, saving it with setAppData and then retrieving it via getAppData and using filterString() to convert it back to an array. You'll need to make sure you're using index numbers that don't conflict with other AppData-based scripts, but the AppData approach is VERY, VERY easy to learn compared to either Custom Attributes or Persistent Global Variables. (In my opinion, AppData is one of the best kept secrets in Maxscript.)

I've used Persistent Global Variables extensively on a large project with literally megabytes of data, but they are very difficult to completely control. You can absolutely bulletproof scripts that use them, but it takes a LOT of testing and troubleshooting. Unless you really need them for storing large amounts of data, they're not worth the trouble.

BakerCo
04-12-2007, 06:16 PM
thanks alot everyone this should get me going pretty good. being as this is a rather simplistic script idea it should not be hard to adapt all that was mentioned here thanks again and I will post up my progress later.

-Baker

CGTalk Moderation
04-12-2007, 06:16 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.