How to change View3DShading type in 2.8?


#1

I want to change the shading type to MATERIAL: https://i.imgur.com/U58tSmu.png
How can I do this with a script?
Thanks!

Edit: I figured it out:

for area in context.screen.areas:  # iterate through areas in current screen
    if area.type == 'VIEW_3D':
        for space in area.spaces:  # iterate through spaces in current VIEW_3D area
            if space.type == 'VIEW_3D':  # check if space is a 3D view
                space.shading.type = 'MATERIAL'  # set the viewport shading to material

#2

I’m dealing with a similar issue here regarding View3DShading. I’m wondering, does this procedure is the only way to pinpoint the ‘destination’ of the action, or is there a specific way to target it directly?

Say, like typing bpy.context.screen.View3DShading.shading.type, in this case. (which doesn’t work, hence my question)

By repurposing your code I can achieve what I’m trying to do, but I’m clearly new to this and I don’t want to just copypaste the whole thing so I’m trying to wrap my head around how it all works.

Brute-force method is pretty tedious at the moment :smiley: