Консоль Python – Python Console

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 – Python Console.

Interface – Інтерфейс

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: Selects all text between the cursor and the start of the current line.

Переміститися на Кінець Рядка – Move to Line End End

Переміщує курсор на кінець поточного рядка.

Shift-End: Selects all text between the cursor and the end of the current line.

Меню «Консоль» – Console Menu

Зчистити Усе – Clear All

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

Зчистити Рядок – Clear Line Shift-Return.

Вилучає все з рядка запрошення.

Видалити Попереднє Слово – 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.

Копіювати як Скрипт – Copy as Script 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

Pastes into the command line.

Відступ – Indent Tab

Вставляє символ табуляції у позиції курсора.

Зневідступ – 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.

Autocomplete Tab

See Auto Completion.

Main View – Головний Огляд

Клавіатурні Прив’язування – Key Bindings

  • LMB – Moves the cursor along the input line.

  • 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 – Selects words to the left/right.

  • Ctrl-A Selects all text and text history.

  • Backspace / Delete – Стирання символів.

  • Ctrl-Backspace / Ctrl-Delete – Стирання слів.

  • Return – Виконання команди.

  • Shift-Return – Додати в історію команд без виконання.

Usage – Використання

Псевдоніми – Aliases

Деякі змінні та модулі доступні для зручності:

  • C: Швидкий доступ до bpy.context.

  • D: Швидкий доступ до bpy.data.

  • bpy: Модуль верхнього рівня Blender Python API.

Перший Погляд на Середовище Консолі – 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 (.

Examples – Приклади

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

Get the active object:

bpy.context.object
bpy.context.active_object

Change the active object’s X coordinate to 1:

bpy.context.object.location.x = 1

Move the active object by 0.5 along the X axis:

bpy.context.object.location.x += 0.5

Change all three location coordinates in one go:

bpy.context.object.location = (1, 2, 3)

Change only the X and Y coordinates:

bpy.context.object.location.xy = (1, 2)

Get the selected objects:

bpy.context.selected_objects

Get the selected objects excluding the active one:

[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.