Консоль 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.

../_images/editors_python-console_default.png

Python Console.

Интерфейс

Header Menus

View Menu

Zoom In / Zoom Out

Increases/decreases the font size.

Move to Previous Word Ctrl-Left

Moves the cursor to the beginning of the previous word. If the cursor is in the middle of a word, the cursor is moved to the beginning of the current word.

Move to Next Word Ctrl-Right

Moves the cursor to the end of the next word. If the cursor is in the middle of a word, the cursor is moved to the end of the current word.

Move to Line Begin Home

Перемещает курсор в начало текущей строки.

Shift-Home: Выделяет весь текст между курсором и началом текущей строки.

Move to Line End End

Перемещает курсор в конец текущей строки.

Shift-End: Выделяет весь текст между курсором и концом текущей строки.

Console Menu

Очистить всё

Refreshes the console, giving the view a fresh start. Note that command history is not cleared.

Очистить строку Shift-Return.

Removes everything from the prompt line.

Delete Previous Word Ctrl-Backspace

Deletes everything between the cursor and the beginning of the previous word (separated by periods). If the cursor is in the middle of a word, deletes everything to the beginning of the current word.

Delete Next Word Ctrl-Delete

Deletes everything between the cursor and the end of the next word. If the cursor is in the middle of a word, deletes everything to the end of the current word.

Скопировать как сценарий Shift-Ctrl-C

Copies the full history buffer to the clipboard. This can be pasted into a text file to be used as a Python script.

Cut Ctrl-X

Copies the selected text into the clipboard and deletes it.

Copy Ctrl-C

Copies the selected text into the clipboard.

Paste Ctrl-V

Вставляется в командную строку.

Отступ Tab

Inserts a tab character at the cursor.

Unindent Shift-Tab

Отменяет выбор.

Backward in History Up

Changes the current command to the previous one from the command history.

Forward in History Down

Changes the current command to the next one from the command history.

Автозаполнение Tab

See Auto Completion.

Main View

Назначение клавиш

  • ЛКМ – Перемещает курсор вдоль строки ввода.

  • 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 Selects all text and text history.

  • Backspace / Delete – Erase characters.

  • Ctrl-Backspace / Ctrl-Delete – Стереть слова.

  • Return – Execute command.

  • Shift-Return – Add to command history without executing.

Использование

Aliases

Some variables and modules are available for convenience:

  • C: Quick access to bpy.context.

  • D: Quick access to bpy.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.

../_images/editors_python-console_dir.png

Auto Completion

The Console can preview the available members of a module or variable. As an example, type bpy. and press Tab:

../_images/editors_python-console_completion.png

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.

../_images/editors_python-console_bpy-context.png

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.

../_images/editors_python-console_bpy-data.png

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.