Just wanted to know if there’s any tips for managing this, specifically:
How to control a growing number of properties being read/written? We have been serialising classes to JSON and writing as string, is there any reason not to do this? (over read/writing each field?)
Clever tips for to manage versioning? At the moment we keep adding more if statements as we increment minor version numbers.
Approach to gracefully upgrading 3dm files created from previous plugin versions? We have some methods that checks major minor versions and does stuff, but I can see it getting unwieldy…
I wouldn’t worry about growing JSON strings, unless you’re writing hundreds of megabytes of data. If you do, I have a few tips, so let me know if that is the case.
You’re using versioning: that is great! Keep doing that. You want to be prepared for backward compatibility, so if a newer version of your plug-in loads an older file, the user is upgraded gracefully. I remember, like you, having a large number of if-statements to support older versions. You may decide at some point to break your backward compatibility, but that will affect your users so be careful.
Once a user loads an older file in a newer plug-in version, make sure that your in-memory data model is always up to date with the latest version of your plug-in. This means that once they save the file, the information is up-to-date automatically.
It sounds like you’re doing everything right, and having backward compatibility can be non-trivial to support.
But thanks @menno for your reply! It’s reassuring, even if its just “keep calm and carry on” – breaking backwards compatibility may actually be beneficial in the short term as we iterate quickly. At the moment its relatively easy for users to recreate models from scratch with new versions of the plugin, rather than having to write a bunch of code to maintain compatibility…
Use the Write3dmChunkVersion - it’s takes up less space and you don’t need to call EndWrite3dmChunk. When reading, use Read3dmChunkVersion. It is best to write/read this as the first entry, and when reading decide based on the version what else you need to read.
(this is from one of the C++ examples SampleSharedUserData.cpp, but assume it can be used similarly in C#). The reason I ask is if there’s any benefit from doing something like this? i.e:
public enum MyPluginChunkType : uint
{
DesignData = 1,
ProjectData = 2
}
if (archive.BeginWrite3dmChunk((uint)MyPluginChunkType.DesignData, 1, 0))
{
// Write design data
archive.EndWrite3dmChunk();
}
It would allow you to structure your information a bit more in the 3dm file.
Personally, I have never had the need to do this, but I can see the benefit in structuring things, for example if you have various classes with plug-in settings or something like that.