0

How to make search folder script in add-on preference? I want to make a button to search a folder in add-on preference that can search resource files like the Extreme PBR add-on. enter image description here

News Wave
  • 3
  • 2
  • Hi and Welcome! Consider that the bare minimum here is to show some effort towards your goal. I'd recommend always add the current state of your code to your question, makes it way easier to give an answer. Please read: https://blender.stackexchange.com/help/how-to-ask, cheers. – brockmann Apr 02 '21 at 16:04

1 Answers1

1

The example given is just a regular StringProperty added to the AddonPreferences. Notice that the subtype of the StringProperty is set to DIR_PATH:

enter image description here

import bpy
from bpy.types import Operator, AddonPreferences
from bpy.props import StringProperty, IntProperty

class ExampleAddonPreferences(AddonPreferences): bl_idname = name

filepath: StringProperty(
    name="Example File Path",
    subtype='DIR_PATH')

number: IntProperty(
    name="Example Number",
    default=4)

def draw(self, context):
    self.layout.label(text="This is a preferences view for our add-on")
    self.layout.prop(self, "filepath")
    self.layout.prop(self, "number")

def register(): bpy.utils.register_class(ExampleAddonPreferences)

def unregister(): bpy.utils.unregister_class(ExampleAddonPreferences)

if name == "main": register()

Further reading

brockmann
  • 12,613
  • 4
  • 50
  • 93