1
$\begingroup$

Not sure how best to do this...

I have a very simple question. When I click on the solid view icon in the window I see the console shows:

bpy.context.space_data.shading.type = 'WIREFRAME'

But when I add that to the Text Script window:

import bpy
bpy.context.space_data.shading.type = 'WIREFRAME'

It of course doesn’t run because it doesn’t have the proper context. I also tried:

import bpy

prev_type = bpy.context.area.type
bpy.context.area.type = 'VIEW_3D'
bpy.context.space_data.shading.type = 'SOLID'
bpy.context.area.type = prev_type

which doesn’t throw an error, but doesn’t work either. I know it must be something simple, but how to fix this? Thanks!

$\endgroup$
0

1 Answer 1

2
$\begingroup$

Screen is divided into areas.

An areas active space, matches area type.

2nd script will set the 3d view in that space to solid shading, change text editor to 3d view to confirm.

To set 3dviews in context screen, find them first

spaces3d = [a.spaces.active for a in context.screen.areas if a.type == 'VIEW_3D']
for s in spaces3d: 
    s.shading.type = 'SOLID'

If there are more than one view 3d open, you may wish to only set the largest area, can sort the list by area area (a.width * a.height)

$\endgroup$
4
  • 1
    $\begingroup$ This question could benefit from this answer too. $\endgroup$
    – brockmann
    Commented Mar 2, 2020 at 12:28
  • $\begingroup$ Cheers, did a cursory search, , close enough to dupe to mark as dupe don't you think $\endgroup$
    – batFINGER
    Commented Mar 2, 2020 at 12:34
  • $\begingroup$ Thanks, how would I use only one (any one) of multiple VIEW_3D areas? Do I set a counter and check it in the for loop, or is there a simpler way? $\endgroup$ Commented Mar 2, 2020 at 12:50
  • $\begingroup$ spaces3d[0] is the first. s = spaces3d.pop() is the last "popped off" the list. See python docs on list type. $\endgroup$
    – batFINGER
    Commented Mar 2, 2020 at 12:53

Not the answer you're looking for? Browse other questions tagged .