bpy.msgbus.subscribe_rna doesnt trigger with the transform system #72109

Open
opened 2019-12-02 11:37:43 +01:00 by Thomas CAPELLE · 10 comments
Member

System Information
Operating system: Windows-10-10.0.17134 64 Bits
Graphics card: GeForce GTX 970/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.60

Blender Version
Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: f6cb5f5449
Worked: (optional)

Short description of error
Callback of bpy.msgbus.subscribe_rna is never called when moving the object in the scene. It only works when changing the property in the Transform panel.

Exact steps for others to reproduce the error

  1. In the scripting view, copy/past the code from here: https://blender.stackexchange.com/questions/150809/how-to-get-an-event-when-an-object-is-selected
  2. Run the script
  3. Toggle system console to see outputs
  4. In the 3D view, select the cube, open the transform panel and change one of the location's components -> the callback print something
  5. Now select the cube and move it directly in the scene -> no output

And an auxiliary question: how to unsubscribe?

Thanks!

**System Information** Operating system: Windows-10-10.0.17134 64 Bits Graphics card: GeForce GTX 970/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 431.60 **Blender Version** Broken: version: 2.80 (sub 75), branch: master, commit date: 2019-07-29 14:47, hash: `f6cb5f5449` Worked: (optional) **Short description of error** Callback of bpy.msgbus.subscribe_rna is never called when moving the object in the scene. It only works when changing the property in the Transform panel. **Exact steps for others to reproduce the error** 1. In the scripting view, copy/past the code from here: https://blender.stackexchange.com/questions/150809/how-to-get-an-event-when-an-object-is-selected 2. Run the script 3. Toggle system console to see outputs 4. In the 3D view, select the cube, open the transform panel and change one of the location's components -> the callback print something 5. Now select the cube and move it directly in the scene -> no output And an auxiliary question: how to unsubscribe? Thanks!
Author
Member

Added subscriber: @grosglob

Added subscriber: @grosglob
Member

Added subscribers: @ideasman42, @lichtwerk

Added subscribers: @ideasman42, @lichtwerk
Member

And an auxiliary question: how to unsubscribe?

bpy.msgbus.clear_by_owner

Regarding the missing update: can confirm the behavior, but it could very well be that this is how it is supposed to work:
I am a bit on shaky ground here, but from my understanding, only the following go through RNA to write to data (in most scenarios):

The transform system doesnt really go through RNA iirc, so subscribing wont succeed here.

Definitely going to let @ideasman42 decide on this [also on the following suggestion as a workaround]:
If msgbus does not handle all updates, do we have to rely on handlers here (less elegant, probably less performant as well...)?

import bpy
from mathutils import *

ob = bpy.context.object
ob["locstore"] = ob.location

def my_handler(scene):
    loc_old = Vector(ob["locstore"])
    if loc_old != ob.location:
        ob["locstore"] = ob.location
        print('Object "{}" changed its location to: {}: '.format(
            ob.name, ob.location)
            )

bpy.app.handlers.depsgraph_update_post.append(my_handler)

Maybe this also belongs more to devtalk, there is a similar thread open, see https://devtalk.blender.org/t/using-bpy-msgbus-subscribe-rna

> And an auxiliary question: how to unsubscribe? `bpy.msgbus.clear_by_owner` Regarding the missing update: can confirm the behavior, but it could very well be that this is how it is supposed to work: I am a bit on shaky ground here, but from my understanding, only the following go through RNA to write to data (in most scenarios): - Python API - User Interface - Animation System (check https://wiki.blender.org/wiki/Source/Architecture/RNA also) The transform system doesnt really go through RNA iirc, so subscribing wont succeed here. Definitely going to let @ideasman42 decide on this [also on the following suggestion as a workaround]: If msgbus does not handle all updates, do we have to rely on `handlers` here (less elegant, probably less performant as well...)? ``` import bpy from mathutils import * ob = bpy.context.object ob["locstore"] = ob.location def my_handler(scene): loc_old = Vector(ob["locstore"]) if loc_old != ob.location: ob["locstore"] = ob.location print('Object "{}" changed its location to: {}: '.format( ob.name, ob.location) ) bpy.app.handlers.depsgraph_update_post.append(my_handler) ``` Maybe this also belongs more to devtalk, there is a similar thread open, see https://devtalk.blender.org/t/using-bpy-msgbus-subscribe-rna

Note that this is a general issue for operators that access struct members directly, not via RNA.

In this case we can get the transform system to send the message that the object location changed.

Note that this is a general issue for operators that access struct members directly, not via RNA. In this case we can get the transform system to send the message that the object location changed.
Member

Think we can call this a Known Issue for the time being (this is not really a bug)

Think we can call this a Known Issue for the time being (this is not really a bug)
Philipp Oeser changed title from bpy.msgbus.subscribe_rna to bpy.msgbus.subscribe_rna doesnt trigger with the transform system 2020-05-12 15:46:48 +02:00

Added subscriber: @timodriaan

Added subscriber: @timodriaan

Added subscriber: @iss

Added subscriber: @iss

Changed status from 'Needs Developer To Reproduce' to: 'Confirmed'

Changed status from 'Needs Developer To Reproduce' to: 'Confirmed'

Confirming since the issue is classified

Confirming since the issue is classified

Added subscriber: @randum

Added subscriber: @randum
Philipp Oeser removed the
Interest
Modeling
label 2023-02-09 15:29:32 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#72109
No description provided.