0
$\begingroup$

I'm writing a script to animate tex characters morphing from one character to another. To make it look smooth, I want to sort the splines in the spline collection within curve data. I'm running into trouble because bpy_struct (the parent class of spline) is read-only, and the copy methods also don't work on bpy_struct.

A test case that shows the error I get:

import bpy
from copy import deepcopy

obj = bpy.context.object

copied_obj = deepcopy(obj)

The error is bpy_struct.__new__(type): expected a single argument.

If this can't be done easily, it would also help me if there were a way to use list methods on bpy_prop_collection instances, specifically sorting.

My plan right now is to create my own classes that mimic the classes I want to sort/copy, then deal directly with the basic data types. But I would... prefer not to do that if possible.

$\endgroup$
1
$\begingroup$

Deepcopy is not supported as the Blender objects are optimized for performance. Most objects have the option, to create a copy by using .copy method

obj = bpy.context.object
copied_obj = obj.copy()

Please note that .copy will also create a new object in the scene (same as duplicate). Making a fully detached copy of an object, you need to do yourself. as you will by then make a local copy of everything in the python interpreter.

In these cases it is best to do it manual and only select the data you need so the performance can be controlled better.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.