5
$\begingroup$

I'm trying to figure out how to create a new scene which is a "linked copy" from Python without relying on context/ops.

The ops version would involve setting the type to LINK_COPY e.g.:

bpy.ops.scene.new(type='LINK_COPY')

The non-ops interface bpy.data.scenes.new only offers to pass in the name of the new scene (see API docs of BlendDataScenes).

How can I turn a scene created by bpy.data.scenes.new into a linked copy?

$\endgroup$
3
$\begingroup$

As far as I can tell, bpy.data.scenes['your_scene'].copy() will give the exact same result as bpy.ops.scene.new(type='LINK_COPY') except for one detail: the new scene has 0 user and gets added to the orphan data. This is not an intended feature and there's no python command to properly fix that. However, there's no need to worry, as the scene will actually not get deleted if you save and revert the file, contrary to any other orphan data.

Still, if it's uncomfortable for you, it's possible to give the scene 1 user by doing any of these:

  • adding a fake user: bpy.data.scenes['your_scene'].use_fake_user = True

or

  • saving and reloading the file

or

  • performing any operation and undoing it with Ctrl+Z (currently, the undo operator reloads many components of the file so I guess it works for the same reason reloading the file works too)

Side note:

You can also do the equivalent of bpy.ops.scene.new(type='EMPTY') (called "Copy Settings" in the interface) this way:

Sc = bpy.data.scenes['your_scene'].copy()
for col in Sc.collection.children:
    NewSc.collection.children.unlink(col)
for obj in Sc.collection.objects:
    NewSc.collection.objects.unlink(obj)
$\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.