Property controlled drivers not updating from python #74000

Closed
opened 2020-02-19 10:43:00 +01:00 by Shay Gusin · 17 comments

System Information
Operating system: MacOS / Unbuntu 18.04
Graphics card: Mac / Nvidia 2080TI

Broken: 2.82.7
Worked: 2.79.7

I have custom property that controls a driver.
there are couple of meshes that change visibility depending on the property value.
When manually changing the custom property value everything works perfectly.
The problem happens when accessing the custom property from python code, and changing the value,
the value on the property changes but the visibility of the meshes controlled by the drivers does not change.
Also on the outliner there's no change in the visibility indication of the meshes.

Expected behaviour:
When changing the property from python code, one mesh becomes invisible and another becomes visible.

**System Information** Operating system: MacOS / Unbuntu 18.04 Graphics card: Mac / Nvidia 2080TI Broken: 2.82.7 Worked: 2.79.7 I have custom property that controls a driver. there are couple of meshes that change visibility depending on the property value. When manually changing the custom property value everything works perfectly. The problem happens when accessing the custom property from python code, and changing the value, the value on the property changes but the visibility of the meshes controlled by the drivers does not change. Also on the outliner there's no change in the visibility indication of the meshes. Expected behaviour: When changing the property from python code, one mesh becomes invisible and another becomes visible.
Author

Added subscriber: @shayg

Added subscriber: @shayg
Member

Added subscriber: @Mets

Added subscriber: @Mets
Member

Probably same underlying issue as studio/blender-studio#73593?

Probably same underlying issue as studio/blender-studio#73593?

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

Changed status from 'Confirmed' to: 'Needs User Info'

Changed status from 'Confirmed' to: 'Needs User Info'

@shayg please provide a minimal blend file that demonstrates the issue.

@shayg please provide a minimal blend file that demonstrates the issue.
Author

Food_Apple.blend

Attached is the file for which there's a problem.
Also this is the code to run:

import bpy
import bmesh

context = bpy.context

apple = bpy.context.scene.objects['controler']

apple['change_model'] = 5
context.scene.frame_set(0)

[Food_Apple.blend](https://archive.blender.org/developer/F8366252/Food_Apple.blend) Attached is the file for which there's a problem. Also this is the code to run: ``` import bpy import bmesh context = bpy.context apple = bpy.context.scene.objects['controler'] apple['change_model'] = 5 context.scene.frame_set(0) ```

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'
Sybren A. Stüvel self-assigned this 2020-02-25 12:47:55 +01:00

That blend file (Food_Apple.blend) is set up incorrectly; the custom property is set on the Scene, but the driver is accessing it on the Object. I have corrected this in #74000-visibility-driver.blend.
The code also doesn't work with that blend file:

>>> apple = bpy.context.scene.objects['controler']

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
KeyError: 'bpy_prop_collection[key]: key "controler" not found'

But I get the gist of your report.

The thing is that assignments to custom properties don't tag the object for updates in the dependency graph. Since tagging for update on an object is expensive (it recalculates the constraints, modifiers, and thus the geometry) this is not done automatically from Python assignments. This code works in the attached blend file in the Python console:

# The file is saved with ['hidden'] = 0 and the Cube as the active object.
C.object['hidden'] = 1
C.object.update_tag()
C.scene.frame_set(C.scene.frame_current+1)

Marking as 'invalid' as this is not a bug in Blender.

That blend file (Food_Apple.blend) is set up incorrectly; the custom property is set on the Scene, but the driver is accessing it on the Object. I have corrected this in [#74000-visibility-driver.blend](https://archive.blender.org/developer/F8369224/T74000-visibility-driver.blend). The code also doesn't work with that blend file: ``` >>> apple = bpy.context.scene.objects['controler'] Traceback (most recent call last): File "<blender_console>", line 1, in <module> KeyError: 'bpy_prop_collection[key]: key "controler" not found' ``` But I get the gist of your report. The thing is that assignments to custom properties don't tag the object for updates in the dependency graph. Since tagging for update on an object is expensive (it recalculates the constraints, modifiers, and thus the geometry) this is not done automatically from Python assignments. This code works in the attached blend file in the Python console: ``` # The file is saved with ['hidden'] = 0 and the Cube as the active object. C.object['hidden'] = 1 C.object.update_tag() C.scene.frame_set(C.scene.frame_current+1) ``` Marking as 'invalid' as this is not a bug in Blender.
Author

Hi @dr.sybren, thanks for the update.

Is there a reason to move to the next frame?
As I understand the setting the current frame will also trigger an update.
Also the actual file is more complex, drivers control more than one object so when performing what you suggest some objects that supposed to appear remain hidden and others.
So if I want to control the top of the apple when I switch the property, sometimes the apple appears without the top at all.

Hi @dr.sybren, thanks for the update. Is there a reason to move to the next frame? As I understand the setting the current frame will also trigger an update. Also the actual file is more complex, drivers control more than one object so when performing what you suggest some objects that supposed to appear remain hidden and others. So if I want to control the top of the apple when I switch the property, sometimes the apple appears without the top at all.

In #74000#879987, @shayg wrote:
Is there a reason to move to the next frame?
As I understand the setting the current frame will also trigger an update.

I didn't test with the current frame.

Also the actual file is more complex, drivers control more than one object so when performing what you suggest some objects that supposed to appear remain hidden and others.
So if I want to control the top of the apple when I switch the property, sometimes the apple appears without the top at all.

The object to tag for update is the object that contains the custom property. Drivers that depend on that property value should all be automatically updated.

> In #74000#879987, @shayg wrote: > Is there a reason to move to the next frame? > As I understand the setting the current frame will also trigger an update. I didn't test with the current frame. > Also the actual file is more complex, drivers control more than one object so when performing what you suggest some objects that supposed to appear remain hidden and others. > So if I want to control the top of the apple when I switch the property, sometimes the apple appears without the top at all. The object to tag for update is the object that contains the custom property. Drivers that depend on that property value should all be automatically updated.

Added subscriber: @elie

Added subscriber: @elie

I am experiencing similar issue with object drivers targetting scene properties. Unfortunately calling scene.update_tag() does not trigger the update of object's driven attributes.

edit: my issue was that the 3D view was not redrawn, so I added:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        area.tag_redraw()
I am experiencing similar issue with object drivers targetting scene properties. Unfortunately calling `scene.update_tag()` does not trigger the update of object's driven attributes. edit: my issue was that the 3D view was not redrawn, so I added: ``` for area in bpy.context.screen.areas: if area.type == 'VIEW_3D': area.tag_redraw() ```

Added subscriber: @spiraloid-3

Added subscriber: @spiraloid-3

here's a hacky catchall I used to force an update when all the other solutions failed me.

  for obj in bpy.context.scene.objects:
      obj.hide_render = obj.hide_render
here's a hacky catchall I used to force an update when all the other solutions failed me. ``` for obj in bpy.context.scene.objects: obj.hide_render = obj.hide_render

Added subscriber: @Harry-Kunz

Added subscriber: @Harry-Kunz
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
7 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#74000
No description provided.