Консоль Python#
The Python Console offers a quick way to test code snippets and explore Blender’s API.
It executes whatever you type on its >>>
prompt and has command history and auto-complete.
Интерфейс (interface)#
Основной вид#
Назначение клавиш
ЛКМ – Перемещает курсор вдоль строки ввода.
Left / Right – Moves the cursor by one character.
Ctrl-Left / Ctrl-Right – Moves the cursor by one word.
Shift-Left / Shift-Right – Selects characters to the left/right.
Shift-Ctrl-Left / Shift-Ctrl-Right — Выделяет слова слева/справа.
Ctrl-A Выделить весь текст и его историю.
Backspace / Delete – Стереть символы.
Ctrl-Backspace / Ctrl-Delete – Стереть слова.
Return – Выполнить команду.
Shift-Return – Добавить в историю команд без выполнения.
Использование#
Aliases#
Some variables and modules are available for convenience:
C
: Quick access tobpy.context
.D
: Quick access tobpy.data
.bpy
: Top level Blender Python API module.
First Look at the Console Environment#
To see the list of global functions and variables,
type dir()
and press Return to execute it.
Auto Completion#
The Console can preview the available members of a module or variable.
As an example, type bpy.
and press Tab:
The submodules are listed in green. Attributes and methods will be listed
in the same way, with methods being indicated by a trailing (
.
Примеры#
bpy.context#
This module gives you access to the current scene, the currently selected objects, the current object mode, and so on.
Примечание
For the commands below to show the proper output, make sure you have selected object(s) in the 3D Viewport.
Get the current 3D Viewport mode (Object, Edit, Sculpt, etc.):
bpy.context.mode
Получить активный объект:
bpy.context.object
bpy.context.active_object
Изменить координату X активного объекта на 1:
bpy.context.object.location.x = 1
Переместить активный объект на 0,5 по оси X:
bpy.context.object.location.x += 0.5
Change all three location coordinates in one go:
bpy.context.object.location = (1, 2, 3)
Изменить только координаты X и Y:
bpy.context.object.location.xy = (1, 2)
Получить выбранные объекты:
bpy.context.selected_objects
Получить выбранные объекты, исключая активный:
[obj for obj in bpy.context.selected_objects if obj != bpy.context.object]
bpy.data#
Gives you access to all the data in the blend-file, regardless of whether it’s currently active or selected.
bpy.ops#
«Operators» are actions that are normally triggered from a button or menu item but can also be called programmatically. See the bpy.ops API documentation for a list of all operators.