# Create a folder dialog box for an addon (2.91) [duplicate]

I'm trying to add a folder dialog box in the add-on I'm working on. I managed to add a button that opens a folder dialog and setup the path, but I'd like to be able to see that path rather than just printing it in the console.

Something like that :

I'm currently using an operator and I found out that I need to use a Property, here's what I tried :

class project_path(bpy.types.PropertyGroup):
path: bpy.props.StringProperty(subtype="DIR_PATH")


and then tried to call it in my Panel with :

class PT_Panel(Panel):
bl_space_type = "VIEW_3D"
bl_region_type ="UI"
bl_label = "Operations"
bl_category = "Tools"

def draw(self, context):

layout = self.layout

sce = context.scene

box = layout.box()
box.label( text = "Project Path")

row = box.row()
row.prop(sce.project_path,"path",text='Project Path')


But then I got that error :

AttributeError: 'Scene' object has no attribute 'project_path'


Can't find any help on that, I guess I'm not using the correct attribute, but I've tried a bunch of different things without success, am I not supposed to use the class as an attribute ?

I found this question that is relevant, but it's also not explaining where the attribute is taken from.

This is how you get it to work

Import :

from bpy.props import PointerProperty


ProjPath = context.scene.proj_path
row.prop(ProjPath, "path", text='Project Path')


While registering:

classes = [project_path, PT_Panel]

def register():

for cls in classes :
bpy.utils.register_class(cls)
bpy.types.Scene.proj_path= PointerProperty(type= project_path)

def unregister():

for cls in classes :
bpy.utils.unregister_class(cls)
del bpy.types.Scene.proj_path

if __name__ == "__main__":
register()


If you want to save it permanently then use AddonPrefrences

And try to improve your naming skills :