Maniphest T76174

bpy.app.handlers Works fine in the view port and depsgraph but not when rendering.
Closed, Archived

Assigned To
Philipp Oeser (lichtwerk)
Authored By
Ryan Brunette (Cabbage_94)
Apr 28 2020, 10:33 AM
Tags
  • Python API
  • Dependency Graph
Subscribers
Philipp Oeser (lichtwerk)
Robert Guetzkow (rjg)
Ryan Brunette (Cabbage_94)

Description

System Information
Operating system: Windows-10-10.0.18362-SP0 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 445.75

Blender Version
Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-02-12 16:20, hash: rB77d23b0bd76f
Worked: (optional)

Short description of error
I have made myself an addon that controls an objects scale based off of 2 custom properties.
this code runs every frame change and during depsgraph updates. Every thing works fine even when key framing these custom properties,
but not while rendering.

Exact steps for others to reproduce the error
Here is the addon in full.


The code that is run on every frame change is on line 165 and is appended to the handler at line 310.

Everything in the view port seems to work perfectly.

And just for debugging purposes a added some print commands in my code at various steps.

So when I hit render whether I'm using eevee or cycles I get a console that says its executing my code and a render that does not reflect that.
The Console


The render result. Object stays the same size as last seen in the viewport.

I have tried using different handlers like render_pre, but no luck.
This is most likely something stupid in my code as I only started a week ago. For now I'm reporting this as a bug either in blender or the blender API documentation.

Event Timeline

Ryan Brunette (Cabbage_94) created this task.Apr 28 2020, 10:33 AM
Philipp Oeser (lichtwerk) closed this task as Archived.Apr 28 2020, 11:37 AM
Philipp Oeser (lichtwerk) claimed this task.
Philipp Oeser (lichtwerk) edited projects, added Python API, Dependency Graph; removed BF Blender.
Philipp Oeser (lichtwerk) added a subscriber: Philipp Oeser (lichtwerk).

Have a look at T71234: Custom property doesnt update when rendering animation also.
Or here (under Handlers): https://wiki.blender.org/wiki/Reference/Release_Notes/2.81/Python_API

Basically it boils down to having to do something like this instead:

@persistent
def test_func(scene, depsgraph):
    obj_list = [obj for obj in bpy.data.objects if "sTag" in obj]
    print("About to update all objects")

    for i in obj_list:
        # access evaluated objects prop [these are updated fine in frame_change_post]
        i_eval = i.evaluated_get(depsgraph)
        mx = i_eval["Max_x_Dimension"]
        my = i_eval["Max_y_Scale"]
        a = 0.0
        i_eval.dimensions[0] = mx
        if i_eval.scale[0] > my:
            a = my
        else:
            a = i_eval.scale[0]
        # alter original object
        i.scale[0] = a
        i.scale[1] = a

    print("Updated " + str(len(obj_list)) + " objects")
    
    return {'FINISHED'}

Also (I think) you have to use the _post handler (instead of the _pre)...
(just check the file, I have updated this for you...)

Think we have to close this (feel free though to comment again if issues persist...)

Robert Guetzkow (rjg) added a subscriber: Robert Guetzkow (rjg).EditedApr 28 2020, 11:40 AM

This is most likely something stupid in my code as I only started a week ago. For now I'm reporting this as a bug either in blender or the blender API documentation.

The bug tracker is not meant for help with add-on development, it's for bugs only. If you need help with your add-on development, please ask a question on one of our community websites, e.g. blender.chat python channel, blenderartists.org or Blender's StackExchange.

As @Philipp Oeser (lichtwerk) explained, you need to use the evaluated dependency graph when modifying the objects while rendering. This is has also been answered on Blender's StackExchange.