_RestrictData workaround?

I just came across this problem with _RestrictData when the add-on loads. I understand why this problem shows up, as I have read some other threads regarding this problem, though I still don’t get how to fix it. One of the properties defined in the bpy.types.panel class requires bpy.data.materials.

My question is, what is the best workaround for this?

Thanks.

/GB

Panels can’t have properties. They are either declared globally (bpy.props), on an object-basis (ID properties), or inside operator classes.

Context and data restriction is only an issue if you try to use a default value in a global property which is based on a certain object, e.g.

bpy.props.StringProperty(default=bpy.data.materials[2].name)

You shouldn’t do something like that in the first place, but if it’s absolutely necessary for you, I can post a hacky workaround.

Hmm, okey. I have had properties in my panel class and it have worked, though I guess you shouldn’t because its a bad structure of the code and it maybe doesn’t work in some cases. Anyways, what I wanna do is I wanna create a list of all the materials in the scene. I thought using the enumproperty would work good here, but I can’t reach bpy.data.materials at startup. Is there a smarter way of creating this list of materials that will be visible in the panel, or should I use that hacky workaround you mentioned?^^

Thanks!

You can use a dynamic enum property, see e.g. here

Works great! Just for curiosity, what does a pointerproperty do more exactly? Is it a way of creating a property from the bottom or something?

Thanks!

You basically use it to nest other properties, see the API docs:

www.blender.org/api/blender_python_api_2_73_release/bpy.props.html#propertygroup-example

Okay, thanks!