[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42693] branches/soc-2011-onion-uv-tools/ doc/python_api/rst: hand synchronize a doc file with trunk.

Antony Riakiotakis kalast at gmail.com
Sat Dec 17 20:14:26 CET 2011


Revision: 42693
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42693
Author:   psy-fi
Date:     2011-12-17 19:14:19 +0000 (Sat, 17 Dec 2011)
Log Message:
-----------
hand synchronize a doc file with trunk. This dile is making the diffing process very cumbersome. I hope that no conflicts will emerge in the future

Added Paths:
-----------
    branches/soc-2011-onion-uv-tools/doc/python_api/rst/info_overview.rst

Removed Paths:
-------------
    branches/soc-2011-onion-uv-tools/doc/python_api/rst/info_overview.rst

Deleted: branches/soc-2011-onion-uv-tools/doc/python_api/rst/info_overview.rst
===================================================================
--- branches/soc-2011-onion-uv-tools/doc/python_api/rst/info_overview.rst	2011-12-17 16:22:08 UTC (rev 42692)
+++ branches/soc-2011-onion-uv-tools/doc/python_api/rst/info_overview.rst	2011-12-17 19:14:19 UTC (rev 42693)
@@ -1,373 +0,0 @@
-*******************
-Python API Overview
-*******************
-
-This document is to give an understanding of how python and blender fit together, covering some of the functionality that isn't obvious from reading the API reference and example scripts.
-
-
-Python in Blender
-=================
-
-Blender embeds a python interpreter which is started with blender and stays active. This interpreter runs scripts to draw the user interface and is used for some of Blender's internal tools too.
-
-This is a typical python environment so tutorials on how to write python scripts will work running the scripts in blender too. Blender provides the :mod:`bpy` module to the python interpreter. This module can be imported in a script and gives access to blender data, classes, and functions. Scripts that deal with blender data will need to import this module. 
-
-Here is a simple example of moving a vertex of the object named **Cube**:
-
-.. code-block:: python
-
-   import bpy
-   bpy.data.objects["Cube"].data.vertices[0].co.x += 1.0
-
-This modifies Blender's internal data directly. When you run this in the interactive console you will see the 3D viewport update.
-
-
-The Default Environment
-=======================
-
-When developing your own scripts it may help to understand how blender sets up its python environment. Many python scripts come bundled with blender and can be used as a reference because they use the same API that script authors write tools in. Typical usage for scripts include: user interface, import/export, scene manipulation, automation, defining your own toolset and customization.
-
-On startup blender scans the ``scripts/startup/`` directory for python modules and imports them. The exact location of this directory depends on your installation. `See the directory layout docs <http://wiki.blender.org/index.php/Doc:2.5/Manual/Introduction/Installing_Blender/DirectoryLayout>`_
-
-
-Script Loading
-==============
-
-This may seem obvious but it's important to note the difference between executing a script directly or importing it as a module.
-
-Scripts that extend blender - define classes that exist beyond the scripts execution, this makes future access to these classes (to unregister for example) more difficult than importing as a module where class instance is kept in the module and can be accessed by importing that module later on.
-
-For this reason it's preferable to only use directly execute scripts that don't extend blender by registering classes.
-
-
-Here are some ways to run scripts directly in blender.
-
-* Loaded in the text editor and press **Run Script**.
-
-* Typed or pasted into the interactive console.
-
-* Execute a python file from the command line with blender, eg:
-
-  ``blender --python /home/me/my_script.py``
-
-
-To run as modules:
-
-* The obvious way, ``import some_module`` command from the text window or interactive console.
-
-* Open as a text block and tick "Register" option, this will load with the blend file.
-
-* copy into one of the directories ``scripts/startup``, where they will be automatically imported on startup.
-
-* define as an addon, enabling the addon will load it as a python module.
-
-
-Addons
-------
-
-Some of blenders functionality is best kept optional, alongside scripts loaded at startup we have addons which are kept in their own directory ``scripts/addons``, and only load on startup if selected from the user preferences.
-
-The only difference between addons and built-in python modules is that addons must contain a **bl_info** variable which blender uses to read metadata such as name, author, category and URL.
-
-The user preferences addon listing uses **bl_info** to display information about each addon.
-
-`See Addons <http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Guidelines/Addons>`_ for details on the **bl_info** dictionary.
-
-
-Integration through Classes
-===========================
-
-Running python scripts in the text editor is useful for testing but you’ll want to extend blender to make tools accessible like other built-in functionality.
-
-The blender python api allows integration for:
-
-* :class:`bpy.types.Panel`
-
-* :class:`bpy.types.Menu`
-
-* :class:`bpy.types.Operator`
-
-* :class:`bpy.types.PropertyGroup`
-
-* :class:`bpy.types.KeyingSet`
-
-* :class:`bpy.types.RenderEngine`
-
-
-This is intentionally limited. Currently, for more advanced features such as mesh modifiers, object types, or shader nodes, C/C++ must be used.
-
-For python intergration Blender defines methods which are common to all types. This works by creating a python subclass of a Blender class which contains variables and functions specified by the parent class which are pre-defined to interface with Blender.
-
-For example:
-
-.. code-block:: python
-
-   import bpy
-   class SimpleOperator(bpy.types.Operator):
-       bl_idname = "object.simple_operator"
-       bl_label = "Tool Name"
-
-       def execute(self, context):
-           print("Hello World")
-           return {'FINISHED'}
-
-   bpy.utils.register_class(SimpleOperator)
-
-First note that we subclass a member of :mod:`bpy.types`, this is common for all classes which can be integrated with blender and used so we know if this is an Operator and not a Panel when registering.
-
-Both class properties start with a **bl_** prefix. This is a convention used to distinguish blender properties from those you add yourself.
-
-Next see the execute function, which takes an instance of the operator and the current context. A common prefix is not used for functions.
-
-Lastly the register function is called, this takes the class and loads it into blender. See `Class Registration`_.
-
-Regarding inheritance, blender doesn't impose restrictions on the kinds of class inheritance used, the registration checks will use attributes and functions defined in parent classes.
-
-class mix-in example:
-
-.. code-block:: python
-
-   import bpy
-   class BaseOperator:
-       def execute(self, context):
-           print("Hello World BaseClass")
-           return {'FINISHED'}
-
-   class SimpleOperator(bpy.types.Operator, BaseOperator):
-       bl_idname = "object.simple_operator"
-       bl_label = "Tool Name"
-
-   bpy.utils.register_class(SimpleOperator)
-
-Notice these classes don't define an ``__init__(self)`` function. While ``__init__()`` and ``__del__()`` will be called if defined, the class instances lifetime only spans the execution. So a panel for example will have a new instance for every redraw, for this reason there is rarely a cause to store variables in the panel instance. Instead, persistent variables should be stored in Blenders data so that the state can be restored when blender is restarted.
-
-.. note:: Modal operators are an exception, keeping their instance variable as blender runs, see modal operator template.
-
-So once the class is registered with blender, instancing the class and calling the functions is left up to blender. In fact you cannot instance these classes from the script as you would expect with most python API's.
-
-To run operators you can call them through the operator api, eg:
-
-.. code-block:: python
-
-   import bpy
-   bpy.ops.object.simple_operator()
-
-User interface classes are given a context in which to draw, buttons window, file header, toolbar etc, then they are drawn when that area is displayed so they are never called by python scripts directly.
-
-
-Registration
-============
-
-
-Module Registration
--------------------
-
-Blender modules loaded at startup require ``register()`` and ``unregister()`` functions. These are the *only* functions that blender calls from your code, which is otherwise a regular python module.
-
-A simple blender/python module can look like this:
-
-.. code-block:: python
-
-   import bpy
-
-   class SimpleOperator(bpy.types.Operator):
-       """ See example above """
-
-   def register():
-       bpy.utils.register_class(SimpleOperator)
-
-   def unregister():
-       bpy.utils.unregister_class(SimpleOperator)    
-
-   if __name__ == "__main__":
-       register()
-
-These functions usually appear at the bottom of the script containing class registration sometimes adding menu items. You can also use them for internal purposes setting up data for your own tools but take care since register won't re-run when a new blend file is loaded.
-
-The register/unregister calls are used so it's possible to toggle addons and reload scripts while blender runs.
-If the register calls were placed in the body of the script, registration would be called on import, meaning there would be no distinction between importing a module or loading its classes into blender.
-
-This becomes problematic when a script imports classes from another module making it difficult to manage which classes are being loaded and when.
-
-The last 2 lines are only for testing:
-
-.. code-block:: python
-
-   if __name__ == "__main__":
-       register()
-
-This allows the script to be run directly in the text editor to test changes.
-This ``register()`` call won't run when the script is imported as a module since ``__main__`` is reserved for direct execution.
-
-
-Class Registration
-------------------
-
-Registering a class with blender results in the class definition being loaded into blender, where it becomes available alongside existing functionality.
-
-Once this class is loaded you can access it from :mod:`bpy.types`, using the bl_idname rather than the classes original name.
-
-When loading a class, blender performs sanity checks making sure all required properties and functions are found, that properties have the correct type, and that functions have the right number of arguments.
-
-Mostly you will not need concern yourself with this but if there is a problem with the class definition it will be raised on registering:
-
-Using the function arguments ``def execute(self, context, spam)``, will raise an exception:
-
-``ValueError: expected Operator, SimpleOperator class "execute" function to have 2 args, found 3``
-
-Using ``bl_idname = 1`` will raise.
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list