I'm trying to expose the VIEW_3D location of my Add-on in its preferences. So far I got the user input working showing in the preferences of my Add-on.
# Input Variable
class preferences_props(bpy.types.PropertyGroup):
location_name: bpy.props.StringProperty(
name="Path",
default="Toolbox",
description="Define location of the Add-on in 3D View Menu.",
)
# Define Location in 3D View
class PT_mossifier_preferences(bpy.types.AddonPreferences):
bl_idname = __package__
bl_label = "Preferences"
bl_description = "Add-on Configurations"
bl_options = {'REGISTER', 'UNDO'}
def draw(self, context):
props = context.scene.preferences_props
layout = self.layout
layout.label(text='Under which 3D View tab to store the Add-on')
row = layout.row()
row.prop(props, "location_name")
Now I want to get location_name in my UI module, so I can set the bl_category = location_name. F.e. like this.
# Create Dropdown in Toolbox Tab
class PT_addon_ui(bpy.types.Panel):
bl_label = "Addon"
bl_idname = "PT_Addon"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = location_name
However I cannot get the actual variable value out of my preferences module. This is how I'm initialy trying to import it. And I'm using print to see if the value is what I need. However print returns "None" all the time.
import bpy
addon_prefs = bpy.context.preferences.addons[__package__].preferences
print(addon_prefs)
Also using other methos to import a variable don't work. I get the error "AttributeError: type object 'preferences_props' has no attribute 'location_name'"
from .mossifier_preferences import preferences_props
print(preferences_props.location_name)
What would be the actual way to get location_name into my UI module?
Thank you in advance!
AddonPreferences
class as if it were a property group. That way you can access the prop frombpy.context.preferences.addons["your_addon_name"].preferences.props
$\endgroup$