[Bf-blender-cvs] [935b7a6f65d] master: Context: implement indexing for list properties in path_resolve.
Alexander Gavrilov
noreply at git.blender.org
Mon Jul 18 16:37:50 CEST 2022
Commit: 935b7a6f65d2c90e54b59a50fd1c488f02da0e8e
Author: Alexander Gavrilov
Date: Fri Jun 24 17:08:54 2022 +0300
Branches: master
https://developer.blender.org/rB935b7a6f65d2c90e54b59a50fd1c488f02da0e8e
Context: implement indexing for list properties in path_resolve.
The real RNA path_resolve method supports indexing lists,
but the python version on the Context object does not. This
patch adds the missing feature for completeness.
Differential Revision: https://developer.blender.org/D15413
===================================================================
M release/scripts/modules/bpy_types.py
===================================================================
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index aaa2ae59a0d..df0631ec26d 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -56,6 +56,21 @@ class Context(StructRNA):
if value is None:
return value
+ # If the attribute is a list property, apply subscripting.
+ if isinstance(value, list) and path_rest.startswith("["):
+ index_str, div, index_tail = path_rest[1:].partition("]")
+ if not div:
+ raise ValueError("Path index is not terminated: %s%s" % (attr, path_rest))
+ try:
+ index = int(index_str)
+ except ValueError:
+ raise ValueError("Path index is invalid: %s[%s]" % (attr, index_str))
+ if 0 <= index < len(value):
+ path_rest = index_tail
+ value = value[index]
+ else:
+ raise IndexError("Path index out of range: %s[%s]" % (attr, index_str))
+
# Resolve the rest of the path if necessary.
if path_rest:
path_resolve_fn = getattr(value, "path_resolve", None)
More information about the Bf-blender-cvs
mailing list