Bàn Giao Tiếp 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](../_images/editors_python-console_default.png)
Bàn Giao Tiếp Python.¶
Giao Diện (Interface)¶
Khung Nhìn Chính (Main View)¶
Những Bố Trí Phím (Key Bindings)
NCT (LMB) -- Di Chuyển the con trỏ dọc theo the đầu vào đường nét/thẳng.
Trái (Left) / Phải (Right) -- Di Chuyển the con trỏ bởi/theo cái/số một nhân vật/ký tự.
Ctrl-Trái (Left) / Ctrl-Phải (Right) -- Di Chuyển the con trỏ bởi/theo cái/số một word.
Shift-Left / Shift-Right -- Selects characters to the left/right.
Shift-Ctrl-Trái (Left) / Shift-Ctrl-Phải (Right) -- Lựa Chọn chữ viết tới the trái/phải.
Ctrl-A Lựa Chọn toàn bộ văn bản và văn bản lịch sử.
Phím Lùi (BackSpace)/Xóa (Delete) - Xóa ký tự.
Ctrl-Phím Lùi (BackSpace)/Ctrl-Xóa (Delete) - Xóa từ.
Return - Thực hiện lệnh.
Shift-Return - Thêm vào lịch sử lệnh mà không cần thực thi.
Cách Sử Dụng (Usage)¶
Bí Danh (Aliases)¶
Một số biến số và mô-đun có sẵn để sử dụng thuận tiện:
C
: Truy cập nhanh vàobpy.context
.D
: Truy cập nhanh vàobpy.data
.bpy
: Mô-đun ở cấp bậc cao nhất trong API Python của Blender.
Làm Quen với Môi Trường Bàn Giao Tiếp (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](../_images/editors_python-console_dir.png)
Tự Động Hoàn Chỉnh (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](../_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 (
.
Một Số Ví Dụ (Examples)¶
bpy.context¶
This module gives you access to the current scene, the currently selected objects, the current object mode, and so on.
Ghi chú
Để các lệnh bên dưới hiển thị đầu ra chỉnh tru thì xin hãy đảm bảo rằng bạn đã chọn (các) đối tượng trong Cổng Nhìn 3D.
![../_images/editors_python-console_bpy-context.png](../_images/editors_python-console_bpy-context.png)
Lấy the hiện tại 3Cổng Nhìn chế độ (Đối Tượng, Biên Soạn, Điêu Khắc, v.v.):
bpy.context.mode
Lấy đối tượng đang hoạt động
bpy.context.object
bpy.context.active_object
Thay Đổi the đối tượng đang hoạt động's X coordinate tới 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
Thay Đổi toàn bộ ba địa điểm/vị trí tọa độ vào/trong cái/số một go:
bpy.context.object.location = (1, 2, 3)
Thay Đổi duy X và Y tọa độ:
bpy.context.object.location.xy = (1, 2)
Lấy đối tượng được chọn
bpy.context.selected_objects
Lấy the đối tượng được chọn excluding the đang/hoạt động/năng động cái/số một:
[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](../_images/editors_python-console_bpy-data.png)
bpy.ops¶
"Thao Tác" sẽ được hành động that sẽ được bình thường ra triggered từ một nút bấm hoặc trình mục but có thể đồng thời be được gọi là programmatically. Xin xem bpy.ops (bpy.các thao tác) Application Programming Interface: Giao Diện Lập Trình Ứng Dụng documentation cho/đối với một danh sách của toàn bộ thao tác.