Also I noticed that "performing arithmetic" message from time to time, not only when first open but when I play the file. Consider that the script is storing a Z value on an object that is own by the Moho object. If for some reason meanwhile the sort operation (four nested for---end loops) the shapes list should be reloaded from the cache or from the file I believe that the Z value is lost and then the layer script is making a mathematical operation with a Z value that has a nil value (not valid). It is simply solved once the script is run again. The reason for that is the lack of performance of the script. It still being a mistery to me but the layer script is called three times in the same frame. It causes a lot of performance loose.
Regarding to new ideas:
-Oh! if we could make masking operations between shapes!
-Oh! if we could make blending operations between shapes!

I have other script that uses the 3D rig to move in a 3D environment not the points but the Vector layers that are bound to it. I think it can be modified to work in this way:
Current shape sort is performed based on the average of the Z depth of the each point bone. As well as each point in a shape has a single bone parent and the bone has a Z depth value (calculated, not real), you can calculate the average Z of the shape based in the points the shape holds and its corresponding Z's.
A point is shared by different shapes based on the welding operation. So moving a point (in 3D) makes sure that all the shapes that are asociated to that point moved with it.
What I suggest is to separate each shape (when needed) in individual vector layers. Two points in two different Vector layers cannot be welded but can be bound to the same bone and they would follow the path. That would allow separate the shapes into vector layers.
Adventages:
You can perform masking operations.
You can perform blending operations.
Disventages:
You can loose the curvature continuity between outlines because they are in different layers.
You have to disable the 3D camera.
Possibly jump traffic of script running in som many layers...
Current script I did to perform layers sort based on z depth is only valid if you bind a layer to a single pt bone. If you want to have the average of the Z of the pt points of the layer the script must be changed.
If the layer sort based on the new recent added feature were added to the script interface I guess it can be esier to implement.
Any suggestions?
