Hi i have some questions :

  1. i want to paste block of function into the python console and got a lot of indentation error. Is this a bug or do i miss something ? i'm using 2.79.

  2. I'm new in coding. What is the best IDE for doing interactive debugging regarding building python code/function for Blender ?

Anyone can help ?

class VIEW3D_MT_edit_mesh_looptools(bpy.types.Menu):
    """    LOOPTOOLS    """
    bl_idname = "loop.tools" 
    bl_label = "LoopTools"

    def draw(self, context):
        layout = self.layout
        layout.operator("mesh.looptools_bridge", text="Bridge").loft = False
        layout.operator("mesh.looptools_bridge", text="Loft").loft = True

enter image description here

  • $\begingroup$ Suggest use spaces rather than tabs for indent. (there is a convert to spaces on the text editor window) Unfortunately the py console sees the blank line as a full unindent. Related $\endgroup$ – batFINGER May 30 '18 at 11:41
  • $\begingroup$ Thanks , i found the problem. when pasting , Blender won't accept the empty line in the codes (like empty line between that bl_label and def draw). this is strange..... $\endgroup$ – andio May 30 '18 at 13:11
  • 1
    $\begingroup$ Have a look at script in updated addon link It will use the script stub to run the script from the text editor into the py console. The locals from the script are available in the py console. $\endgroup$ – batFINGER May 30 '18 at 14:53

Sadly, this just won't work. Something about cutting and pasting screws up the indentations, replacing spaces with tabs or visa versa, or with nothing. I'm not sure if it's when the external editor/IDE is copying, when the python console is pasting, or in the general copy-paste mechanism. I'm having this problem today on Windows. I don't know if the same happens on Linux; I haven't done any Python scripting for Blender on Linux in a long time.

What I do is write nicely formatted Python in my favorite editor (Notepad++ today, as I'm on Windows), copy it to a blank document in the same editor, remove all the blank lines and comments, then select and paste that code into the console. It's clumsy, tedious grunt work, but I can at least make progress.

The nicely formatted version of the source gets saved to a file, and used as an external script for Blender projects in the future, when I'm no longer doing the R&D.

  • $\begingroup$ Begs the question. Why not paste and run scripts from the text editor? The example script in the question is panel draw code, can't for the life of me think of any reason to run that by pasting in py console.As noted in comment under question: can run external and internal scripts using this handy addon to have results available in the console's locals. $\endgroup$ – batFINGER Aug 4 '18 at 14:32

There is a solution, usually when I encounter this problem, I replace "TAB"'s with spaces. Here is the interesting thing, you can replace a "TAB" with any number of spaces. You could replace a TAB with a single space, or multiple spaces.

Now, for the second part of your question, any text editor that allows you to set "TAB" to spaces, so in "sublime text 3" which I use you would go to "view"->"indentation"->"Indent Using Spaces".

Here is the fun part, "TAB" with in a python file is not a problem for the python interpreter, it works fine. Its just an issue when you pasting to the command line.

Also, I don't know what your question has to do with Blender, this should be an S O question.


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.