Fix T101272: Missing view layer updates handling collections via python.

Fixed by ensuring the view layer is up to date.
This commit is contained in:
Jeroen Bakker 2022-09-27 11:57:34 +02:00
parent cbab734445
commit 4a60c4746d
Notes: blender-bot 2023-02-14 04:31:04 +01:00
Referenced by commit bb8dba8609, Fix missing view layer update when iterating a collection from Python.
Referenced by issue #101394, Importing file after making a new collection active hits an assert (View Layer Object Base out of sync)
Referenced by issue #101272, Missing view layer updates handling collections in python
1 changed files with 44 additions and 0 deletions

View File

@ -369,6 +369,41 @@ static bool rna_LayerCollection_has_selected_objects(LayerCollection *lc,
return false;
}
static bool rna_LayerCollection_children_lookupint(struct PointerRNA *ptr,
int key,
struct PointerRNA *r_ptr)
{
Scene *scene = (Scene *)ptr->owner_id;
LayerCollection *lc = (LayerCollection *)ptr->data;
ViewLayer *view_layer = BKE_view_layer_find_from_collection(scene, lc);
BKE_view_layer_synced_ensure(scene, view_layer);
LayerCollection *child = BLI_findlink(&lc->layer_collections, key);
if (!child) {
return false;
}
RNA_pointer_create(ptr->owner_id, &RNA_LayerCollection, child, r_ptr);
return true;
}
static bool rna_LayerCollection_children_lookupstring(struct PointerRNA *ptr,
const char *key,
struct PointerRNA *r_ptr)
{
Scene *scene = (Scene *)ptr->owner_id;
LayerCollection *lc = (LayerCollection *)ptr->data;
ViewLayer *view_layer = BKE_view_layer_find_from_collection(scene, lc);
BKE_view_layer_synced_ensure(scene, view_layer);
LISTBASE_FOREACH (LayerCollection *, child, &lc->layer_collections) {
if (STREQ(child->collection->id.name + 2, key)) {
RNA_pointer_create(ptr->owner_id, &RNA_LayerCollection, child, r_ptr);
return true;
}
}
return false;
}
#else
static void rna_def_layer_collection(BlenderRNA *brna)
@ -399,6 +434,15 @@ static void rna_def_layer_collection(BlenderRNA *brna)
RNA_def_property_collection_sdna(prop, NULL, "layer_collections", NULL);
RNA_def_property_struct_type(prop, "LayerCollection");
RNA_def_property_ui_text(prop, "Children", "Child layer collections");
RNA_def_property_collection_funcs(prop,
NULL,
NULL,
NULL,
NULL,
NULL,
"rna_LayerCollection_children_lookupint",
"rna_LayerCollection_children_lookupstring",
NULL);
/* Restriction flags. */
prop = RNA_def_property(srna, "exclude", PROP_BOOLEAN, PROP_NONE);