[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39735] trunk/blender/doc/python_api/rst: - use python convention for headings

Campbell Barton ideasman42 at gmail.com
Sat Aug 27 10:09:13 CEST 2011


Revision: 39735
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39735
Author:   campbellbarton
Date:     2011-08-27 08:09:12 +0000 (Sat, 27 Aug 2011)
Log Message:
-----------
- use python convention for headings
- use implicit examples rather than .. code-block::

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/info_gotcha.rst
    trunk/blender/doc/python_api/rst/info_overview.rst
    trunk/blender/doc/python_api/rst/info_quickstart.rst

Modified: trunk/blender/doc/python_api/rst/info_gotcha.rst
===================================================================
--- trunk/blender/doc/python_api/rst/info_gotcha.rst	2011-08-27 07:06:44 UTC (rev 39734)
+++ trunk/blender/doc/python_api/rst/info_gotcha.rst	2011-08-27 08:09:12 UTC (rev 39735)
@@ -1,12 +1,12 @@
-########
+********
 Gotcha's
-########
+********
 
 This document attempts to help you work with the Blender API in areas that can be troublesome and avoid practices that are known to give instability.
 
-***************
+
 Using Operators
-***************
+===============
 
 Blender's operators are tools for users to access, that python can access them too is very useful nevertheless operators have limitations that can make them cumbersome to script.
 
@@ -19,19 +19,13 @@
 
 * Operators poll function can fail where an API function would raise an exception giving details on exactly why.
 
-=================================
+
 Why does an operator's poll fail?
-=================================
+---------------------------------
 
 When calling an operator gives an error like this:
 
-.. code-block:: python
-
    >>> bpy.ops.action.clean(threshold=0.001)
-   Traceback (most recent call last):
-     File "<blender_console>", line 1, in <module>
-     File "scripts/modules/bpy/ops.py", line 179, in __call__
-       ret = op_call(self.idname_py(), None, kw)
    RuntimeError: Operator bpy.ops.action.clean.poll() failed, context is incorrect
 
 Which raises the question as to what the correct context might be?
@@ -51,14 +45,12 @@
 
    Blender does have the functionality for poll functions to describe why they fail, but its currently not used much, if you're interested to help improve our API feel free to add calls to ``CTX_wm_operator_poll_msg_set`` where its not obvious why poll fails.
 
-   .. code-block:: python
-
       >>> bpy.ops.gpencil.draw()
       RuntimeError: Operator bpy.ops.gpencil.draw.poll() Failed to find Grease Pencil data to draw into
 
-================================
+
 The operator still doesn't work!
-================================
+--------------------------------
 
 Certain operators in Blender are only intended for use in a specific context, some operators for example are only called from the properties window where they check the current material, modifier or constraint.
 
@@ -72,13 +64,11 @@
 Another possibility is that you are the first person to attempt to use this operator in a script and some modifications need to be made to the operator to run in a different context, if the operator should logically be able to run but fails when accessed from a script it should be reported to the bug tracker.
 
 
-**********
 Stale Data
-**********
+==========
 
-===============================
 No updates after setting values
-===============================
+-------------------------------
 
 Sometimes you want to modify values from python and immediately access the updated values, eg:
 
@@ -97,9 +87,9 @@
 
 This can be done by calling :class:`bpy.types.Scene.update` after modifying values which recalculates all data that is tagged to be updated.
 
-===============================
+
 Can I redraw during the script?
-===============================
+-------------------------------
 
 The official answer to this is no, or... *"You don't want to do that"*.
 
@@ -128,18 +118,16 @@
    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
 
 
-******************************
 Matrix multiplication is wrong
-******************************
+==============================
 
 Every so often users complain that Blenders matrix math is wrong, the confusion comes from mathutils matrices being column-major to match OpenGL and the rest of Blenders matrix operations and stored matrix data.
 
 This is different to **numpy** which is row-major which matches what you would expect when using conventional matrix math notation.
 
 
-***********************************
 I can't edit the mesh in edit-mode!
-***********************************
+===================================
 
 Blenders EditMesh is an internal data structure (not saved and not exposed to python), this gives the main annoyance that you need to exit edit-mode to edit the mesh from python.
 
@@ -152,9 +140,8 @@
 For the time being this limitation just has to be worked around but we're aware its frustrating needs to be addressed.
 
 
-***********************************
 EditBones, PoseBones, Bone... Bones
-***********************************
+===================================
 
 Armature Bones in Blender have three distinct data structures that contain them. If you are accessing the bones through one of them, you may not have access to the properties you really need.
 
@@ -163,49 +150,48 @@
 	In the following examples ``bpy.context.object`` is assumed to be an armature object.
 
 
-==========
 Edit Bones
-==========
+----------
 
 ``bpy.context.object.data.edit_bones`` contains a editbones; to access them you must set the armature mode to edit mode first (editbones do not exist in object or pose mode). Use these to create new bones, set their head/tail or roll, change their parenting relationships to other bones, etc.
 
 Example using :class:`bpy.types.EditBone` in armature editmode:
 
-.. code-block:: python
+This is only possible in edit mode.
 
-	# This is only possible in edit mode.
-	bpy.context.object.data.edit_bones["Bone"].head = Vector((1.0, 2.0, 3.0)) 
+   >>> bpy.context.object.data.edit_bones["Bone"].head = Vector((1.0, 2.0, 3.0)) 
 
-	# This will be empty outside of editmode.
-	mybones = bpy.context.selected_editable_bones
+This will be empty outside of editmode.
 
-	# Returns an editbone only in edit mode.
-	bpy.context.active_bone
+	>>> mybones = bpy.context.selected_editable_bones
 
+Returns an editbone only in edit mode.
 
-===================
+	>>> bpy.context.active_bone
+
+
 Bones (Object Mode)
-===================
+-------------------
 
 ``bpy.context.object.data.bones`` contains bones. These *live* in object mode, and have various properties you can change, note that the head and tail properties are read-only.
 
 Example using :class:`bpy.types.Bone` in object or pose mode:
 
-.. code-block:: python
+Returns a bone (not an editbone) outside of edit mode
 
-	# returns a bone (not an editbone) outside of edit mode
-	bpy.context.active_bone
+	>>> bpy.context.active_bone
 
-	# This works, as with blender the setting can be edited in any mode
-	bpy.context.object.data.bones["Bone"].use_deform = True
+This works, as with blender the setting can be edited in any mode
 
-	# Accessible but read-only
-	tail = myobj.data.bones["Bone"].tail
+	>>> bpy.context.object.data.bones["Bone"].use_deform = True
 
+Accessible but read-only
 
-==========
+	>>> tail = myobj.data.bones["Bone"].tail
+
+
 Pose Bones
-==========
+----------
 
 ``bpy.context.object.pose.bones`` contains pose bones. This is where animation data resides, i.e. animatable transformations are applied to pose bones, as are constraints and ik-settings.
 
@@ -229,18 +215,16 @@
 	Strictly speaking PoseBone's are not bones, they are just the state of the armature, stored in the :class:`bpy.types.Object` rather than the :class:`bpy.types.Armature`, the real bones are however accessible from the pose bones - :class:`bpy.types.PoseBone.bone`
 
 
-=======================
 Armature Mode Switching
-=======================
+-----------------------
 
 While writing scripts that deal with armatures you may find you have to switch between modes, when doing so take care when switching out of editmode not to keep references to the edit-bones or their head/tail vectors. Further access to these will crash blender so its important the script clearly separates sections of the code which operate in different modes.
 
 This is mainly an issue with editmode since pose data can be manipulated without having to be in pose mode, however for operator access you may still need to enter pose mode.
 
 
-****************
 Unicode Problems
-****************
+================
 
 Python supports many different encpdings so there is nothing stopping you from writing a script in latin1 or iso-8859-15.
 
@@ -256,8 +240,6 @@
 
 This means seemingly harmless expressions can raise errors, eg.
 
-.. code-block:: python
-
    >>> print(bpy.data.filepath)
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-21: ordinal not in range(128)
 
@@ -267,10 +249,8 @@
    TypeError: bpy_struct: item.attr= val: Object.name expected a string type, not str
 
 
-Here are 2 ways around filesystem encoding issues.
+Here are 2 ways around filesystem encoding issues:
 
-.. code-block:: python
-
    >>> print(repr(bpy.data.filepath))
 
    >>> import os
@@ -292,9 +272,8 @@
 * **Possibly** - use bytes instead of python strings, when reading some input its less trouble to read it as binary data though you will still need to deciede how to treat any strings you want to use with Blender, some importers do this.
 
 
-***************************************
 Strange errors using 'threading' module
-***************************************
+=======================================
 
 Python threading with Blender only works properly when the threads finish up before the script does. By using ``threading.join()`` for example.
 
@@ -361,9 +340,8 @@
    Pythons threads only allow co-currency and wont speed up you're scripts on multi-processor systems, the ``subprocess`` and ``multiprocess`` modules can be used with blender and make use of multiple CPU's too.
 
 
-*******************************
 Help! My script crashes Blender
-*******************************
+===============================
 
 Ideally it would be impossible to crash Blender from python however there are some problems with the API where it can be made to crash.
 
@@ -380,16 +358,13 @@
 * Crashes may not happen every time, they may happen more on some configurations/operating-systems.
 
 
-=========
 Undo/Redo
-=========
+---------
 
 Undo invalidates all :class:`bpy.types.ID` instances (Object, Scene, Mesh etc).
 
 This example shows how you can tell undo changes the memory locations.
 
-.. code-block:: python
-
    >>> hash(bpy.context.object)
    -9223372036849950810
    >>> hash(bpy.context.object)
@@ -403,9 +378,8 @@
 As suggested above, simply not holding references to data when Blender is used interactively by the user is the only way to ensure the script doesn't become unstable.
 
 
-===================
 Array Re-Allocation

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list