1
$\begingroup$

When I assign a new bpy.props Property to the Scene, like this: bpy.types.Scene.my_prop = bpy.props.IntProperty() - I can then set unique my_prop value for each Scene in the Blender project. The same is with the Object, Material, etc. But I would like to have some PropertyGroup attached to the current project, which settings would be unique for each project, but remain the same for all the scenes, objects and other data blocks in it. I could not find anything like bpy.types.Project. There is bpy.types.BlendData, but when I assign any bpy.props to it as an argument, it appears in bpy.context.blend_data as a function, not as a registered property. Also this attribute can not be changed or deleted once it was set. I understand that what I want is probably not the way it meant to work and that once the Property is registered it is meant to stay available regardless closing and opening the projects, until it is unregistered. I just want to clarify if there is no straight forward way to assign the Property to the Project itself. Is it so or am I missing something?

UPD. The only way I see for now is to assign PropertyGroup as an attribute of the bpy.types.Scene and to write an operator which would copy the values from the PropertyGroup of the context scene to all the other scenes every time the property is changed. But in this way it may be pretty tricky to write update functions for the properties.

$\endgroup$

1 Answer 1

2
$\begingroup$

When you create a Property Definition by such an assignment, you are adding a new field to an existing type class. Because of the way that Property definitions work, you may only add to classes that inherit from one of three types:

any subclass of ID, Bone and PoseBone.

bpy.types.BlendData does not inherit from any of those classes.

There is some behind the scenes C magic going on with Property Definitions, and so if you try to add one from a class that doesn't properly inherit, you get the behavior you've seen.

You don't need to assign a PropertyGroup. You can add your property directly to bpy.types.Scene as you describe in your first sentence.

Do you want the property value to be shared by all scenes? Or do you want each scene to have its own value? In the first case, the best choice would be to assign it to a more inclusive class than Scene and refer to it from that class. I can't tell you which class to use without more specific information about what you want to do.

In either case, you don't need an operator to change the value, you can simply add a prop layout to a panel for that value. See this answer for an example of how to do that.

$\endgroup$
1
  • $\begingroup$ Thank you. In short I need a PropertyGroup registered as a CollectionProperty of the whole project which items could be referenced by index in any data block. E.g. I add a new item with a stack of settings, edit them once and then can use this stack for any object in any scene by pointing at item index as IntProperty. Now I see that the best solution for me would be to register a custom class inheriting from bpy.types.ID, but 'ID' classes are not registerable, so this is not possible and I'll just find some workaround. Thank you! $\endgroup$ Commented Apr 5, 2022 at 9:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .