Blender Python: Declare Property Group (on the stack?)

by Robert   Last Updated September 11, 2019 23:15 PM

The questions keep coming, I know. I cannot find this simple answer anywhere. It may be because I'm not sure exactly how to phrase it in searches.

Is it possible to declare a variable of a custom type that is derived from bpy.types.PropertyGroup?

I have a situation where I create controls for the active object. But I would like to show these controls in a disabled state when there is no active object (or any object at all). So my (possibly terrible) idea is to declare a local variable of the property group used by objects and use the data in this temporary property group to draw the buttons and controls. I know I can just skip drawing the associated controls, but I don't like how disruptive it is to have the panel contents shift around when it happens.

Here is an example of what I mean:

class MyClass(bpy.types.PropertyGroup):
    Var : BoolProperty(
        name = "Stuff",
        description = "my stuff",

def draw_panel():

    if active_object:
        draw_buttons(active_object.MyProperties, disabled=false)
        temp_props = MyClass()
        draw_buttons(temp_props, disabled=true)

So the controls would be associated with a temporary property object. However, the code temp_props = MyClass() does not work. It appears that bpy_struct requires some type of "constructor parameter" (I'm not sure what these are called in python)?

If there is a better way to handle this, please feel free to slap me out of this idea. And in either case, how would one go about declaring a class derived from a property group or bpy_struct locally within a function? Is it even possible? I can't seem to find anything in the API docs about initializing one of these objects on our own.

Related Questions

Its ok in using for an addon?

Updated March 29, 2018 14:15 PM

Create a Button with a Large Icon

Updated April 03, 2018 15:15 PM

Blender Python: Output Paragraph of Text?

Updated September 09, 2019 13:15 PM

Blender Python: Access Selected Collections?

Updated September 11, 2019 02:15 AM

Blender Python: Property Description String Limit?

Updated September 11, 2019 15:15 PM