def execute(self, context): data_path = self.data_path value = self.value prop = self.property prop_old = getattr(self, "_last_prop", [None])[0] if prop_old is None: self.report({'ERROR'}, "Direct execution not supported") return {'CANCELLED'} try: value_eval = eval(value) except: value_eval = value # First remove item = eval("context.%s" % data_path) rna_idprop_ui_prop_clear(item, prop_old) exec_str = "del item['%s']" % prop_old # print(exec_str) exec(exec_str) # Reassign exec_str = "item['%s'] = %s" % (prop, repr(value_eval)) # print(exec_str) exec(exec_str) self._last_prop[:] = [prop] prop_type = type(item[prop]) prop_ui = rna_idprop_ui_prop_get(item, prop) if prop_type in {float, int}: prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.min) prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.max) prop_ui['description'] = self.description # otherwise existing buttons which reference freed # memory may crash blender [#26510] # context.area.tag_redraw() for win in context.window_manager.windows: for area in win.screen.areas: area.tag_redraw() return {'FINISHED'}
def execute(self, context): data_path = self.data_path value = self.value prop = self.property prop_old = self._last_prop[0] try: value_eval = eval(value) except: value_eval = value # First remove item = eval("context.%s" % data_path) rna_idprop_ui_prop_clear(item, prop_old) exec_str = "del item['%s']" % prop_old # print(exec_str) exec(exec_str) # Reassign exec_str = "item['%s'] = %s" % (prop, repr(value_eval)) # print(exec_str) exec(exec_str) self._last_prop[:] = [prop] prop_type = type(item[prop]) prop_ui = rna_idprop_ui_prop_get(item, prop) if prop_type in (float, int): prop_ui['soft_min'] = prop_ui['min'] = prop_type(self.min) prop_ui['soft_max'] = prop_ui['max'] = prop_type(self.max) prop_ui['description'] = self.description return {'FINISHED'}
def execute(self, context): from rna_prop_ui import rna_idprop_ui_prop_get, rna_idprop_ui_prop_clear data_path = self.data_path value = self.value prop = self.new_prop_name prop_old = self.current_prop_name _last_prop = [prop_old] if prop_old is None: self.report({'ERROR'}, "Direct execution not supported") return {'CANCELLED'} try: value_eval = eval(value) # assert else None -> None, not "None", see [#33431] assert (type(value_eval) in {str, float, int, bool, tuple, list}) except: value_eval = value if not prop: prop = prop_old #Keep the same name # First remove item = eval("context.%s" % data_path) prop_type_old = type(item[prop_old]) rna_idprop_ui_prop_clear(item, prop_old) exec_str = "del item[%r]" % prop_old # print(exec_str) exec(exec_str) # Reassign exec_str = "item[%r] = %s" % (prop, repr(value_eval)) # print(exec_str) exec(exec_str) _last_prop[:] = [prop] prop_type = type(item[prop]) prop_ui = rna_idprop_ui_prop_get(item, prop) if prop_type in {float, int}: prop_ui["soft_min"] = prop_ui["min"] = prop_type(self.min) prop_ui["soft_max"] = prop_ui["max"] = prop_type(self.max) prop_ui["description"] = self.description # If we have changed the type of the property, update its potential anim curves! if prop_type_old != prop_type: data_path = '["%s"]' % bpy.utils.escape_identifier(prop) done = set() def _update(fcurves): for fcu in fcurves: if fcu not in done and fcu.data_path == data_path: fcu.update_autoflags(item) done.add(fcu) def _update_strips(strips): for st in strips: if st.type == 'CLIP' and st.action: _update(st.action.fcurves) elif st.type == 'META': _update_strips(st.strips) adt = getattr(item, "animation_data", None) if adt is not None: if adt.action: _update(adt.action.fcurves) if adt.drivers: _update(adt.drivers) if adt.nla_tracks: for nt in adt.nla_tracks: _update_strips(nt.strips) # otherwise existing buttons which reference freed # memory may crash blender [#26510] # context.area.tag_redraw() for win in context.window_manager.windows: for area in win.screen.areas: area.tag_redraw() return {'FINISHED'}
def execute(self, context): from rna_prop_ui import rna_idprop_ui_prop_get, rna_idprop_ui_prop_clear data_path = self.data_path value = self.value prop = self.new_prop_name prop_old = self.current_prop_name _last_prop = [prop_old] if prop_old is None: self.report({"ERROR"}, "Direct execution not supported") return {"CANCELLED"} try: value_eval = eval(value) # assert else None -> None, not "None", see [#33431] assert type(value_eval) in {str, float, int, bool, tuple, list} except: value_eval = value if not prop: prop = prop_old # Keep the same name # First remove item = eval("context.%s" % data_path) prop_type_old = type(item[prop_old]) rna_idprop_ui_prop_clear(item, prop_old) exec_str = "del item[%r]" % prop_old # print(exec_str) exec(exec_str) # Reassign exec_str = "item[%r] = %s" % (prop, repr(value_eval)) # print(exec_str) exec(exec_str) _last_prop[:] = [prop] prop_type = type(item[prop]) prop_ui = rna_idprop_ui_prop_get(item, prop) if prop_type in {float, int}: prop_ui["soft_min"] = prop_ui["min"] = prop_type(self.min) prop_ui["soft_max"] = prop_ui["max"] = prop_type(self.max) prop_ui["description"] = self.description # If we have changed the type of the property, update its potential anim curves! if prop_type_old != prop_type: data_path = '["%s"]' % bpy.utils.escape_identifier(prop) done = set() def _update(fcurves): for fcu in fcurves: if fcu not in done and fcu.data_path == data_path: fcu.update_autoflags(item) done.add(fcu) def _update_strips(strips): for st in strips: if st.type == "CLIP" and st.action: _update(st.action.fcurves) elif st.type == "META": _update_strips(st.strips) adt = getattr(item, "animation_data", None) if adt is not None: if adt.action: _update(adt.action.fcurves) if adt.drivers: _update(adt.drivers) if adt.nla_tracks: for nt in adt.nla_tracks: _update_strips(nt.strips) # otherwise existing buttons which reference freed # memory may crash blender [#26510] # context.area.tag_redraw() for win in context.window_manager.windows: for area in win.screen.areas: area.tag_redraw() return {"FINISHED"}