As I make myself comfortable scripting in Blender I use the Scripting workspace: the Text Editor and Python Console in particular.

I've noticed that the Text Editor uses 4 spaces for indentation while the Console uses 5 somehow. This makes it cumbersome to copy tested snippets from Console into Text Editor as I need to manually edit every single indentation. Here is a short sample copied from Console:

 for o in C.view_layer.objects:
...     print(o.name)

Is this normal behaviour ? Is it possible to change Console's indentation to 4 spaces instead of 5 ? What is the recommended workflow that would allow consistent copy/pasting between Console and Text Editor ? (Note this is on Windows 10 using Blender 2.82a)


1 Answer 1


The indent is 4 spaces.

enter image description here

The console indent is 4 spaces.

>>> C.space_data.prompt
'>>> '

The prompt is ">>> " notice the space at the end, you are counting it as being in indent. Can select console code and choose "Copy as script" effectively chopping length of prompt from start of each line.

Copy from image pasted here

import bpy
from bpy import data as D
from bpy import context as C
from mathutils import *
from math import *

#~ PYTHON INTERACTIVE CONSOLE 3.8.2 (default, Apr  2 2020, 03:24:36)  [GCC 7.5.0]
#~ Builtin Modules:       bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.context, bpy.utils, bgl, blf, mathutils
#~ Convenience Imports:   from mathutils import *; from math import *
#~ Convenience Variables: C = bpy.context, D = bpy.data
for i in range(20):

Notice it copies all the console buffer and adds the imports, not just the selection.

Would be simple enough to use standard copy and chop 4 from each line of the clipboard.

>>> for line in C.window_manager.clipboard.split("\n"):
...     line[4:]
'for i in range(20):'
'    print(i)'

  • $\begingroup$ I am so happy I was so wrong :) Thank you so much for the detailed explanation (+1). Would it be possible to copy the Console text selection as a script (as opposed to the whole content) ? $\endgroup$ May 30, 2020 at 13:18

You must log in to answer this question.

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