I have some experience in programming, so I know the basics of Python in Blender. I know how to dig through the Blender Python Refernce but it is very much to look around.

I know I need to import bpy and os but I am not sure how to correctly get what I want.

I know I can create a custom Panel in whatever world or Area I need:

class panel1(bpy.types.Panel):
    bl_idname = "panel.panel1"
    bl_label = "My Custom Panel"

    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "world"

# Zeichnet den Button zum Öffnen des Message Fensters
    def draw(self, context):
        layout = self.layout
        layout.operator("open.browser", text = "Browser Bowser")

class OpenBrowser(bpy.types.Operator):
    bl_idname = "open.browser"
    bl_label = "Minimum code to open browser & get filepath"

    filepath = bpy.props.StringProperty(subtype="FILE_PATH") 
    #somewhere to remember the address of the file

    def execute(self, context):
        display = "filepath= "+self.filepath  
        print(display) #Prints to console  
        #Window>>>Toggle systen console

        return {'FINISHED'}

    def invoke(self, context, event): # See comments at end  [1]

        #Open browser, take reference to 'self' 
        #read the path to selected file, 
        #put path in declared string type data structure self.filepath

        return {'RUNNING_MODAL'}  
        # Tells Blender to hang on for the slow user input

def register():

def unregister():

if __name__ == "__main__":

so the main code looks like this.

Now I want to store the path that will be selected with the browser in a var that feed/fill into a editable TextBox in the Panel that can be empty before the user select one with the browser: And I then would Need a Create Path Button, that creates SubFolder within that selected path.

like in this example:

import os


os.mkdir("foo")  #creates foo in /home/monty

os.chdir("foo") #change the current working diirectory to `foo`


os.mkdir("bar")  #now `bar` is created in `/home/monty/foo`
  • 6
    $\begingroup$ It's easier than you might think. Just add a StringProp and set it's subtype to 'DIR_PATH': How to create a Folder Dialog?. $\endgroup$ – p2or Mar 3 at 11:32
  • $\begingroup$ Thank you. does this mean the StringProp have to be a separate class and can be reused everytime I need a field with text ? Do you have time to build a more explainable answer? $\endgroup$ – Master Heavy Mar 4 at 12:45
  • 1
    $\begingroup$ StringProperty can hold one path to one folder. For multiple paths (properties) you can use eg. a CollectionProperty to hold one path per item, which also is the base for building up an UIList. Did you try the code? What's your goal? Setting up project folders per scene like cache, sim, comp, prev etc.? How does the UI should look like? $\endgroup$ – p2or Mar 4 at 13:48
  • $\begingroup$ yes, my goal is to create a little Ui or addon, that makes repitive tasks easier. Starting with selecting base folder and create necessary project folders, which will be hardcoded. Ending up creating connections that every project need to have - so for example same Color Correction for exterior shots, output path, setting Object ID to TextureSelectDriver, all such stuff that is mostly the same in every Project. And I dig into all that stuff you linked right now, so I think I will have a better understanding in a few minutes ;) $\endgroup$ – Master Heavy Mar 5 at 8:27
  • $\begingroup$ Yep. Remaining problem is where to put the new panel... I think one good approach is having a custom window, don't know. Also, if you haven't seen it already, might be interesting: prism-pipeline.com $\endgroup$ – p2or Mar 5 at 10:38

Your Answer

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

Browse other questions tagged or ask your own question.