Via the link or append operator
Test script, template file as a scene property in way of example, possibly better set as an addon preference.
import bpy
from bpy.props import StringProperty
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
col = layout.column()
col.prop(scene, "template_file")
# check if fp exists
col.operator_context = 'INVOKE_DEFAULT'
if True:
# write an op to
directory = "%s/Group/" % (scene.template_file)
op = col.operator("wm.append")
op.directory = directory
op.instance_groups = True
def register():
bpy.types.Scene.template_file = StringProperty(
subtype='FILE_PATH')
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
# del prop
if __name__ == "__main__":
register()
Alternatively A file test.blend
that has 5 groups in it.
>>> fp = "/home/batfinger/Desktop/test.blend"
>>> with bpy.data.libraries.load(fp) as (data_in, data_out):
... pass
...
>>> data_in.groups
['Group.004', 'Group.003', 'Group.002', 'Group.001', 'Group']
a group name above can be passed as filename
argument to operator as show in
Appending an Object Without A Link
Links re linking appending from files.
How to Link/Append a data-block using the Python API?
Import group from external blend file
How to search through multiple Blender files to find a specific object?