I want to export a list with all my objects in my scene, but it always outputs to the default folder. I already have a little UI and when I press the button it should open the file browser and I want to set the specific path. enter image description here

Is there a way to it?

Here is the operator it should work in

 #Operator Export
    class RGL_OT_export(bpy.types.Operator):
        bl_idname = "object.export"
        bl_label = "Regalplannung"
        bl_description = "Exportier Bestückung"
        def execute(self, context):     
            selection = bpy.context.selected_objects
            result = ""
            for sel in selection:
                bpy.context.object.modifiers["Vollständig gefüllt"].show_viewport = False
                parent = sel.parent
                parent_0 = parent.dimensions [0]
                parent_1 = parent.dimensions [1]
                parent_2 = parent.dimensions [2]
                x = (sel.name.split("_")[0])
                y = (sel.name.split("_")[1])
                z = (sel.name.split("_")[2])
                h = (sel.name.split("_")[3])
                if parent_0 < parent_1:
                    dims = parent.dimensions [0] / sel.dimensions [0]
                    dims = parent.dimensions [1] / sel.dimensions [1]
            result += "%s - %s - %s - %s - %f\n" % (x, y, z, h, dims)
            tempFolder = os.path.abspath (bpy.context.scene.render.filepath)
            filename = os.path.join (tempFolder, "newfile.txt")
            os.makedirs(os.path.dirname(filename), exist_ok=True)
            file = open(filename, "w")
            return {'FINISHED'}
  • $\begingroup$ Hello, could you post a snippet of your current code so we can start from it ? $\endgroup$
    – Gorgious
    Jan 10 at 10:02
  • $\begingroup$ @Gorgious I edited my question and added the code :) $\endgroup$
    – Kr3o
    Jan 10 at 10:06
  • $\begingroup$ could not find an exact duplicate but basically you need to modify your operator to inherit from ExportHelper and use an invoke method. See blender.stackexchange.com/questions/30678/… blender.stackexchange.com/questions/198831/… blender.stackexchange.com/questions/79373/… $\endgroup$
    – Gorgious
    Jan 10 at 10:26
  • 1
    $\begingroup$ You should find a pretty solid example in the text editor by going Templates > Python > Operator file export $\endgroup$
    – Gorgious
    Jan 10 at 10:27
  • 1
    $\begingroup$ BTW when you have a context passed as parameter in a method, you should use that one instead of bpy.context $\endgroup$
    – Gorgious
    Jan 10 at 10:28


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.