# Changing CyclesObjectSettings from a script and update the viewport

I thought it was going to be an easy one for my first ever script but boy was I wrong. All I wanted was a script that creates a basic plane and set it to be a Shadow Catcher so I wrote this basic code:

import bpy

# Create plane
size=10, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

# Set plane to be a shadow catcher
bpy.context.scene.render.engine = 'CYCLES'


This worked for creating the plane and setting the values but the results are not represented in the view port, It does work when rendering but I would like to be able to preview it. I've read about

bpy.context.scene.update()


and that it was later replaced by:

bpy.context.view_layer.update()


Since it is also mentioned in the Stale Data entry in the API documentation I've tried and implement a view layer update like so:

import bpy

# Create plane
size=10, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

# Set plane to be a shadow catcher
bpy.context.scene.render.engine = 'CYCLES'

# Update view layer
bpy.context.view_layer.update()


but I don't see any difference. I wonder whether I'm not implementing the update() function correctly or whether it's not the problem in the first place, any help would be greatly appreciated.

You can just call Object.update_tag() to update the actual display data:

import bpy

C = bpy.context

# Set the engine to cycles
C.scene.render.engine = 'CYCLES'

# Create the primitive