Attributes: Expose "is required" read-only property to Python
This allows detecting if deleting the attribute will be possible
without actually trying to delete it, which can give warning
messages in the terminal.
As an example:
```
>>> [(item.name, item.is_required) for item in mesh.attributes]
[('Attribute', False),
('position', True),
('.edge_verts', True),
('sharp_face', False),
('.corner_vert', True),
('.corner_edge', True)]
```
Pull Request: https://projects.blender.org/blender/blender/pulls/111468
This commit is contained in:
@@ -279,6 +279,12 @@ static bool rna_Attribute_is_internal_get(PointerRNA *ptr)
|
||||
return !BKE_attribute_allow_procedural_access(layer->name);
|
||||
}
|
||||
|
||||
static bool rna_Attribute_is_required_get(PointerRNA *ptr)
|
||||
{
|
||||
const CustomDataLayer *layer = (const CustomDataLayer *)ptr->data;
|
||||
return BKE_id_attribute_required(ptr->owner_id, layer->name);
|
||||
}
|
||||
|
||||
static void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
|
||||
{
|
||||
ID *id = ptr->owner_id;
|
||||
@@ -1156,6 +1162,11 @@ static void rna_def_attribute(BlenderRNA *brna)
|
||||
prop, "Is Internal", "The attribute is meant for internal use by Blender");
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
||||
prop = RNA_def_property(srna, "is_required", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(prop, "rna_Attribute_is_required_get", nullptr);
|
||||
RNA_def_property_ui_text(prop, "Is Required", "Whether the attribute can be removed or renamed");
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
|
||||
/* types */
|
||||
rna_def_attribute_float(brna);
|
||||
rna_def_attribute_float_vector(brna);
|
||||
|
||||
Reference in New Issue
Block a user