# How to iterate through a PropertyGroup?

I'm fairly new to using Blender's API, and Python for that matter, and just can't find the answer to my question elsewhere so here it goes:

I have a PropertryGroup and I want to write the names and the values of the contained properties into a file. They are mostly floats and 2 booleans.

My PropertyGroup ist for example looking like this:

class ExampleFloatPropertyGroup(bpy.types.PropertyGroup):
float_a = bpy.props.FloatProperty \
(
name = "Float A",
description = "Contains the value of Float A",
default = 1.0
)
float_b = bpy.props.FloatProperty \
(
name = "Float B",
description = "Contains the value of Float B",
default = 2.0
)


Within my operator I'm using it like this:

example_floats = bpy.props.PointerProperty(type = ExampleFloatPropertyGroup)


And so far everything works fine. I can work with it, pass it on to other classes, they can work with it and so on.

Now I tried to access the information that I need by using .items() or .keys(). For example like this example_floats.items().But as long as the values in my PropertyGroup are set to default, I'm only getting a completly empty return looking like this []

As soon as I change one of the values from default to something else, the returns are no longer empty but I only get the values that I did change, but still not the ones that are still set to default.

Also I'm only getting the key and the current value. I would also like to Access the property's attribute name. In this case "Float A" or "Float B".

So as the titles states, how can I iterate the single properties contained in a PropertyGroup, while retrieving the value and the name of the propertie?

I'm sure there is a relatively easy solution, but I was not able to work around that problem after hitting google for quite some time today.

Any help is greatly appreciated!

• Are you not adding the pointer property to something, like a scene, object? How are there different instances of the group? Jan 28, 2017 at 19:54
• I did have the pointer attached to the scene. The problem is I was using it inside an operator which creates some kind of mesh. I wanted the propertys inside the group to be displayed in the operator panel, so that I can directly manipulate the created mesh. This did not work since Blender always just goes back to the state of the moment that I invoked the operator, before redrawing the mesh. This "going back" did include the group's values. So I make an instance of the group in my operator and just delete the one attached to the scene and reattach the up-to-date one from my operator. Jan 28, 2017 at 21:35

I am wondering the same thing too, but I found a solution in this discussion: here

After using help() or dir() in that PropertyGroup, you can find out some attributes inside this object as follow:

['__annotations__', '__dict__', '__doc__', '__module__', '__weakref__', 'bl_rna', 'name', 'rna_type' , "SOMETHING", "YOU", "DEFINED"]


Depend on what version of blender you are using, you can iterate these attributes to get what you defined.

For Blender 2.8, since the APIs forced developer to use annotation instead, you can find all attributes(as a dict) you defined in bpy.some.where.thePropertiesGroup.__annotations__ without those inherited attribute from PropertyGroup.

If you want to get those attribute, you should use built-in getattr() method as following:

for key in propsgroup.__annotations__.keys():
the_value = getattr(propsgroup, key)