8
$\begingroup$

I'm writing a python script wich is going to import custom data in custom file. For now, for choosing the file I've to do this:

ui old

But it's not very useful because you have to type the path of file by yourself.

I want to create somthing like this :

ui new

How to create quick interface like that. With a file browser button and the path of selected file edit box is linked at the path of file wich you have selected with the little 'file' button.

I'm not asking for a full code. (of course if you have a full code I'll accept it :D) But if you have just an explanation of how to do this and how the 'path of file' button work, it will be very helpfull.

$\endgroup$

1 Answer 1

13
$\begingroup$

Add a StringProperty to your operator, then set its subtype to either FILE_PATH or DIR_PATH. For example, this bit of code in my addon:

class OHA_QuickLink_Props(bpy.types.PropertyGroup):
    root_folder = StringProperty(
        name="Root Folder",
        description="Only .blend files two levels below this folder will be listed.",
        subtype="DIR_PATH",
        update=update_oha_quicklink_root_folder)

Blender 2.8x:

class OHA_QuickLink_Props(bpy.types.PropertyGroup):
    root_folder : StringProperty(
        name="Root Folder",
        description="Only .blend files two levels below this folder will be listed.",
        subtype="DIR_PATH",
        update=update_oha_quicklink_root_folder)

yields the following text field when drawn:

1a

$\endgroup$
2
  • $\begingroup$ Wow... it was as simple as that. Thank you!! $\endgroup$ Commented Dec 12, 2013 at 10:14
  • $\begingroup$ the official documentation was too confusing. thx for giving a short and clear example! $\endgroup$ Commented Dec 2, 2014 at 15:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.