Scripted objects migration

Introduction
Scripted objects are rebuilt every time a FCStd document is opened. To do this the document keeps a reference to the module and Python class that were used to create the object, along with the properties and values of that object.

Particularly focus on this part:

If the module or class is no longer present, the object will fail to load correctly. This means that once an object is created using a particular class, the module should no longer be moved or renamed because if this is done, previously saved objects will break.

However, a valid reason for moving or renaming the class is to improve the structure and maintainability of the original code, for example, when restructuring an entire workbench. In this case there are various strategies to migrate old objects to using a new class. This is done in order to retain backwards compatibility, when outright breaking of old documents must be avoided.

Old object and new object
An old object is defined in a module which is at the root of the workbench.

An old object was previously created and saved in.

Now we consider that the workbench is restructured, so that classes aren't just at the root directory, but instead are inside an directory. This is a way to organize the different files of a complex workbench, including objects, viewproviders, Gui Commands, task panel interfaces, etc.

This new module has the same type of object but both the module and class have changed. The properties also have changed; one was renamed, and a new property has been added.

Migration by redirecting the class
In the older module the original class needs to be redirected to point to the new class.

This old module no longer contains the definition of the class; now it just points to the new class, so that any older document that tries to load will be immediately redirected to the new object.

Migration when restoring the document
In the older module the original class just contains a method to migrate the object.

The method, if implemented, will run when the document tries to restore an object that uses the  class.

Links

 * Migrating and upgrading old scripted objects