[Bf-blender-cvs] [0bb33294c12] blender2.8: RNA API: ViewLayers: add name to LayerCollection struct.

Bastien Montagne noreply at git.blender.org
Thu Nov 8 11:36:45 CET 2018


Commit: 0bb33294c12163191c180dda41533c690eea1b3a
Author: Bastien Montagne
Date:   Thu Nov 8 11:34:18 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB0bb33294c12163191c180dda41533c690eea1b3a

RNA API: ViewLayers: add name to LayerCollection struct.

Just use Collection name (same as for material slots e.g.).

That way, one can access those by their names as well, in
LayerCollection.children ... collection property (yeah, collection,
collection, and moar collection).

===================================================================

M	source/blender/makesrna/intern/rna_layer.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
index 727364a5bda..693d7a06a79 100644
--- a/source/blender/makesrna/intern/rna_layer.c
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -192,6 +192,18 @@ static void rna_ObjectBase_select_update(Main *UNUSED(bmain), Scene *UNUSED(scen
 	ED_object_base_select(base, mode);
 }
 
+static void rna_LayerCollection_name_get(struct PointerRNA *ptr, char *value)
+{
+	ID *id = (ID *)((LayerCollection *)ptr->data)->collection;
+	BLI_strncpy(value, id->name + 2, sizeof(id->name) - 2);
+}
+
+int rna_LayerCollection_name_length(PointerRNA *ptr)
+{
+	ID *id = (ID *)((LayerCollection *)ptr->data)->collection;
+	return strlen(id->name + 2);
+}
+
 static void rna_LayerCollection_use_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
 {
 	Scene *scene = (Scene *)ptr->id.data;
@@ -222,6 +234,13 @@ static void rna_def_layer_collection(BlenderRNA *brna)
 	RNA_def_property_struct_type(prop, "Collection");
 	RNA_def_property_ui_text(prop, "Collection", "Collection this layer collection is wrapping");
 
+	prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+	RNA_def_property_string_sdna(prop, NULL, "collection->id.name");
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE | PROP_ANIMATABLE);
+	RNA_def_property_ui_text(prop, "Name", "Name of this view layer (same as its collection one)");
+	RNA_def_property_string_funcs(prop, "rna_LayerCollection_name_get", "rna_LayerCollection_name_length", NULL);
+	RNA_def_struct_name_property(srna, prop);
+
 	prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
 	RNA_def_property_collection_sdna(prop, NULL, "layer_collections", NULL);
 	RNA_def_property_struct_type(prop, "LayerCollection");



More information about the Bf-blender-cvs mailing list