I so wanted code completion when tinkering with blender python api that I took the plunge and repurposed sphinx_doc_gen.py - script used for the api docs generation - to generate .pypredef files for Pydev. So if it’s in the docs, code completion should be now available.
This will generate, alongside the script, a folder named pypredef_bpy_api_version.
This folder contains the necessary files to enable code completion for bpy, blf and mathultils modules within pydev.
How to:
In Eclipse:
Window > Preferences…
Preferences > Pydev > Interpreter-Python
Python Interpreters > Predefined > New…
Select Folder then Apply
Notes:
bgl, aud and bge modules are not currently supported
code completion is not exhaustive, parts of the api are not documented. In doubt, check the online docs
Examples:
obj = bpy.context.active_object
# code completion will also work for obj
obj = bpy.context.selected_objects[0]
# code completion doesn't work for obj.
# but you can assert the type of obj
assert isinstance(obj,bpy.types.object)
# and now code completion will work as expected for obj
Files:
The attached archive contains:
pydev_pypredef_gen.py : script to generate the .pypredef files
a folder containing pre-generated .pypredef files for the python api corresponding to the 2.57b release
Thanks a lot! I was already looking for a way to generate blender API stub classes to make autocomplete work in pyDev. You have saved quite some time for me with this. Currently I am testing what possible problems can be in this approach, and found something in my current script. Seems like there is a problem with altering existing types and autocomplete, for example:
In this case, whan typing last line “evil_global” is recognised and and even available in autocomplete. But after validating the file it is marked as error (since original Scene object has no such member). Any ideas about solution for that?
Anyway, you did a great job and this was another step towards normal workflow for developing blender extensions.
i just ran the script on a fresh svn update
and i wonder why the first 2 lines in the def draw() compile
and the third line doesn’t …
import bpy
def draw():
ms = bpy.data.meshes
me = ms.new("compiles")
otherMe = bpy.data.meshes.new("doesntCompile")
"""
Description Resource Path Location Type
Undefined variable from import: new blender.py /blender_pydev/src line 7 PyDev Problem
"""
if __name__ == "__main__":
draw()
any explanations ?
i ran the script on a fresh svn update of the blender sourcecode
and it created the folder ‘pypredef_bpy_2_58_1_r37811’
this script causes error for me. do you have any idea?
c:\Graphics\Blender258>blender --background --python pydev_pypredef_gen.py
Info: Config directory with “startup.blend” file not found.
found bundled python: c:\Graphics\BLENDE~3\2.57\python
Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “<string>”, line 1054, in <module>
File “<string>”, line 1048, in main
File “<string>”, line 375, in rna2pypredef
File “<string>”, line 207, in pycontext2pypredef
File “c:\Graphics\BLENDE~3\2.57\python\lib\ctypes_init_.py”, line 340, in _ init_
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
It is a perfect case of paralel development!
On march-april 2011 I adapted the same script for the same purpose! Mine is named pypredef_gen.py. It has been added and described in this free book: http://airplanes3d.net/pydev-000_e.xml
Becasue I use Windows, I can explain atmuc and sc3sc3 their problems:
Original Campbell Barton’s script used a kind of hack to read the alternative context structures (this structure has a different fields in different windows - a thing that is impossible to match properly with PyDev autocompletion). It tries to use current executable (blender.exe) as an unnamed shared object (a dynamic link library) and read the context structures directly from the structures that are exposed as public part of this shared binary code. This hack does not work in Windows, unfortunately. In my version of the script I have just skipped creation of this small part. You will find it in the file that accompanies the book, and the book contains detailed description how to generate the *.pypredef files, along with easier debugging of Blender scripts…
Pydev actually does not need anything if Blender is compiled as Python module and installed into Python folder, in fact it has the best working completion for Blender stuff. All the other ones I myself tried (VsCode, Pycharm etc) sucked to death.
Well I’m using this for PyCharm in conjunction with my script that fixes some things produced by running blender against file linked above and I’m more than happy for several years already.