# [Addon] Auto Completion in Blenders Text Editor

Looks nice and will be handy for folks who don’t want to use a separate IDE.

A little offtopic I guess, but as nice as this is I would absolutely kill for an embedded console (iPython?) with syntax highlighting and tab completion.

But jedfrechette,

A little offtopic I guess, but as nice as this is I would absolutely kill for an embedded console (iPython?) with syntax highlighting and tab completion.

What do you mean clearly, please?

After using an advanced Python console like iPython it’s just really hard to go back to the basic Python console that Blender includes.

Yes I know Ctrl+Space autocompletes in Blender, but every other console I’ve ever used uses Tab so I never remember Ctrl+Space. iPython also does simple things like syntax hightlighting for exceptions so it is easier to see what when wrong. Probably it’s best feature though is that it makes it really easy to explore your objects. Calling ‘foo?’ will print the doc strings and a bunch of other info about the object so you spend less time searching through documentation in a browser window. It also has a bunch of other useful stuff from simple benchmarking and debugging to a much nicer history than the default shell all the way up to some pretty advanced magic that I’ve rarely touched. All in all it just makes it much nicer to use Python interactively.

Ok Jed and I have a question: I have installed ipython with ancaconda bundle for windows but the script ipythonforBlender doesn’t run because Blender use embended python and not pyhton from my Vista…Sniff…Sniff!

You are on linux, I mean!..because the script run well…

The indication I got was
<!> event has invalid window
in the shell I use to start Blender

A lot of code completion I do already in emacs with an python code completion ectra *.el files …
But having it in the text-view of Blender is fine too

Good idea and work, thanks!

Oh, I am a fan of IPython too
Using
ipython notebook

If that could be combined with Blender ???

Yes PKHG you can use this:

with this, you have auto-completion in the bpy…
amazing when it run, on windows it’s not easy…

hey all, thanks for the feedback and ideas, but it would really help if you can provide an example video that shows the behavior you like

Got it

But not yet totally working and how it works with or inside Blender?


PS C:\Users\Peter\Documents\Blender\blender_ipython-master&gt; .\blender_ipython.py notebook
2014-12-03 16:44:03.703 [NotebookApp] Using existing profile dir: 'C:\\Users\\Peter\\.ipython\\profile_default'
2014-12-03 16:44:03.727 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2014-12-03 16:44:03.820 [NotebookApp] Serving notebooks from local directory: C:\Users\Peter\Documents\Blender\blende
python-master
2014-12-03 16:44:03.823 [NotebookApp] 0 active kernels
2014-12-03 16:44:03.830 [NotebookApp] The IPython Notebook is running at: http://localhost:8888/
2014-12-03 16:44:03.832 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip conf
ation).
2014-12-03 16:44:11.123 [NotebookApp] ERROR | Unhandled error in API request
Traceback (most recent call last):
File "D:\Python34\lib\site-packages\IPython\html\base\handlers.py", line 286, in wrapper
result = method(self, *args, **kwargs)
File "D:\Python34\lib\site-packages\IPython\html\services\sessions\handlers.py", line 65, in post
kernel_id = km.start_kernel(path=path)
File "D:\Python34\lib\site-packages\IPython\html\services\kernels\kernelmanager.py", line 90, in start_kernel
kernel_id = super(MappingKernelManager, self).start_kernel(**kwargs)
File "D:\Python34\lib\site-packages\IPython\kernel\multikernelmanager.py", line 116, in start_kernel
km.start_kernel(**kwargs)
File "D:\Python34\lib\site-packages\IPython\kernel\manager.py", line 217, in start_kernel
**kw)
File "D:\Python34\lib\site-packages\IPython\kernel\manager.py", line 173, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "D:\Python34\lib\site-packages\IPython\kernel\launcher.py", line 247, in launch_kernel
stdin=_stdin, stdout=_stdout, stderr=_stderr, cwd=cwd, env=os.environ)
File "D:\Python34\lib\subprocess.py", line 848, in __init__
restore_signals, start_new_session)
File "D:\Python34\lib\subprocess.py", line 1104, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is geen geldige Win32-toepassing
"Content-Length": "49",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Origin": "http://localhost:8888",
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safa
537.36",
"Accept-Encoding": "gzip,deflate",
"Accept-Language": "nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Host": "localhost:8888",
"X-Requested-With": "XMLHttpRequest",
"Connection": "keep-alive",
"Referer": "http://localhost:8888/notebooks/Untitled0.ipynb"
}
ERROR:tornado.access:500 POST /api/sessions (::1) 127.09ms referer=http://localhost:8888/notebooks/Untitled0.ipynb



I installed the addon with no errors and activated it, but when I start typing I get no auto-completion and when I next move the mouse I get this error:

What have I done wrong?

Hey PKHG: Do you it on Linux?

Like this:

http://www.blender.org/forum/profile.php?mode=viewprofile&u=1891&sid=1805f5dc91b3e66d94d54a2e5e3becdc
and his mail: Mathias Panzenböck (Panzi) <[email protected]>

http://hackworthy.blogspot.fr/

I have send him a need of tuto about…Wait and see.

Hi @Gcs_dev,

If you have downloaded the script recently from Github, you must remove “-ai” at the end of the name of the folder.
You must have “script_auto_complete” only!

I did get it from Github but the folder didn’t have “-ai” at the end. It did have “-master” though, which I removed following a post from the beginning of this thread. It didn’t solve the error though.

Jacques Lucke: your amazing work reminded what is so cool in a user point of view with Blender and especially Python: Every time you want to create something new and useful, because you need it, it already exist ^^.
That cool from a user, and sometimes developer point of view, but it also a bit frustrating: As a developper, I can never do something useful that already exist ! ^^
Let me explain what I mean: I was working exactly on the same thing for about 3 weeks, and I just had some working code when you opened that topic

Another project that will go to my computer’s trash

Amazing work, keep going with that kind of stuff. Thanks a lot !!

I will delve deeply into your code to see how you did that, because I was trying to re-use the console autocompletion code, and taht was a kind of big deal.

About the code that pitiwazou shared with you, it’s just a realy simple pie menu I use for my coding stuff, the only things that can be interesting for you are the BetterComment (and derivatives): these operator replace the default one, and avoid some “issues”.
For instance, when you try to use the comment operator, it will not work if you do not have selected at least 1 character in 1 line. It’s not so usefull, and especially when you are conding something with your 2 hand on the keyboard, it’s so long to do.
With the BetterComment, it just works

If you want some help to extend you add-on (but I’m sure you do not need that anymore ! ), let me know

Hi Jacques.

Do you think it would be possible to nest the same Blender search window afterwards?

@Gcs_dev: I think I fixed this now. The reason for the problem is basicly the same that Spirou4D mentioned but slightly different. I hope it works with a new Version.
Those things are always a bit harder to test as I have to do this on another computer.

@lapineige: Thanks. I found no other auto completion addon for blender and you can be sure a searched it.
I always try to do something ‘new’ as you may see with the other addons I worked on in the last few months.
Maybe you can show you code a bit? on github or so

Let me explain how I did this basicly, so you don’t have to go through the whole code.

I found reusing the console autocompletion too hard, as I can’t customize it in any way (in fact I didn’t use this console ever before )
I wanted to have the whole api accesable very easily to always show relevant information. The biggest problem is, how can the addon know which object type a certain variable contains because you don’t have to declare this at any point. So everything my addon does is guessing. This works the following way:

1. Find the ‘parent’ variable name. e.g.: “bpy.context.screen.” -> “screen”
2. Search through all types in bpy.types and check if this word exists as property somewhere. e.g. “screen” is a property of “Context” and “Window”
3. Then find out which types this word can be possibly. e.g. if you write parent, this can mean that it is one of the following types: “MaskParent”, “Bone”, “PoseBone”, “Node”, “EditBone”, “String”, “Library” or “Object”
4. get all possible ‘subproperties’ and show them in the list + filter them before by the already written characters

I know the suggestions I get this way aren’t perfect, but it’s absolutely better than nothing and most of the time you know what you want to write but forgot the correct spelling or so.
Maybe I can improve this later so that in “context.area.” area gets only recognized as “Area” and not as float that holds the area of a face in a mesh.

An obvious problem is that these steps have to be very fast. For this reason I’m kind of caching the whole api to get very fast access to every single aspect like data types, function name/parameters/returns, descriptions, …
This caching process takes about a second.

Here is an example how I can access certain things:


doc = Documentation()
doc.build()
doc.get_possible_property_types("location") -&gt; "Float Vector 3", "Boolean", "Integer Vector 2", "Float Vector 2"
doc.get_function_names_or_type("BlendDataObjects") -&gt; "new", "remove", "tag"



This way it’s very easy to get the information. Now I only have to draw it in a nice way on the screen.

I hope this helps you to understand how it works

Oh yeah ! That simply clever: as python do, if it looks like a duck, it’s a duck ^^
I guess you also use the type fonction.

I have no interesting code to show, because I just have some working code for some particular code.
In fact, I choosed what appeared to be a lazy solution, I tried to re-use the console code.
And yeah, that’s realy long to make that stugf working in the text editor

But before putting it in the trash, I think I will try to finish that, to make a proof-of-concept (or just for fun ^^).

I found no other auto completion addon for blender and you can be sure a searched it.

In fact, 1 guys tried to do what I’m doing for the 2.57 version. But it’s not working anymore in recent version.

I was saying that not to say that you do not search before doing that. I just said that there is a “syndrome” with python, everytime you want to do something new, it already exist !

I don’t know so much about your coding stuff, I just tried your amazing animation tools (yeah, amazing).
For my part I just tested the PyNodes, and I realy not understood the (too) small documentation about them

@Gamel: Actually I don’t know if this is possible, because I’m not using the standard ui elements.
If the possibilty exists I can change that later. The drawing code is totally seperated from the code that makes the suggestions

I’m pretty sure you can use it

Here are some updates of today. I rewrote the drawing code to have a cleaner ui.
Also you can scroll through the suggestion list now and there is a new template for the bl_info dictionary.

One functionality I really miss here in Blender is the ability to set the text cursor position via Python. The way I do this now is veryy hacky (writing a certain string and then find-replace it with the normal operator)…
Maybe someone knows a better way?