[英]Open a file browser in a specific folder with Python
I'm a french guy, so excuse me if my English is not very good. 我是法国人,如果我的英语不太好,请原谅。 Here is my problem : I'm using python to make a script that works with Blender, and I need to import an .obj file.
这是我的问题:我正在使用python制作与Blender一起使用的脚本,并且需要导入.obj文件。 I already have the importer, but I enter the entire filepath.
我已经有了导入器,但是我输入了整个文件路径。
It's look like that : 看起来像这样:
bpy.ops.import_scene.obj(filepath='C:/Users/MarcPro/Desktop/testauto/03-Reconstruction/Data/Tile/Tile.obj', axis_forward='Y', axis_up='Z')
Instead, I would like to open a file browser (for example explorer.exe ), go search for the .obj file and select it for bpy.ops.import_scene.obj importer. 相反,我想打开一个文件浏览器(例如explorer.exe ),搜索.obj文件并为bpy.ops.import_scene.obj导入器选择它。
Do you have any idea please ? 你有什么主意吗?
Thanks, 谢谢,
Ero. ro
That's not a very Blender-friendly approach, in my opinion. 我认为,这不是非常适合Blender的方法。
I think what you want to do is use the built-in Blender file selection dialog to pick the file. 我认为您要做的是使用内置的Blender文件选择对话框来选择文件。
I'm not sure, but this might be something for bpy.types.WindowManager.fileselect_add
. 我不确定,但这可能是
bpy.types.WindowManager.fileselect_add
东西。
You can choose a file in python using Tkinter: Choosing a file in Python with simple Dialog 您可以使用Tkinter在python中选择文件 : 使用简单对话框在Python中选择文件
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.