﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3APT%2F2.5%2FPy%2FAPI%2FIntro</id>
	<title>Dev:PT/2.5/Py/API/Intro - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=Dev%3APT%2F2.5%2FPy%2FAPI%2FIntro"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:PT/2.5/Py/API/Intro&amp;action=history"/>
	<updated>2026-04-21T00:16:39Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:PT/2.5/Py/API/Intro&amp;diff=105595&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:PT/2.5/Py/API/Intro&amp;diff=105595&amp;oldid=prev"/>
		<updated>2018-06-28T19:44:31Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 19:44時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=Dev:PT/2.5/Py/API/Intro&amp;diff=105594&amp;oldid=prev</id>
		<title>wiki&gt;Genio84: /* Introdução à Blender/Python API */</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=Dev:PT/2.5/Py/API/Intro&amp;diff=105594&amp;oldid=prev"/>
		<updated>2011-06-12T08:44:56Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Introdução à Blender/Python API&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= Introdução à Blender/Python API =&lt;br /&gt;
&lt;br /&gt;
Esta API está em desenvolvimento mas está estável o suficiente para começar a ser usada com apenas pequenas mudanças a serem feitas até à primeira versão estável do Blender 2.5.&lt;br /&gt;
&lt;br /&gt;
A Blender/Python API pode fazer o seguinte:&lt;br /&gt;
* Editar qualquer data de User Interface(Scenes, Meshes, Particles etc.)&lt;br /&gt;
* Modificar as preferências do utilizador, atalhos do teclado e temas&lt;br /&gt;
* Correr ferramentas com as próprias definições&lt;br /&gt;
* Criar elementos do User Interface como menus, cabeçalhos e painéis&lt;br /&gt;
* Criar novas ferramentas&lt;br /&gt;
* Criar ferramentas interactivas&lt;br /&gt;
* Criar novas Render Engines que se integram com o Blender&lt;br /&gt;
* Definir novas definições na Blender data existente&lt;br /&gt;
* Desenhar na 3D view usando comandos OpenGL do Python&lt;br /&gt;
&lt;br /&gt;
A Blender/Python API '''não consegue''' (por enquanto)...&lt;br /&gt;
* Criar novos space types&lt;br /&gt;
* Atribuir Custom Properties a todos os tipos&lt;br /&gt;
* Definir Callbacks quando as Python-defined properties estão ajustadas&lt;br /&gt;
== Antes de começar ==&lt;br /&gt;
Este documento não pretende cobrir totalmente cada tópico. O seu propósito é dar-lhe a conhecer a Blender 2.5 Python API.&lt;br /&gt;
&lt;br /&gt;
Uma rápida lista the coisas a saber antes de começar:&lt;br /&gt;
* O Blender usa o Python 3.1; algumas 3rd party extensions não estão disponíveis por enquanto.&lt;br /&gt;
* A consola do Blender 2.5 foi melhorada; testar one-liners na consola é uma boa maneira de aprender.&lt;br /&gt;
* Para tópicos específicos, veja {{Link/API}}&lt;br /&gt;
* Button tooltips mostram atributos Python e nomes de operadores.&lt;br /&gt;
* Right clicking em butões e em menu items ligam directamente à documentação da API.&lt;br /&gt;
* Para mais exemplos, o text menu tem uma templates section onde alguns exemplos de operadores podem ser encontrados.&lt;br /&gt;
* Para examinar outros scripts distribuídos com o Blender, veja '''.blender/scripts/ui''' para o User Interface e '''.blender/scripts/op''' para operadores.&lt;br /&gt;
&lt;br /&gt;
== Conceptos chave ==&lt;br /&gt;
&lt;br /&gt;
=== Data Access ===&lt;br /&gt;
&lt;br /&gt;
==== Accessing datablocks ====&lt;br /&gt;
&lt;br /&gt;
Python accesses Blender's data in the same way as the animation system and user interface, which means any setting that is changed via a button can also be changed from Python.&lt;br /&gt;
&lt;br /&gt;
Accessing data from the currently loaded blend file is done with the module '''bpy.data'''. This gives access to library data. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.objects&lt;br /&gt;
&amp;lt;bpy_collection[6], BlendDataObjects&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt; bpy.data.scenes&lt;br /&gt;
&amp;lt;bpy_collection[1], BlendDataScenes&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.materials&lt;br /&gt;
&amp;lt;bpy_collection[1], BlendDataMaterials&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== About Collections ====&lt;br /&gt;
&lt;br /&gt;
You'll notice that an index as well as a string can be used to access members of the collection.&lt;br /&gt;
&lt;br /&gt;
Unlike Python's dictionaries, both methods are acceptable; however, the index of a member may change while running Blender.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; list(bpy.data.objects)&lt;br /&gt;
[bpy.data.objects[&amp;quot;Cube&amp;quot;], bpy.data.objects[&amp;quot;Plane&amp;quot;]]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.objects['Cube']&lt;br /&gt;
bpy.data.objects[&amp;quot;Cube&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.objects[0]&lt;br /&gt;
bpy.data.objects[&amp;quot;Cube&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Accessing attributes ====&lt;br /&gt;
&lt;br /&gt;
Once you have a datablock such as a material, object, groups etc.,  its attributes can be accessed just like changing a setting in the interface; in fact, the button tooltip also displays the Python attribute which can help in finding what settings to change in a script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.objects[0].name &lt;br /&gt;
&amp;quot;Cube&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.scenes[&amp;quot;Scene&amp;quot;]&lt;br /&gt;
&amp;lt;bpy_struct Scene(&amp;quot;Scene&amp;quot;)&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.materials.new(&amp;quot;MyMaterial&amp;quot;)&lt;br /&gt;
&amp;lt;bpy_struct Material(&amp;quot;MyMaterial&amp;quot;)&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For testing what data to access it's useful to use the &amp;quot;Console&amp;quot;, which is its own space type in Blender 2.5.&lt;br /&gt;
This supports auto-complete, giving you a fast way to dig into different data in your file.&lt;br /&gt;
&lt;br /&gt;
Example: data path that can be quickly found via the console:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# scene.render_data - &amp;gt; scene.render (since rev 27104)&lt;br /&gt;
#&amp;gt;&amp;gt;&amp;gt; bpy.data.scenes[0].render_data.resolution_percentage&lt;br /&gt;
&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.scenes[0].render.resolution_percentage&lt;br /&gt;
100&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; bpy.data.scenes[0].objects[&amp;quot;Torus&amp;quot;].data.vertices[0].co.x&lt;br /&gt;
1.0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Custom Properties ====&lt;br /&gt;
Python can access properties on any datablock that has an ID (data that can be linked in and accessed from bpy.data.*).&lt;br /&gt;
&lt;br /&gt;
When assigning a property, you can make up your own names, these will be created when needed or overwritten if they exist.&lt;br /&gt;
&lt;br /&gt;
This data is saved with the blend file and copied with objects.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
bpy.context.object[&amp;quot;MyOwnProperty&amp;quot;] = 42&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;SomeProp&amp;quot; in bpy.context.object:&lt;br /&gt;
    print(&amp;quot;Property found&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Use the get function like a Python dictionary which can have a fallback value.&lt;br /&gt;
value = bpy.data.scenes[&amp;quot;Scene&amp;quot;].get(&amp;quot;test_prop&amp;quot;, &amp;quot;fallback value&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# dictionaries can be assigned as long as they only use basic types.&lt;br /&gt;
group = bpy.data.groups.new(&amp;quot;MyTestGroup&amp;quot;)&lt;br /&gt;
group[&amp;quot;GameSettings&amp;quot;] = {&amp;quot;foo&amp;quot;: 10, &amp;quot;bar&amp;quot;: &amp;quot;spam&amp;quot;, &amp;quot;baz&amp;quot;: {}}&lt;br /&gt;
&lt;br /&gt;
del group[&amp;quot;GameSettings&amp;quot;]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that these properties can only be assigned  basic Python types.&lt;br /&gt;
* int, float, string&lt;br /&gt;
* array of ints/floats&lt;br /&gt;
* dictionary (only string keys types on this list)&lt;br /&gt;
&lt;br /&gt;
These properties are valid outside of Python. They can be animated by curves or used in driver paths.&lt;br /&gt;
&lt;br /&gt;
=== Context ===&lt;br /&gt;
While it's useful to be able to access data directly by name or as a list,  it's more common to operate on the user's selection. The context is always available from '''bpy.context''' and can be used to get the active object, scene, tool settings along with many other attributes.&lt;br /&gt;
&lt;br /&gt;
Common-use cases...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.object&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.selected_objects&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.context.visible_bones&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the context is read-only. These values cannot be modified directly, though they may be changed by running API functions or by using the data API. So '''bpy.context.object = obj''' will raise an error. But '''bpy.context.scene.objects.active = obj''' will work as expected.&lt;br /&gt;
&lt;br /&gt;
The context attributes change depending on where it is accessed.  The 3D view has different context members to the Console, so take care when accessing context attributes that the user state is known.&lt;br /&gt;
&lt;br /&gt;
See [http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.context.html bpy.context] API reference&lt;br /&gt;
&lt;br /&gt;
=== Operators (Tools) ===&lt;br /&gt;
Operators are tools generally accessed by the user from buttons, menu items or key shortcuts. From the user perspective they are a tool but Python can run these with its own settings through the '''bpy.ops''' module.&lt;br /&gt;
&lt;br /&gt;
Examples...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.ops.mesh.flip_normals()&lt;br /&gt;
 {'FINISHED'}&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.ops.mesh.hide(unselected=False)&lt;br /&gt;
 {'FINISHED'}&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; bpy.ops.object.scale_apply()&lt;br /&gt;
 {'FINISHED'}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|Operator Cheat Sheet|&amp;quot;Help -&amp;gt; Operator Cheat Sheet&amp;quot; gives a list of all operators and their default values in Python syntax, along with the generated docs.  This is a good way to get an overview of Blender's operators.}}&lt;br /&gt;
&lt;br /&gt;
==== Operator Poll() ====&lt;br /&gt;
Some operators have a &amp;quot;poll&amp;quot; function which may check that the mouse is a valid area or that the object is in the correct mode (Edit Mode, Weight Paint etc).&lt;br /&gt;
&lt;br /&gt;
When an operator's poll function fails within python, an exception is raised.&lt;br /&gt;
&lt;br /&gt;
For example, calling bpy.ops.view3d.render_border() from the console raises the following error:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
RuntimeError: Operator bpy.ops.view3d.render_border.poll() failed, context is incorrect&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this case the context must be the 3d view with an active camera.&lt;br /&gt;
&lt;br /&gt;
== Integration ==&lt;br /&gt;
Python scripts can integrate with Blender in the following ways: &lt;br /&gt;
&lt;br /&gt;
* By defining a rendering engine&lt;br /&gt;
* By defining operators&lt;br /&gt;
* By defining menus, headers and panels&lt;br /&gt;
* By inserting new buttons into existing menus, headers and panels&lt;br /&gt;
&lt;br /&gt;
In Python, this is done by defining a class, which is a subclass of an existing type.&lt;br /&gt;
&lt;br /&gt;
=== Example Operator ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import bpy&lt;br /&gt;
&lt;br /&gt;
class OpHelloWorld(bpy.types.Operator):&lt;br /&gt;
    bl_idname = &amp;quot;screen.hello_world&amp;quot;&lt;br /&gt;
    bl_label = &amp;quot;Hello World&amp;quot;&lt;br /&gt;
     &lt;br /&gt;
    def execute(self, context):&lt;br /&gt;
        self.report({'WARNING'}, &amp;quot;Hello World&amp;quot;)&lt;br /&gt;
        return {'FINISHED'}&lt;br /&gt;
&lt;br /&gt;
# registering and menu integration&lt;br /&gt;
def register():&lt;br /&gt;
    bpy.utils.register_class(OpHelloWorld)&lt;br /&gt;
&lt;br /&gt;
# unregistering and removing menus&lt;br /&gt;
def unregister():&lt;br /&gt;
    bpy.utils.unregister_class(OpHelloWorld)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    register()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once this script runs, ''HelloWorld'' is registered with Blender and can be called from the operator search popup or added to the toolbar.&lt;br /&gt;
&lt;br /&gt;
To run the script:&lt;br /&gt;
&lt;br /&gt;
# Highlight the above code then press {{shortcut|ctrl|c}} to copy it&lt;br /&gt;
# Start Blender&lt;br /&gt;
# Press {{shortcut|ctrl|right}} twice to change to the Scripting layout&lt;br /&gt;
# Press {{shortcut|ctrl|v}} to paste the code into the text panel (the upper left frame)&lt;br /&gt;
# Click '''Run Script''' or press {{shortcut|alt|p}} to run the script&lt;br /&gt;
# Click in the 3dview, press spacebar for the search menu, and type &amp;quot;hello&amp;quot;&lt;br /&gt;
# click on the &amp;quot;Hello World&amp;quot; item found in search&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice the class members with the bl_ prefix, these are documented in the Python API.&lt;br /&gt;
http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Operator.html&lt;br /&gt;
&lt;br /&gt;
=== Example Panel ===&lt;br /&gt;
Panels register themselves as a class, like an operator. Notice the extra variables used to set the context they display in.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import bpy&lt;br /&gt;
&lt;br /&gt;
class OBJECT_PT_hello(bpy.types.Panel):&lt;br /&gt;
    bl_label = &amp;quot;Hello World Panel&amp;quot;&lt;br /&gt;
    bl_space_type = &amp;quot;PROPERTIES&amp;quot;&lt;br /&gt;
    bl_region_type = &amp;quot;WINDOW&amp;quot;&lt;br /&gt;
    bl_context = &amp;quot;object&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
    def draw(self, context):&lt;br /&gt;
        layout = self.layout&lt;br /&gt;
&lt;br /&gt;
        obj = context.object&lt;br /&gt;
&lt;br /&gt;
        row = layout.row()&lt;br /&gt;
        row.label(text=&amp;quot;Hello world!&amp;quot;, icon='WORLD_DATA')&lt;br /&gt;
&lt;br /&gt;
        row = layout.row()&lt;br /&gt;
        row.label(text=&amp;quot;Active object is: &amp;quot; + obj.name)&lt;br /&gt;
        row = layout.row()&lt;br /&gt;
        row.prop(obj, &amp;quot;name&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
# registering and menu integration&lt;br /&gt;
def register():&lt;br /&gt;
    bpy.utils.register_class(OBJECT_PT_hello)&lt;br /&gt;
 &lt;br /&gt;
# unregistering and removing menus&lt;br /&gt;
def unregister():&lt;br /&gt;
    bpy.utils.unregister_class(OBJECT_PT_hello)&lt;br /&gt;
 &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    register()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run the script:&lt;br /&gt;
&lt;br /&gt;
# Highlight the above code then press {{shortcut|ctrl|c}} to copy it&lt;br /&gt;
# Start Blender&lt;br /&gt;
# Press {{shortcut|ctrl|right}} twice to change to the Scripting layout&lt;br /&gt;
# Press {{shortcut|ctrl|v}} to paste the code into the text panel (the upper left frame)&lt;br /&gt;
# Click '''Run Script''' or press {{shortcut|alt|p}} to run the script&lt;br /&gt;
&lt;br /&gt;
To view the results:&lt;br /&gt;
&lt;br /&gt;
# {{shortcut|RMB}}-click on the default cube to select it&lt;br /&gt;
# {{shortcut|LMB}}-click the Object properties icon in the buttons panel (far right; appears as a tiny cube)&lt;br /&gt;
# Scroll down to see a panel named '''Hello World Panel'''&lt;br /&gt;
# Changing the object name also updates '''Hello World Panel''''s '''Name:''' field&lt;br /&gt;
&lt;br /&gt;
Note the row distribution and the label and properties that are available through the code.&lt;br /&gt;
&lt;br /&gt;
See also [http://www.blender.org/documentation/250PythonDoc/bpy.types.Panel.html#bpy.types.Panel the Panel class documentation]&lt;br /&gt;
&lt;br /&gt;
== Types ==&lt;br /&gt;
Blender defines a number of Python types but also uses Python native types.&lt;br /&gt;
&lt;br /&gt;
Blender's Python API can be split up into 3 categories. &lt;br /&gt;
&lt;br /&gt;
==== Native Types ====&lt;br /&gt;
&lt;br /&gt;
In simple cases returning a number or a string as a custom type would be cumbersome, so these are accessed as normal python types.&lt;br /&gt;
&lt;br /&gt;
* blender float/int/boolean -&amp;gt; float/int/boolean&lt;br /&gt;
* blender enumerator -&amp;gt; string&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; C.object.rotation_mode = 'AXIS_ANGLE'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
* blender enumerator (multiple) -&amp;gt; set of strings&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 # within an operator&lt;br /&gt;
 self.report({'WARNING', 'INFO'}, &amp;quot;SomeMessage&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Internal Types ====&lt;br /&gt;
''used for Blender datablocks and collections.''&amp;lt;br&amp;gt;&lt;br /&gt;
Reference: http://www.blender.org/documentation/250PythonDoc/bpy.types.bpy_struct.html&lt;br /&gt;
&lt;br /&gt;
For data that contains its own attributes groups/meshes/bones.&lt;br /&gt;
&lt;br /&gt;
There are 2 main types that wrap Blenders data, one for datablocks (known internally as bpy_struct), another for properties.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; C.object&lt;br /&gt;
bpy.data.objects[&amp;quot;Cube&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
 &amp;gt;&amp;gt;&amp;gt; C.scene.objects&lt;br /&gt;
bpy.data.scenes[&amp;quot;Scene&amp;quot;].objects&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that these types keep a reference to Blender's data so modifying them should be immediately visible.&lt;br /&gt;
&lt;br /&gt;
==== Mathutils Types ====&lt;br /&gt;
''used for vectors, quaternion, eulers, matrix and color types.''&amp;lt;br&amp;gt;&lt;br /&gt;
Reference: http://www.blender.org/documentation/250PythonDoc/mathutils.html&lt;br /&gt;
&lt;br /&gt;
Some attributes such as object.location, bone.rotation_euler and scene.cursor_location can be accessed as special math types which can be added together and manipulated in useful ways.&lt;br /&gt;
&lt;br /&gt;
Example of a matrix, vector multiplication:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
bpy.context.object.data.verts[0].co * bpy.context.object.matrix_world&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Mathutils types keep a reference to Blender's internal data so changes can be applied back.&lt;br /&gt;
&lt;br /&gt;
Examples&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# modifies Z in place.&lt;br /&gt;
bpy.context.object.location.z += 2.0&lt;br /&gt;
&lt;br /&gt;
# location variable holds a reference to the object too.&lt;br /&gt;
location = bpy.context.object.location&lt;br /&gt;
location *= 2.0&lt;br /&gt;
&lt;br /&gt;
# Copying the value drops the reference.&lt;br /&gt;
location = bpy.context.object.location.copy()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Animation ==&lt;br /&gt;
There are 2 ways to add keyframes through Python. The first is through key properties directly, which is similar to inserting a keyframe as a user.&lt;br /&gt;
You can also manually create the curves and keyframe data, then set the path to the property. Here are examples of both methods.&lt;br /&gt;
&lt;br /&gt;
These 2 examples insert a keyframe on the active object's Z axis.&lt;br /&gt;
&lt;br /&gt;
Simple example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
obj = bpy.context.object&lt;br /&gt;
obj.location[2] = 0.0&lt;br /&gt;
obj.keyframe_insert(data_path=&amp;quot;location&amp;quot;, frame=10.0, index=2)&lt;br /&gt;
obj.location[2] = 1.0&lt;br /&gt;
obj.keyframe_insert(data_path=&amp;quot;location&amp;quot;, frame=20.0, index=2)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Using Low-Level Functions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
obj = bpy.context.object&lt;br /&gt;
obj.animation_data_create()&lt;br /&gt;
obj.animation_data.action = bpy.data.actions.new(name=&amp;quot;MyAction&amp;quot;)&lt;br /&gt;
fcu_z = obj.animation_data.action.fcurves.new(data_path=&amp;quot;location&amp;quot;, index=2)&lt;br /&gt;
fcu_z.keyframe_points.add(2)&lt;br /&gt;
fcu_z.keyframe_points[0].co = 10.0, 0.0&lt;br /&gt;
fcu_z.keyframe_points[1].co = 20.0, 1.0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Style Conventions ==&lt;br /&gt;
For Blender 2.5 we have chosen to follow python suggested style guide to avoid mixing styles amongst our own scripts and make it easier to use python from other projects.&lt;br /&gt;
&lt;br /&gt;
Using our style guide for your own scripts makes it easier if you eventually want to contribute them to blender.&lt;br /&gt;
&lt;br /&gt;
This style guide is known as pep8 and can be found [http://www.python.org/dev/peps/pep-0008/| here].&lt;br /&gt;
&lt;br /&gt;
A brief listing of pep8 criteria.&lt;br /&gt;
* camel caps for class names: MyClass&lt;br /&gt;
* all lower case underscore separated module names: my_module&lt;br /&gt;
* indentation of 4 spaces (no tabs)&lt;br /&gt;
* spaces around operators. 1 + 1, not 1+1&lt;br /&gt;
* only use explicit imports, (no importing '*')&lt;br /&gt;
* don't use single line: &amp;lt;code&amp;gt;if val: body&amp;lt;/code&amp;gt;, separate onto 2 lines instead.&lt;br /&gt;
&lt;br /&gt;
As well as pep8 we have other conventions used for blender python scripts.&lt;br /&gt;
* Use single quotes for enums, and double quotes for strings.&amp;lt;br&amp;gt;Both are of course strings but in our internal API enums are unique items from a limited set. eg.&amp;lt;br&amp;gt;&amp;lt;code&amp;gt;bpy.context.scene.render.file_format = 'PNG'&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&amp;lt;code&amp;gt;bpy.context.scene.render.filepath = &amp;quot;//render_out&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* pep8 also defines that lines should not exceed 79 characters, we felt this is too restrictive so this is optional per script.&lt;br /&gt;
&lt;br /&gt;
Periodically we run checks for pep8 compliance on blender scripts, for scripts to be included in this check add this line as a comment at the top of the script.&lt;br /&gt;
 # &amp;lt;pep8 compliant&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To enable line length checks use this instead.&lt;br /&gt;
 # &amp;lt;pep8-80 compliant&amp;gt;&lt;/div&gt;</summary>
		<author><name>wiki&gt;Genio84</name></author>
		
	</entry>
</feed>