This simple patch adds a full_path parameter to [copy_data_path_button()](https://www.blender.org/api/blender_python_api_current/bpy.ops.ui.html?highlight=copy_data_path_button#bpy.ops.ui.copy_data_path_button) operator in order to match the behavior of Ctrl+Shift+Alt+C shortcut on the active mouse cursor property, which isn't exposed to the API yet.
At the moment the operator copies the data-path of the active mouse cursor UI property to the clipboard. By placing the cursor over the scenes 'resolution x' property and running copy_data_path_button() the clipboard yields: render.resolution_x. However in order to find the corresponding RNA path via python an entire RNA iteration is required (error-prone and slow). By using this patch and setting full_path flag to True, the operator now allows to copy the full data-path of the data-block to the clipboard so in this case: bpy.data.scenes["Scene"].render.resolution_x and is especially fast as expected.
For demonstration purposes as well as to provide a simple use case I wrote a python operator to report the active property when pressing Shift+Q while mouse cursor is over a UI property (to test the assignment it also adds 1 to the value of each IntegerProperty or FloatProperty per execution).
import bpy
class MouseCursorPropertyOperator(bpy.types.Operator):
bl_idname = "screen.active_property_add"
bl_label = "Add custom value to active mouse cursor property"
bl_options = {'REGISTER'}
@classmethod
def poll(cls, context):
return bpy.ops.ui.copy_data_path_button.poll()
def execute(self, context):
# get the data path
bpy.ops.ui.copy_data_path_button()
path = context.window_manager.clipboard
# get full data path
bpy.ops.ui.copy_data_path_button(full_path=True)
full_path = context.window_manager.clipboard
# split path in class and property
rna, prop = context.window_manager.clipboard.rsplit('.', 1)
addend = 1
# set attribute value if its type is an integer
if type(eval(full_path)) is int:
rna_eval = (eval(rna))
value = getattr(rna_eval, prop)
setattr(rna_eval, prop, value + addend)
self.report({"INFO"}, "{} set to {}".format(prop, value + addend))
# set attribute value if its type is an float
elif type(eval(full_path)) is float:
if prop.endswith("]"): # check if property is vector
#print (getattr(rna_eval, path))
index = prop[-2:-1]
rna_eval = eval(".".join([rna, path]))
value = getattr(rna_eval, ("x","y","z")[int(index)])
setattr(rna_eval, ("x","y","z")[int(index)], value + addend)
self.report({"INFO"}, "{} set to {}".format(prop, value + addend))
else: # single float property
rna_eval = (eval(rna))
value = getattr(rna_eval, prop)
setattr(rna_eval, prop, value + 10)
self.report({"INFO"}, "{} set to {}".format(prop, value + addend))
# neither integer nor float
else:
print (type(eval(full_path)))
self.report({"INFO"}, "{} not an integer or float".format(prop))
return {'FINISHED'}
addon_keymaps = []
def register():
bpy.utils.register_class(MouseCursorPropertyOperator)
# handle the keymap
wm = bpy.context.window_manager
kc = wm.keyconfigs.addon
if kc:
km = wm.keyconfigs.addon.keymaps.new(name='Screen')
kmi = km.keymap_items.new(MouseCursorPropertyOperator.bl_idname, type='Q', value='PRESS', shift=True)
addon_keymaps.append((km, kmi))
def unregister():
for km, kmi in addon_keymaps:
km.keymap_items.remove(kmi)
addon_keymaps.clear()
bpy.utils.unregister_class(MouseCursorPropertyOperator)
if __name__ == "__main__":
register()Here a gif: https://i.stack.imgur.com/Qd6YS.gif
Note: Unfortunately it does not work in the compositor for this reason.
Best regards,
Christian

