I have a script that loads a scene with objects, cameras etc. and also sets the gpu rendering settings. When I use the script up until the rendering command and then click on the render button, the GPU is used. When I use the same script and use the bpy.ops.render.render(write_still=True) command the images are rendered and saved properly, but not with the GPU settings.

Which rendering command does the same as the one I have to click? It isn't the one described when hovering over it.

Parts of code related to gpu and render settings:

# [7.5] Set resolution
bpy.data.scenes["Scene"].render.resolution_percentage = 10
bpy.data.scenes["Scene"].render.tile_x = 512
bpy.data.scenes["Scene"].render.tile_y = 512

# [8] Enable CUDA and activate GPU
# code from https://developer.blender.org/T54099

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

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

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

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

bpy.context.scene.cycles.device = 'GPU'
bpy.data.scenes["Scene"].cycles.feature_set = 'EXPERIMENTAL'

for c in camNames:
    print(c,  r'C:\Users\X\Desktop\3DModels\TestRenderings\\' + model.split('\\')[-1] + '\\' + c + 'image.jpg')
    bpy.data.scenes["Scene"].camera = bpy.data.objects[c]
    bpy.data.scenes['Scene'].render.filepath = r'C:\Users\X\Desktop\3DModels\TestRenderings\\' + model.split('\\')[-1] + '\\' + c + 'image.jpg'
    R = random.uniform(0.0,0.2)
    G = random.uniform(0.0,0.2)
    B = random.uniform(0.0,0.2)

    bpy.data.materials['carpaint_basic'].node_tree.nodes['RGB'].outputs[0].default_value = (R, G, B, 10)


enter image description here

  • 1
    $\begingroup$ bpy.ops.render.render(write_still=True) seems to work when typed into Python Console on Blender 2.97 when I try it with GPU rendering. I see GPU usage going up significantly while rendering. Maybe the problem is in another part of the code or the context it gets executed in. Could you tell more about how you run the code and maybe share the code itself or the relevant part of it? $\endgroup$ – Martynas Žiemys Aug 20 '18 at 10:20
  • $\begingroup$ @MartinZ After further investigation it seems like windows' taskmanager didn't track GPU usage correctly that wasn't on the main screen $\endgroup$ – Bedmobile Aug 20 '18 at 12:23
  • $\begingroup$ For future comerades in suffering: bpy.ops.render.render('INVOKE_DEFAULT', write_still = True) seemingly uses GPU while background renders don't, INVOKE_DEFAULT bascially instructs blender to pretend a user pressed the render button $\endgroup$ – Bedmobile Aug 20 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.