display/shade objects in 3D view

Hi can anybody tell the python commands to switch from texture to solid view. I am trying bpy.types.SpaceView3D.viewport_shade but its not working

Similar to your previous question, you must first get an instance of the SpaceView3D to access its methods and members.

Sorry i am new to blender python what do u mean by instance. I really don’t get it??

this is the solution that i required

import bpy

#bpy.context.scene.game_settings.material_mode = ‘GLSL’
areas = bpy.context.screen.areas
for area in areas:
if area.type == ‘VIEW_3D’:

that’s very cool, and a little confusing.

How did you know you could go “.type” after area?

Trying to autocomplete that in the console shows it’s not in the list, and doesn’t work there either for that matter.


You could see it in the console this way:

scrn = bpy.context.screen.name  #get the current screen name
areas = bpy.data.screen[scrn].areas
area[0].type   #will give you type of first area
for area in areas:
    print(area.type)    #will print type for each area

(by the way this is for the total python beginner like me…)

Thanks for that super rapid reply! There was a couple of typos that screwed me up initially in what you had written but thankfully I punched myself out of that paper bag. :slight_smile:

Also i eventually was able to unlock what i was asking.

bpy.data.screens. - then hitting autocomplete will give a different menu than

similarly it is possible to bring up the ‘.type’ (is it a method, function or class? still getting my head round all this) in the autocomplete list when typing in…

bpy.data.screens[0].areas[0]. - then hitting autocomplete, ‘type’ is then in the list that follows.

what are ‘screens’ or ‘areas’? I mean are they classes? Which contain lists? Hence the square brackets? I’m floundering here obviously. It’s tricky to translate what i’ve learned about python into practical examples for blender i must admit.

I’m intending to rewrite all this up for people like me so hopefully this will help many others to crack into blender python with these sorts of examples. (In addition to the other practical resources like blendercookie of course)

for anyone who is like me…

‘screens’ is referring to the screen layouts that can be selected on the top header bar, usually this boots up with ‘Default’, i’ve switched to ‘scripting’ which makes it number 4 in the list. Hence the number 4 below.

The ‘areas’ is referring to the various window panels that are shown, the 3d view happens to be the 3rd along so is 2 in the list, i.e. [0, 1, 2]

that means this line can be written in the console so long as you’re in the scripting scene layout and be able to switch the shading mode of the 3dview.


In the blender python api searching for the ‘viewport_shade’ function shows the location as -

What does the word ‘space’ represent in the brackets? I was expecting you could go something like…
bpy.types.SpaceView3D(Something here?).viewport_shade=‘WhateverYouLikeHere’.

Can anyone shed some light on this?

Sorry for the obviously beginner-like question and long ramble that this response has turned into, many thanks for reading this far if you made it! :slight_smile:

Thanks again,