I want to import multiple objects from another .blend file using a python script. What is the best way to do this without having to import every single object?
Example of what i want to import:
import bpy filepath = "//link_library.blend" # append all objects starting with 'house' with bpy.data.libraries.load(filepath) as (data_from, data_to): data_to.objects = [name for name in data_from.objects if name.startswith("house")] # link them to scene scene = bpy.context.scene for obj in data_to.objects: if obj is not None: scene.objects.link(obj)
You need to use append and choose which object you want to import and which type this object is.
Some of the different types are shown below:
Once you know that then you can use the below python script which is found here to import the object you want from another .blend file
blendfile = 'D:/path_to_blend_file/source.blend' section = '\\Object\\' objects = ['myobj1','myobj2','myobj3','myobj4','myobj5'] ###<-- Add the name of objects you want to append directory = blendfile + section for obj in objects: filename = obj bpy.ops.wm.append(filename=filename, directory=directory)