bpy.ops.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. Calling Operators
  3. -----------------
  4. Provides python access to calling operators, this includes operators written in
  5. C, Python or macros.
  6. Only keyword arguments can be used to pass operator properties.
  7. Operators don't have return values as you might expect,
  8. instead they return a set() which is made up of:
  9. ``{'RUNNING_MODAL', 'CANCELLED', 'FINISHED', 'PASS_THROUGH'}``.
  10. Common return values are ``{'FINISHED'}`` and ``{'CANCELLED'}``.
  11. Calling an operator in the wrong context will raise a ``RuntimeError``,
  12. there is a poll() method to avoid this problem.
  13. Note that the operator ID (bl_idname) in this example is ``mesh.subdivide``,
  14. ``bpy.ops`` is just the access path for python.
  15. Keywords and Positional Arguments
  16. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  17. For calling operators keywords are used for operator properties and
  18. positional arguments are used to define how the operator is called.
  19. There are 3 optional positional arguments (documented in detail below).
  20. .. code-block:: python
  21. bpy.ops.test.operator(override_context, execution_context, undo)
  22. - override_context - ``dict`` type.
  23. - execution_context - ``str`` (enum).
  24. - undo - ``bool`` type.
  25. Each of these arguments is optional, but must be given in the order above.
  26. """
  27. import bpy
  28. # calling an operator
  29. bpy.ops.mesh.subdivide(number_cuts=3, smoothness=0.5)
  30. # check poll() to avoid exception.
  31. if bpy.ops.object.mode_set.poll():
  32. bpy.ops.object.mode_set(mode='EDIT')