0
$\begingroup$

I'm trying to load scene properties from a given blend file into the current one using bpy.data.libraries.load()

import bpy

with bpy.data.libraries.load(blend_path, link=False) as (data_from, data_to):
    print("Scenes available in the file:", data_from.scenes)
    if data_from.scenes: scene_name = data_from.scenes[0]; data_to.scenes = [scene_name]
    else: print("No scenes available in given file.")
        
    if data_to.scenes and data_to.scenes[0]:
        bpy.context.scene["prop1"] = data_to.scenes[0].get("prop1")
        if not bpy.context.scene["prop1"]: print("error no prop1 found in target scene")
    else: print(f"Scene '{scene_name}' could not be loaded.")

It's working but unfortunately it loads all of the objects and associate data items (materials etc.) into the current blend also.

Is there a way I can get scene properties without loading the contents of the scene? It seems messy to do something like:

for obj in loaded_scene:
    for material in obj.material_slots:
        for image in material: D.images.remove(image)
        D.materials.remove(material)
    D.meshes.remove(obj.data)
    D.objects.remove(obj)

(and any other types which may have been wrongly append which may be missed (lights, cameras, node groups etc.)

$\endgroup$

1 Answer 1

0
$\begingroup$

Go to File>Append then select the file you want the properties from.

If appending the entire scene isn't appending missed objects such as lights or cameras, you can choose the camera/light folder in the append screen to specifically append the camera/light.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .