1
$\begingroup$

I can successfully controll the grid_scale & grid_lines in bpy.types.SpaceView3D.

I know this, because the console tells me that my input has been recieved, for example, when I write: bpy.types.SpaceView3D.grid_lines the console prints my new value.

But here's my question: Why doesn't the values update in the Blender Properties panel, I mean visually in my current scene? (check my print screen you can see the values haven't changed. - that's the problem.)

I'm new to scripting so a simplified answer would be brilliant. Thanks / Danenter image description here

$\endgroup$
2
$\begingroup$

Difference between a class and an instance.

bpy.types.SpaceView3D is a class, it has a grid_lines property. The blender UI has a window, made up of screens, made up of areas, within each area an active space (what you see in that area). The active space in a view 3d area is an instance of the bpy.types.SpaceView3D class.

Running this code in the text editor will change all 3d view spaces grid lines to 10 and scale to 2

import bpy

for screen in bpy.data.screens:
    for area in screen.areas:
        if area.type == 'VIEW_3D':
            area.spaces.active.grid_lines = 10
            area.spaces.active.grid_scale = 2

in the python console the active space is not a 3d view area, rather a python console. Similar to above but in console

>>> type(C.space_data)
<class 'bpy.types.SpaceConsole'>

>>> for i, a in enumerate(C.screen.areas):
...     i, a.type
...     
(0, 'INFO')
(1, 'PROPERTIES')
(2, 'CONSOLE')
(3, 'VIEW_3D')
(4, 'TEXT_EDITOR')

>>> space3d = C.screen.areas[3].spaces.active
>>> type(space3d)
<class 'bpy.types.SpaceView3D'>

>>> space3d.grid_lines = 10

If the code is invoked, via a button or menu (for example), in the context of the 3d view, then the 3D VIEW space would also be context.space_data

$\endgroup$
1
  • $\begingroup$ Brilliant answer! You made me understand what's going on, and thanks for your help, & for the perfect clarity! $\endgroup$ Feb 6 '18 at 19:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.