0

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]
            else:
                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")
        file.write(result)
        file.close()
        return {'FINISHED'}

Kr3o
  • 91
  • 8
  • Hello, could you post a snippet of your current code so we can start from it ? – Gorgious Jan 10 '22 at 10:02
  • @Gorgious I edited my question and added the code :) – Kr3o Jan 10 '22 at 10:06
  • could not find an exact duplicate but basically you need to modify your operator to inherit from ExportHelper and use an invoke method. See https://blender.stackexchange.com/questions/30678/bpy-file-browser-get-selected-file-names https://blender.stackexchange.com/questions/198831/right-way-to-stop-export-operator-from-saving-with-empty-filename/198924 https://blender.stackexchange.com/questions/79373/set-custom-location-for-import-export-helper – Gorgious Jan 10 '22 at 10:26
  • 1
    You should find a pretty solid example in the text editor by going Templates > Python > Operator file export – Gorgious Jan 10 '22 at 10:27
  • 1
    BTW when you have a context passed as parameter in a method, you should use that one instead of bpy.context – Gorgious Jan 10 '22 at 10:28
  • Hey thanks for the quick help, definitely gonna check out the links and the template. – Kr3o Jan 10 '22 at 10:30

0 Answers0