2
$\begingroup$

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_circle")
        layout.operator("mesh.looptools_curve")
        layout.operator("mesh.looptools_flatten")
        layout.operator("mesh.looptools_gstretch")
        layout.operator("mesh.looptools_bridge", text="Loft").loft = True
        layout.operator("mesh.looptools_relax")
        layout.operator("mesh.looptools_space") 

enter image description here

$\endgroup$
  • $\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
2
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you. The only solution which worked for me. On top of it, I have added a package for AutoPep8 package in sublime $\endgroup$ – Lizesh Shakya Jun 23 at 23:12
1
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\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
0
$\begingroup$

That's no longer the case at least from blender 2.81 (could be also from lower versions) Open the Text Editor and when you want to execute press ALT+P (or in the menu Text > Run Script)

Also, since now it's not the Python Console, all the errors/prints will be in the System Console (Window > Toggle System Console) And make sure you import what's needed (e.g. import bpy)

Tip: You can also turn on Live Edit

| improve this answer | |
$\endgroup$
  • $\begingroup$ I believe the question is re pasting code into blenders python console. $\endgroup$ – batFINGER May 24 at 7:51
  • $\begingroup$ Yes, it's about running the code in the scene exactly as I was needed to do when finding this question. And while testing more after coming here I found out this method is a great solution for it. $\endgroup$ – Ido May 24 at 20:29
  • $\begingroup$ It is still the case in 2.8 that if you paste the script from Q into py console it won't work. $\endgroup$ – batFINGER May 25 at 7:11
  • $\begingroup$ I'm not you understood my answer $\endgroup$ – Ido May 25 at 20:09
  • $\begingroup$ I understand your answer thankyou fpr asking.. Whereas, I'm not sure you understand the question. Please re-read. Debugging using prints in text editor, sure, but it's not an interactive py console. ie you have no access to local variables after the script has run. If the blank line is removed from script above it runs when pasted in console. The class is available to tinker with and examine, register and unregister etc. $\endgroup$ – batFINGER May 25 at 20:50

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.