Access my addon's panels programatically?

I’m making an addon. I wanted to set a layout property on all the panels. Specifically, I’d like to set self.layout.scale_y on them all. I can definitely do it manually in each panel’s defintion, but the thought occurred to me that it might be cool to set some properties like this by looping thru all the panels. Something like…

for p in panels:
     p.layout.scale_y = 1.5

Is it possible to access the panels programmatically like that? I can’t figure out where they are in the BPY landscape (for example, they don’t seem to be in bpy.context.scene)


An easier way would be to create a FloatProperty and and set the value with that in each panel. For example,

Scene.myPanelScale = FloatProperty()

''' Now, in each panel draw method '''
def draw(self, context):
    self.layout.scale_y = context.scene.myPanelScale;

You could even expose that in it’s own panel if you want (for example, in your AddonPreferences) for maximum customizability.

1 Like

I don’t think you can do what you’re trying to do in the way you want to.

A panel’s draw method is defined at register time and while a hack where it is unregistered and registered back dynamically is possible, it would be extremely ugly and I assume buggy. So you would have to either use a blender property like the previous answer suggests (ideally in the addon preferences I guess), or use a global variable in one of your files and call it inside your panel draw method.

1 Like