Maniphest T61838

Can't activate all Cycles Render Devices from script on first try
Closed, Archived

Assigned To
Oleg (DotBow)
Authored By
Oleg (DotBow)
Feb 22 2019, 7:35 AM
Tags
  • BF Blender
  • Add-ons (Community)
Subscribers
Oleg (DotBow)

Description

System Information
Operating system: Windows 10
Graphics card: NVIDIA GTX 950

Blender Version
Broken:
2.80, 9541ce2c261b, blender2.8, 2019-02-21

Short description of error
Don't know is this a bug or not, got script from here: T54099. Can't activate all Cycles Render Devices from script on first try.

import bpy

class TOPBAR_OT_load_dotbow_config(bpy.types.Operator):
    bl_idname = "wm.load_dotbow_config"
    bl_label = "Load DotBow Config"

    def execute(self, context):
        # bpy.ops.wm.read_factory_settings()

        scene = bpy.context.scene
        scene.cycles.device = 'GPU'

        prefs = bpy.context.preferences
        cprefs = prefs.addons['cycles'].preferences

        # Attempt to set GPU device types if available
        for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):
            try:
                cprefs.compute_device_type = compute_device_type
                break
            except TypeError:
                pass

        # Enable all CPU and GPU devices
        for device in cprefs.devices:
            device.use = True

        # bpy.ops.wm.save_homefile()

        return {'FINISHED'}


def menu_func(self, context):
    layout = self.layout
    layout.operator(TOPBAR_OT_load_dotbow_config.bl_idname)


classes = (
    TOPBAR_OT_load_dotbow_config,
)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.TOPBAR_MT_file.prepend(menu_func)


def unregister():
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)
    bpy.types.TOPBAR_MT_file.remove(menu_func)


if __name__ == "__main__":
    register()

Exact steps for others to reproduce the error
Add script to Text Editor and run it.
Open file menu in topbar -> Press Load DotBow Config -> Check Cycles Render Devices in settings, only GPU is selected.
Repeat steps and check Cycles Render Devices again - all devices active.

Related Objects

Mentioned Here
T54099: Force GPU rendering python script
rB9541ce2c261b: Missed last commit

Event Timeline

Oleg (DotBow) created this task.Feb 22 2019, 7:35 AM
Oleg (DotBow) updated the task description.
Oleg (DotBow) changed the task status from Unknown Status to Archived.Mar 4 2019, 8:21 PM
Oleg (DotBow) claimed this task.

Ok, found solution:

bpy.context.preferences.addons['cycles'].preferences.get_devices()

Just force cycles to update devices!