6
$\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$
11
$\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$
  • $\begingroup$ Wow... it was as simple as that. Thank you!! $\endgroup$ – lucblender Dec 12 '13 at 10:14
  • $\begingroup$ the official documentation was too confusing. thx for giving a short and clear example! $\endgroup$ – Val Dec 2 '14 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.