1
$\begingroup$

I'm looking for a way to either use the system file explorer for importing and exporting in Blender or display custom icons in Blender's file browser.

I've tried using Python scripts to call system commands like os.startfile() and subprocess.Popen(['explorer', filepath]), but unfortunately, I haven't been successful in getting them to work.

What is the best practice for opening the system file explorer or displaying custom icons in Blender's file browser?

Is there a specific method or API that I should be using for this purpose?

Written by ChatGPT

enter image description here enter image description here enter image description here enter image description here

$\endgroup$
4
  • $\begingroup$ I have one script that uses os.startfile() successfully. Are you trying to call it from a script by itself or is the os.startfile call wrapped in a Blender operator? I would try putting it into an operator and see if that works. Blender might have some kind of built-in security function that prevents it from calling raw Python scripts that interact with the operating system, but I'm not positive this is the case. $\endgroup$
    – Jakemoyo
    Commented May 16 at 18:23
  • $\begingroup$ chatgpt.com/share/85dd7ca9-3bb1-4cf6-bf26-b64b02af4205 $\endgroup$ Commented May 17 at 4:25
  • $\begingroup$ "According to GPT, is this the only way to do it?" $\endgroup$ Commented May 17 at 4:28
  • $\begingroup$ "This is because it requires changes to the core functionality of Blender, and such changes can only be achieved by modifying the source code. Other methods, such as plugins or scripts, may not be able to completely replace Blender's built-in file browser. This is because these methods simply add a layer of wrapping on top of Blender's functionality and cannot alter the internal behavior of Blender's file browser." $\endgroup$ Commented May 17 at 4:30

2 Answers 2

1
$\begingroup$

The following code opens the windows explorer on windows.

import subprocess

filepath = "D:\\your_path_here\\"
args = ['explorer', filepath]
subprocess.Popen(args)
$\endgroup$
6
  • $\begingroup$ Can't post line breaks in code as a comment, so this had to be an answer. $\endgroup$
    – Leander
    Commented May 17 at 6:56
  • $\begingroup$ Yes, I can open the system file browser in Blender using code, but I want to go further. I want to completely replace Blender's built-in file browser with the system file browser for import/export within Blender, just like how it works in software such as Photoshop, PowerPoint, and Edge. $\endgroup$ Commented May 18 at 6:54
  • $\begingroup$ blenderartists.org/t/regular-windows-file-browser/679015 $\endgroup$ Commented May 18 at 6:55
  • $\begingroup$ Alternatively, I'd like to see custom icons for my folders in Blender's built-in file browser. You can see my custom icons in the images I've shown. If I could see custom icons, it would make finding files much more convenient for me. $\endgroup$ Commented May 18 at 6:57
  • $\begingroup$ docs.blender.org/manual/en/latest/files/blend/previews.html $\endgroup$ Commented May 18 at 6:58
1
$\begingroup$

This operator in a script I wrote has this exact functionality.

import bpy
import os


class op(bpy.types.Operator):
    bl_idname = "custom_fbx_export.file_open_folder"
    bl_label = "Open Folder"
    bl_description = "Open the specified folder"

    @classmethod
    def poll(cls, context):
        if context.scene.custom_fbx_export_props.path == "":
            return False

        return True

    def execute(self, context):
        open_folder(self, context.scene.custom_fbx_export_props.path)
        return {"FINISHED"}


def open_folder(self, path):
    path = os.path.dirname(bpy.path.abspath(path))
    # Warnings
    if not os.path.exists(path):
        self.report({"ERROR_INVALID_INPUT"}, "Path doesn't exist.")
        return

    # Open Folder
    os.startfile(path)
    print("Open path on system " + path)

When you click the button this operator is assigned to, it will open the default Windows file browser.

$\endgroup$
4
  • $\begingroup$ Yes, I can open the system file browser in Blender using code, but I want to go further. I want to completely replace Blender's built-in file browser with the system file browser for import/export within Blender, just like how it works in software such as Photoshop, PowerPoint, and Edge. $\endgroup$ Commented May 18 at 6:52
  • $\begingroup$ blenderartists.org/t/regular-windows-file-browser/679015 $\endgroup$ Commented May 18 at 6:53
  • $\begingroup$ Alternatively, I'd like to see custom icons for my folders in Blender's built-in file browser. You can see my custom icons in the images I've shown. If I could see custom icons, it would make finding files much more convenient for me. $\endgroup$ Commented May 18 at 6:57
  • $\begingroup$ docs.blender.org/manual/en/latest/files/blend/previews.html $\endgroup$ Commented May 18 at 6:58

You must log in to answer this question.

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