I have something like this in the my add-on __init__ file:

class MyPreferences(AddonPreferences):
    bl_idname = __name__

    num: IntProperty(name="Number", default=888)

    def draw(self, context):
        layout = self.layout
        layout.prop(self, "num")

I need to get this number from another file, and "MyPreferences.num" doesn't work. It returns a tuple, where the first value is "<built-in function IntProperty>" and the second value is a dictionary.

I can access the dictionary values, but the only ones available are "name", "attr", and "default", so if the user changes the property, I can't access the new value.

What should I do?

  • $\begingroup$ Would help if this example was self contained $\endgroup$
    – ideasman42
    Oct 24 '15 at 13:34

Something like this

addon = bpy.context.preferences.addons.get(addon_name)
if addon:
    prefs = addon.preferences

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.