【问题标题】:Open a file browser in a specific folder with Python使用 Python 在特定文件夹中打开文件浏览器
【发布时间】:2013-04-09 12:15:35
【问题描述】:

我是法国人,如果我的英语不是很好,请原谅。 这是我的问题:我正在使用 python 来制作一个适用于 Blender 的脚本,我需要导入一个 .obj 文件。我已经有了导入器,但我输入了整个文件路径。

看起来是这样的:

bpy.ops.import_scene.obj(filepath='C:/Users/MarcPro/Desktop/testauto/03-Reconstruction/Data/Tile/Tile.obj', axis_forward='Y', axis_up='Z')

相反,我想打开一个文件浏览器(例如 explorer.exe),搜索 .obj 文件并选择它作为 bpy.ops.import_scene.obj 导入器。

请问你有什么想法吗?

谢谢,

埃罗。

【问题讨论】:

    标签: python explorer blender file-browser


    【解决方案1】:

    在我看来,这不是一个非常适合 Blender 的方法。

    我认为您想要做的是使用内置的 Blender 文件选择对话框来选择文件。

    我不确定,但这可能适用于 bpy.types.WindowManager.fileselect_add

    【讨论】:

    • 我尝试使用 bpy.types.WindowManager.fileselect_add 但我不明白如何正确使用它。它只是打开了资源管理器。如何打开目录,选择文件并将其路径放入 filepath 变量中,然后调用 bpy.ops.import_scene.ob ?
    • 其实我想做和 Tkinter 一样的事情:显示一个“打开”对话框并返回所选文件的路径。用Tkinter很简单,但是我用blender的python试了几次,找不到方法。
    【解决方案2】:

    你可以使用 Tkinter 在 python 中选择一个文件: Choosing a file in Python with simple Dialog

    from Tkinter import Tk
    from tkFileDialog import askopenfilename
    
    Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
    filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
    print(filename)
    

    【讨论】:

    • 谢谢,但我忘了说我已经尝试使用 Tkinter,但它不再适用于 Blender 的 python 的最新版本。但我可以再试一次看看我得到了什么。
    • 其实我想做和 Tkinter 一样的事情:显示一个“打开”对话框并返回所选文件的路径。用Tkinter很简单,但是我用blender的python试了几次,找不到办法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多