0

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. 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.

Do you have any idea please ?

Thanks,

Ero.

izidor
  • 4,068
  • 5
  • 33
  • 43
Ero
  • 1
  • 1
  • 1

2 Answers2

0

That's not a very Blender-friendly approach, in my opinion.

I think what you want to do is use the built-in Blender file selection dialog to pick the file.

I'm not sure, but this might be something for bpy.types.WindowManager.fileselect_add.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • I tried use bpy.types.WindowManager.fileselect_add but I don't understand how to correctly use it. It just opened the explorer. How can I open a directory, select the file and put its path into the filepath variable and then call bpy.ops.import_scene.ob ? – Ero Apr 09 '13 at 13:41
  • Actually I want to do the same thing that Tkinter does : show an "Open" dialog box and return the path to the selected file. Very simple with Tkinter, but I tried several with blender's python, I can't find the way to do it. – Ero Apr 09 '13 at 13:56
-3

You can choose a file in python using Tkinter: 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)
Community
  • 1
  • 1
MaPePeR
  • 931
  • 9
  • 18
  • 1
    Thanks, but I forgot to say that I already try to use Tkinter, but it's not working anymore on the lastest versions of Blender's python. But I can try it again to see what I get. – Ero Apr 09 '13 at 12:42
  • Actually I want to do the same thing that Tkinter does : show an "Open" dialog box and return the path to the selected file. Very simple with Tkinter, but I tried several with blender's python, I can't find the way to do it. – Ero Apr 09 '13 at 13:57