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.row()
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]
context.window_manager.fileselect_add(self)
#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():
bpy.utils.register_class(OpenBrowser)
bpy.utils.register_class(panel1)
def unregister():
bpy.utils.register_class(OpenBrowser)
bpy.utils.unregister_class(panel1)
if __name__ == "__main__":
register()
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.getcwd()
'/home/monty'
os.mkdir("foo") #creates foo in /home/monty
os.chdir("foo") #change the current working diirectory to `foo`
os.getcwd()
'/home/monty/foo'
os.mkdir("bar") #now `bar` is created in `/home/monty/foo`
StringPropand set it'ssubtypeto'DIR_PATH': How to create a Folder Dialog?. – p2or Mar 03 '20 at 11:32StringPropertycan hold one path to one folder. For multiple paths (properties) you can use eg. aCollectionPropertyto 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? – p2or Mar 04 '20 at 13:48