Can't activate all Cycles Render Devices from script on first try #61838

Closed
opened 2019-02-22 07:35:47 +01:00 by Oleg · 3 comments

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: studio/flamenco#54099. 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.

**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: studio/flamenco#54099. 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.
Author

Added subscriber: @DotBow

Added subscriber: @DotBow
Author

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Oleg closed this issue 2019-03-04 20:21:12 +01:00
Oleg self-assigned this 2019-03-04 20:21:12 +01:00
Author

Ok, found solution:

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

Just force cycles to update devices!

Ok, found solution: ``` bpy.context.preferences.addons['cycles'].preferences.get_devices() ``` Just force cycles to update devices!
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 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-addons#61838
No description provided.