3
$\begingroup$

I want to create 2D or 3D object that is mathematically created (all vertices and faces are generated by python). I heard blender can create objects via Python. I already know Python and would like to find more information specifically about bpy.

I assumed blender python API is well documented, but I can't find good documentation (For example, look this page about bpy.data. I think there should be more information about bpy.data.*). Are there any books about blender python which complement official documentation? I don't have much time to search the web (like a sea) to find the documentation about blender python, and I don't know which web resource is the best except for official website. So mainly I'm finding a book about blender python now.

I'm currently reading:

  • The Blender API - Blender 2.49 Scripting

This is the only book I could find. Any other book or web resources are welcome.

$\endgroup$
3
$\begingroup$

Around 2009 / 2010 Blender moved on to the 2.5 series and started using a new and very different python API called bpy. Unfortunately that 2.49 Book doesn't cover bpy and therefore will have little practical usefulness. In the first couple of years after the new 2.5 series bpy changed regularly both in big and in small ways.

Such a fluid environment meant publishing hard-copy documentation wasn't very sensible. This lack of books has not been a barrier for learning bpy, for a few reasons:

  • Blender has a built in Python console (REPL) it lets you print the docstrings of functions and operators. The REPL auto-completes with Ctrl+Space. See this answer for directions and usage and more.
  • Blender, and the add-ons it ships with, are open-source. The nature of these add-ons ranges from convenient mesh editing tools and mesh generation tools to importers and exporters. These categories cover almost everything you might want to see examples of -- some are short and simple others are extensive.
  • The cookbook (for UI and bpy) paved the way for many people, and is still a surprisingly useful reference for figuring out how to declare UI.
  • Blender's TextEditor has templates for common bpy procedures:
    TextEditor > Templates > Python > ...

You mention that you know Python already. My advice to you is to read the source code of a few Mesh creation add-ons available in ../scripts/addons. For instance

add_mesh_extra_objects
add_mesh_bolt_factory

These two add-ons will give a lot of insight into how to write all the boilerplate needed to convert your mathematical concept and code into an operator using bpy.


add_mesh_extra_objects

This add-on even has a selection of mathematical surface generators which seems to be what you are looking for.

enter image description here makes this:
enter image description here
and xyz makes this:
enter image description here

$\endgroup$
  • 1
    $\begingroup$ Totally agree with zeffii's tips. I started scripting exactly this way, and also by following some nice tuts on CG cookie, especially the now archived (but still freely available and relevant) tuts by Patrik Boelens: cgcookie.com/archive/… $\endgroup$ – TLousky Oct 1 '15 at 8:14
  • 1
    $\begingroup$ Another great source is the script cookbook (code snippets) page: wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/… And the small blender things blog (that has lots of OSL, but also lots of BPY stuff): swineworld.org/search/label/Python I also write about BPY scripting in my blog: bioblog3d.wordpress.com/category/python $\endgroup$ – TLousky Oct 1 '15 at 8:18
  • 1
    $\begingroup$ I agree with scripts cookbook, i use it too sometimes so shouldn't omit it either. As for blogs.. they will come up naturally when users search google, but the downside is they can't be updated by anyone other than the author $\endgroup$ – zeffii Oct 1 '15 at 9:46

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.