Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

I know that a list of math functions can be found on this site

But how about functions such as

  • obj.data.materials.clear()
  • obj.data.materials.append()
  • len(obj.data.polygons)
  • .normal or
  • .length ?

I have always wondered whether there was an overview or list or whatnot for these functions.

share|improve this question

4 Answers 4

These functions (or rather methods, properties and attributes) you are asking for are blender-specific, thus part of the Blender Python API (a.k.a. bpy) - just to clear it up. For standard python module features, please refer to the official python docs.

.polygons, .length etc. are properties of certain Blender type instances (objects). To find out what they do and which features are available, you need to check out the bpy API docs for a particular type (class).

There is a page in the docs about how to use the docs:
Blender/Python API Reference Usage: examples of how to use the API reference docs

Example

.polygons is a property of the type bpy.types.Mesh.

It is a type on its own, MeshPolygons, > which has an .active property and an add() method.

If you use the slice notation on .polygons, you will get elements returned of a bpy_prop_collection. The element type is MeshPolygon. A MeshPolygon has i.e. a .normal property in turn.

As you can see, the methods and properties are not found in a single place. The most valuable information is hidden in the bpy.types section of the docs. You can use the online search, or use Blender's built-in Python Console with auto-complete to figure out what is where. You can also find out the type and search for it in the API docs by adding bl_rna.identifier to an object:

>>> bpy.context.object.data.bl_rna.identifier
'Mesh'

>>> bpy.context.object.data.polygons.bl_rna.identifier
'MeshPolygons'

>>> bpy.context.object.data.polygons[0].bl_rna.identifier
'MeshPolygon'

Prepend bpy.types. and you have your type to lookup in the docs!

share|improve this answer

An API navigator can be enabled under File > User Preferences > Addons, Supported Level: Development, search for API navigator.

Change a window to the text editor and in the properties panel (CtrlT) there will now be a foldable menu called API Navigator.

Hope it helps =)

enter image description here

Also... if you right click any UI element and click Edit Source, the code will be displayed in this editor (unless it's from C code, you'll see a message in this case)

share|improve this answer
    
and of coarse if you dont understand the code you see there, codeman has pointed to the official docs, which can be cross-referenced with the actual source to obtain a more complete understanding of whats going on... i honestly never use the API nav, mostly because i get distracted from actually doing what i mean to do and end up just browsing the api.... for hours on end... which would be fine if i was trying to learn python... but i want to model, not code... lol –  Konner Rasmussen Mar 27 at 0:56

While you can easily get a list of operators I don't think anyone has done the same for all of blender. It would probably be too large anyway.

There is help available directly from python, you can use blender's Python console to access it. Starting with the autocomplete feature, typing in obj.data.materials. and pressing the Autocomplete button ( or CtrlSpace) will list all items available, even having entered D.objects[' autocomplete will list available object names.

The next option is listing all class attributes, which is methods and variables, so entering dir(C.active_object.data.materials) into the console gives you -

['__bool__', '__contains__', '__delattr__', '__delitem__', '__doc__', '__doc__',
'__getattribute__', '__getitem__', '__iter__', '__len__', '__module__', '__setattr__',
'__setitem__', '__slots__', 'append', 'bl_rna', 'clear', 'find', 'foreach_get',
'foreach_set', 'get', 'items', 'keys', 'pop', 'rna_type', 'values']

Names surrounded by double underline are 'builtin' implementations as defined by python - eg __len__ is the function called when you use len(C.active_object.data.materials)

Currently of limited use (the scrollback length in the console is too small) is the help function. eg help(C.active_object.data.materials) will output -

Help on bpy_prop_collection object:

class bpy_prop_collection(bpy_prop)
 |  Method resolution order:
 |      bpy_prop_collection
 |      bpy_prop
 |      object
 |  
 |  Methods defined here:
 |  
 |  __bool__(...)
 |      x.__bool__() <==> x != 0
 |  
 |  __contains__(...)
 |      x.__contains__(y) <==> y in x
 |  
 |  __delattr__(...)
 |      x.__delattr__('name') <==> del x.name
 |  
<snip>
 |  ----------------------------------------------------------------------
 |  Methods inherited from bpy_prop:
 |  
 |  __dir__(...)
 |  
 |  __eq__(...)
 |      x.__eq__(y) <==> x==y
 |  
 |  __ge__(...)
 |      x.__ge__(y) <==> x>=y
<snip>
 |  ----------------------------------------------------------------------
 |  Data descriptors inherited from bpy_prop:
 |  
 |  data
 |      The data this property is using, *type* :class:`bpy.types.bpy_struct`
 |  
 |  id_data
 |      The :class:`bpy.types.ID` object this datablock is from or None, (not available for all data types)
 |  
 |  rna_type
 |      The property type for introspection
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes inherited from bpy_prop:
 |  
 |  __new__ = <built-in method __new__ of type object>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T
share|improve this answer

For every python object there are two functions that everybody should know about - dir and help they do what they say on the box so for anything you can type in the console dir(theobject) to get a list of methods and help(theobject.somemethod) to get the help information. These are python builtin functions that should work everywhere.

Note that any members that start with one or more underscores (_) are private and should not be relied on to be available or the same in future or later versions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.