1
$\begingroup$

Is it possible in 2.79 to open the file browser to the internals of a specified blend?

I have a template.blend, that will have several Groups in it. Currently, I have a button that opens the file browser to the directory the template.blend is in.

It's 2 clicks to get to Groups, and I have to rely on the user knowing they should be looking in Group and not Objects or anywhere else.

Selecting a group then appends it to the scene.

Is it possible to open the file browser inside of the blend, so the user is only presented with Groups to append?

A view similar to:

screenshot - browse groups

Edit: Possibly related question

$\endgroup$

1 Answer 1

2
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ This was giving me the same behaviour as the other examples, File Browser just kept opening to the desktop. I assumed because '/Group/' wasn't supported. Turns out... on Windows I needed '\\Group\\' instead. I just ended up using os.path.sep, and now it should work on both OS's? It was the first link that helped with the path issue. And your example draw() is ideal. Thank you. $\endgroup$
    – dval
    Feb 25, 2019 at 14:38
  • $\begingroup$ Cheers, yep use the os path separator. Spent too much time trying to expand each group into buttons and pass the operator the filename run 'EXEC_DEFAULT' with no need to open filebrower. Couldn't get it to work. I'm sure I've seen an example on bse but couldn't find that either. $\endgroup$
    – batFINGER
    Feb 25, 2019 at 15:13

You must log in to answer this question.

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