[Bf-blender-cvs] [532b735] master: Docs; Py API gotcha's section

Campbell Barton noreply at git.blender.org
Sun Jul 12 12:57:40 CEST 2015


Commit: 532b735ee8e2d38120deb6a847e5780f2a787224
Author: Campbell Barton
Date:   Sun Jul 12 20:50:44 2015 +1000
Branches: master
https://developer.blender.org/rB532b735ee8e2d38120deb6a847e5780f2a787224

Docs; Py API gotcha's section

Minor corrections and cleanup

===================================================================

M	doc/python_api/rst/info_gotcha.rst

===================================================================

diff --git a/doc/python_api/rst/info_gotcha.rst b/doc/python_api/rst/info_gotcha.rst
index aad2311..716bb58 100644
--- a/doc/python_api/rst/info_gotcha.rst
+++ b/doc/python_api/rst/info_gotcha.rst
@@ -2,7 +2,8 @@
 Gotchas
 *******
 
-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.
+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:
@@ -10,16 +11,15 @@ This document attempts to help you work with the Blender API in areas that can b
 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.
+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.
 
 Main limits are...
 
-* Can't pass data such as objects, meshes or materials to operate on (operators use the context instead)
-
-* The return value from calling an operator gives the success (if it finished or was canceled),
+- Can't pass data such as objects, meshes or materials to operate on (operators use the context instead)
+- The return value from calling an operator gives the success (if it finished or was canceled),
   in some cases it would be more logical from an API perspective to return the result of the operation.
-
-* Operators poll function can fail where an API function would raise an exception giving details on exactly why.
+- 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?
@@ -32,20 +32,28 @@ When calling an operator gives an error like this:
 
 Which raises the question as to what the correct context might be?
 
-Typically operators check for the active area type, a selection or active object they can operate on, but some operators are more picky about when they run.
+Typically operators check for the active area type, a selection or active object they can operate on,
+but some operators are more picky about when they run.
 
-In most cases you can figure out what context an operator needs simply be seeing how it's used in Blender and thinking about what it does.
+In most cases you can figure out what context an operator needs
+simply be seeing how it's used in Blender and thinking about what it does.
 
 
-Unfortunately if you're still stuck - the only way to **really** know whats going on is to read the source code for the poll function and see what its checking.
+Unfortunately if you're still stuck - the only way to **really** know
+whats going on is to read the source code for the poll function and see what its checking.
 
-For python operators it's not so hard to find the source since it's included with Blender and the source file/line is included in the operator reference docs.
+For Python operators it's not so hard to find the source
+since it's included with Blender and the source file/line is included in the operator reference docs.
 
-Downloading and searching the C code isn't so simple, especially if you're not familiar with the C language but by searching the operator name or description you should be able to find the poll function with no knowledge of C.
+Downloading and searching the C code isn't so simple,
+especially if you're not familiar with the C language but by searching the
+operator name or description you should be able to find the poll function with no knowledge of C.
 
 .. note::
 
-   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.
+   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.
 
       >>> bpy.ops.gpencil.draw()
       RuntimeError: Operator bpy.ops.gpencil.draw.poll() Failed to find Grease Pencil data to draw into
@@ -54,36 +62,45 @@ Downloading and searching the C code isn't so simple, especially if you're not f
 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.
+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.
 
 Examples of this are:
 
-* :mod:`bpy.ops.texture.slot_move`
-* :mod:`bpy.ops.constraint.limitdistance_reset`
-* :mod:`bpy.ops.object.modifier_copy`
-* :mod:`bpy.ops.buttons.file_browse`
+- :mod:`bpy.ops.texture.slot_move`
+- :mod:`bpy.ops.constraint.limitdistance_reset`
+- :mod:`bpy.ops.object.modifier_copy`
+- :mod:`bpy.ops.buttons.file_browse`
 
-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.
+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:
+Sometimes you want to modify values from Python and immediately access the updated values, eg:
 
-Once changing the objects :class:`bpy.types.Object.location` you may want to access its transformation right after from :class:`bpy.types.Object.matrix_world`, but this doesn't work as you might expect.
+Once changing the objects :class:`bpy.types.Object.location`
+you may want to access its transformation right after from :class:`bpy.types.Object.matrix_world`,
+but this doesn't work as you might expect.
 
 Consider the calculations that might go into working out the object's final transformation, this includes:
 
-* animation function curves.
-* drivers and their pythons expressions.
-* constraints
-* parent objects and all of their f-curves, constraints etc.
+- animation function curves.
+- drivers and their Python expressions.
+- constraints
+- parent objects and all of their f-curves, constraints etc.
 
-To avoid expensive recalculations every time a property is modified, Blender defers making the actual calculations until they are needed.
+To avoid expensive recalculations every time a property is modified,
+Blender defers making the actual calculations until they are needed.
 
 However, while the script runs you may want to access the updated values.
 In this case you need to call :class:`bpy.types.Scene.update` after modifying values, for example:
@@ -94,7 +111,9 @@ In this case you need to call :class:`bpy.types.Scene.update` after modifying va
    bpy.context.scene.update()
 
 
-Now all dependent data (child objects, modifiers, drivers... etc) has been recalculated and is available to the script.
+Now all dependent data (child objects, modifiers, drivers... etc)
+has been recalculated and is available to the script.
+
 
 Can I redraw during the script?
 -------------------------------
@@ -103,23 +122,33 @@ The official answer to this is no, or... *"You don't want to do that"*.
 
 To give some background on the topic...
 
-While a script executes Blender waits for it to finish and is effectively locked until its done, while in this state Blender won't redraw or respond to user input.
-Normally this is not such a problem because scripts distributed with Blender tend not to run for an extended period of time, nevertheless scripts *can* take ages to execute and its nice to see whats going on in the view port.
+While a script executes Blender waits for it to finish and is effectively locked until its done,
+while in this state Blender won't redraw or respond to user input.
+Normally this is not such a problem because scripts distributed with Blender
+tend not to run for an extended period of time,
+nevertheless scripts *can* take ages to execute and its nice to see whats going on in the view port.
 
-Tools that lock Blender in a loop and redraw are highly discouraged since they conflict with Blenders ability to run multiple operators at once and update different parts of the interface as the tool runs.
+Tools that lock Blender in a loop and redraw are highly discouraged
+since they conflict with Blenders ability to run multiple operators
+at once and update different parts of the interface as the tool runs.
 
-So the solution here is to write a **modal** operator, that is - an operator which defines a modal() function, See the modal operator template in the text  editor.
+So the solution here is to write a **modal** operator, that is - an operator which defines a modal() function,
+See the modal operator template in the text  editor.
 
-Modal operators execute on user input or setup their own timers to run frequently, they can handle the events or pass through to be handled by the keymap or other modal operators.
+Modal operators execute on user input or setup their own timers to run frequently,
+they can handle the events or pass through to be handled by the keymap or other modal operators.
 
 Transform, Painting, Fly-Mode and File-Select are example of a modal operators.
 
-Writing modal operators takes more effort than a simple ``for`` loop that happens to redraw but is more flexi

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list