0
$\begingroup$

This question has likely been asked before. I tried to search, but I honestly don't know how to phrase the question specifically enough to find anything.

If I define a property inside of a class like this:

class Type(bpy.types.PropertyGroup):

    stuff : bpy.props.BoolProperty(
        name="Property Name",
        description="Property Info",
        default=False,
        )

Is it possible to access the name, description, default, and other fields, later at execution time? Say, for example, during a panel draw function?

Edit:

After posting, I starting playing around and found that class_instance.__annotations__.values() seems to include all of this data. But I'm not sure how to sort it out or access the data. I'm still pretty unskilled with Python concepts like tuples and dictionaries, but it looks like the wanted data may be in a dictionary? I'm thinking it may be possible to access it with something like var.__annotations__.values()[1]['description'].

But even if something like this is possible, would it be the correct way to do it? Is there a better way?

$\endgroup$
  • 1
    $\begingroup$ annotations is a new stuff in Python3. Which Blender 2.80 adapt the feature to make those properties as annotations. And you can use __annotations__ to access those data for sure. If the value is not modified since the Group created, those properties can only be access in annotations AFAIK. But maybe I am wrong. $\endgroup$ – HikariTW Sep 29 '19 at 4:29
1
$\begingroup$

You can access them through RNA without using annotations. Assuming you have registered your PropertyGroup you can access them like in the following example.

For instance the code below gives you access to the description of Eevee's render samples property.

bpy.context.scene.eevee.bl_rna.properties["taa_render_samples"].description
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks! Are bl_rna.properties and __annotations__ similar features? I don't entirely understand what sets these apart. One thing I noticed was that __annotations__ only seems to include "properties", where bl_rna.properties seems to include all members? Is that true? Are there any other differences? $\endgroup$ – Robert Sep 29 '19 at 13:26
  • $\begingroup$ After looking a little deeper, __annotations__ looks to primarily be groupings of strings, where bl_rna.properties looks more like a class instance with many property details, some of which are also strings. I think I'm starting to get it. $\endgroup$ – Robert Sep 29 '19 at 13:49
  • $\begingroup$ The __annotations__ are relevant for the declaration of the properties using the : syntax. It allows you to access the class variables like a dictionary. It usually becomes relevant when you want to create properties dynamically (which you don't do in your example). I haven't checked Blender's source code for this, but I'm fairly certain that bl_rna.properties uses these annotations under the hood. If the properties are registered I find the approach through the Blender API a bit nicer. $\endgroup$ – Robert Gützkow Sep 29 '19 at 13:59

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.