diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 18:11:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 18:11:19 +0400 |
commit | 957604f8954fe369e1841bb922a102d632f0952c (patch) | |
tree | 1a0ff3bb938d5b0218cd545c1b29c356ef1bcb8f /source/blender/windowmanager/intern/wm_operators.c | |
parent | 2a657345c7d68f98b3e8e27fbcd4f9995de077e4 (diff) |
functions to make a string representation of a property & assignment.
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operators.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b16eed9df2c..7316e494b88 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -560,6 +560,51 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i return cstring; } +char *WM_prop_pystring(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + char *id_path; + char *data_path = NULL; + + char *ret; + + if (!ptr->id.data) { + return NULL; + } + + + /* never fails */ + id_path = RNA_path_from_ID_python(ptr->id.data); + + data_path = RNA_path_from_ID_to_property(ptr, prop); + + if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) { + ret = BLI_sprintfN("%s.%s", + id_path, data_path); + } + else { + ret = BLI_sprintfN("%s.%s[%d]", + id_path, data_path, index); + } + + return ret; +} + +char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index) +{ + char *lhs = WM_prop_pystring(ptr, prop, index); + char *rhs = RNA_property_as_string(C, ptr, prop, index); + char *ret; + + if (!lhs) { + return NULL; + } + + ret = BLI_sprintfN("%s = %s", lhs, rhs); + MEM_freeN(lhs); + MEM_freeN(rhs); + return ret; +} + void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot) { RNA_pointer_create(NULL, ot->srna, NULL, ptr); |