0
$\begingroup$

I'm trying to find a way to bring up two file browsers (one after the other), but without success.

The reason for needing multiple file browsers is that I first need the user to export a text file, then export a mesh file. Those could have different names and be exported to different directories.

One solution I could think of is to have a separate operator that I call from the first operator, but the problem seems to be that 1. it doesn't return a value and 2. the code pause while I call the other operator.

I also tried to add multiple fileselect_add calls, but that seemed to crash blender. Any idea?

Sample code:

import bpy
from bpy_extras.io_utils import ExportHelper

class ExportCommon(bpy.types.Operator, ExportHelper):

    bl_idname = "export.common"
    bl_label = "Export common"
    bl_options = {'PRESET'}

    filename_ext = ".fbx"

    def invoke(self, context, event):       

        context.window_manager.fileselect_add(self)

        return {'RUNNING_MODAL'}

    def execute(self, context):

        print(self.filename)
        return {"FINISHED"}
$\endgroup$
3
  • $\begingroup$ How about using an operator calling two file saving operator? $\endgroup$ – HikariTW Sep 6 '20 at 9:44
  • $\begingroup$ I don't think that works as the second operator is dependent on the value of the first operator. And as I call the first operator the second operator will not wait for the result. $\endgroup$ – Simon Björk Sep 6 '20 at 12:57
  • $\begingroup$ If you want to keep the result from the first operator, register a new properties group to scene and use that properties to save your result. Or you can also save at module namespace(maybe a good idea). $\endgroup$ – HikariTW Sep 6 '20 at 13:09
0
$\begingroup$

If I understand your question clearly, you want to proceed with the first modal result and run the second operator right?

Instead of calling two modal operator, you should call the second one in the first operator "execute" function. In that block, the modal part is done and can call another modal operator.

A simple snippet that run two file select window in a sequence:

import bpy
from bpy_extras.io_utils import ExportHelper

class ExportCommon(bpy.types.Operator, ExportHelper):

    bl_idname = "export.common"
    bl_label = "Export common"
    filename: bpy.props.StringProperty()
    filename_ext = ".fbx"

    def invoke(self, context, event):  
        context.window_manager.fileselect_add(self)
        return {'RUNNING_MODAL'}

    def execute(self, context):
        print(self.filename)
        bpy.ops.wm.save_as_mainfile('INVOKE_DEFAULT', copy=True)
        return {"FINISHED"}

bpy.utils.register_class(ExportCommon)

bpy.ops.export.common('INVOKE_DEFAULT')
$\endgroup$
1
  • 1
    $\begingroup$ Yes, this seems to work well! I need to organize my code a bit differently, but it should be doable. Thanks a lot! $\endgroup$ – Simon Björk Sep 8 '20 at 9:04

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.