Page MenuHome
Paste P563

python message bus example
ActivePublic

Authored by Campbell Barton (campbellbarton) on Nov 28 2017, 5:05 PM.
import bpy
handle = object()
# all branches below work
if 1:
# To get some properties we need to prevent them being coerced into native Py types.
subscribe_to = bpy.context.object.path_resolve("name", False)
elif 0:
subscribe_to = bpy.context.object.location
else:
# all object locations
subscribe_to = bpy.types.Object, "location"
def notify_test(*args):
print("Notify changed!", args)
bpy.msgbus.subscribe_rna(
key=subscribe_to,
owner=handle,
args=(1, 2, 3),
notify=notify_test,
)
# In general we won't need to explicitly publish, nevertheless - support it.
bpy.msgbus.publish_rna(key=subscribe_to)
# ... to clear
# bpy.msgbus.clear_by_owner(handle)

Event Timeline

@Campbell Barton (campbellbarton) Hi! When I try running the above code as a script from the text editor in blender, I get this error in the system console:

Traceback (most recent call last):
File "/Text", line 22, in <module>
TypeError: Required argument 'key' (pos 1) not found
Error: Python script fail, look in the console for now...

Here is an excerpt from system-info.txt as generated by the 2.8 build I am using, I hope it helps identify the build I've tested that produced this error :P :

===========================================
= Blender 2.80 (sub 3) System Information =
===========================================


Blender:
===========================================

version: 2.80 (sub 3), branch: blender2.8, commit date: 2017-12-22 21:18, hash: fe1e2c2f89b, type: Release
build date: 2017-12-23, 01:33:42
platform: Darwin

Have you any further guidance on how to clear this error so I can continue testing? Thanks! :D

Pasting the code given in this post into blender's (blender 2.80.40) script editor and hitting the run script button gives me this output:

Traceback (most recent call last):
  File "/Text", line 22, in <module>
TypeError: subscribe_rna() missing required argument 'options' (pos 5)
Error: Python script fail, look in the console for now...

Sorry, looks like its still broke

rB9df460203517a791107c6da816ab21ace803d5f4 or newer is needed, otherwise pass in set() as the last arg.