Consola 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

Consola de Python.

Interfaz

Menús del encabezado

Menú Vista

Acercarse/Alejarse

Increases/decreases the font size.

Mover a la Palabra Anterior Ctrl-Izquierda

Mueve el cursor al principio de la palabra anterior. Si el cursor está en medio de una palabra, el cursor se mueve al principio de la palabra actual.

Mover a la Siguiente Palabra Ctrl-Derecha

Mueve el cursor al final de la siguiente palabra. Si el cursor está en medio de una palabra, el cursor se mueve al final de la palabra actual.

Mover al Inicio de Línea Inicio

Mueve el cursor al inicio de la línea actual.

Shift-Home: Selects all text between the cursor and the start of the current line.

Mover al Final de la Línea Fin

Mueve el cursor al final de la línea actual.

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

Menú Consola

Eliminar Todo

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

Eliminar Línea Mayús-Intro.

Eliminará todo en la línea del símbolo del sistema.

Borrar Palabra Anterior Ctrl-Retroceso

Elimina todo entre el cursor y el comienzo de la palabra anterior (separado por puntos). Si el cursor está en medio de una palabra, borra todo hasta el principio de la palabra actual.

Borrar Palabra Siguiente Ctrl-Suprimir

Elimina todo entre el cursor y el final de la siguiente palabra. Si el cursor está en medio de una palabra, borra todo hasta el final de la palabra actual.

Copiar como Script Mayús-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.

Cortar Ctrl-X

Copies the selected text into the clipboard and deletes it.

Copiar Ctrl-C

Copies the selected text into the clipboard.

Pegar Ctrl-V

Pastes into the command line.

Aumentar Sangría Tab

Inserta un carácter de tabulación en el cursor.

Quitar Sangría Mayús-Tab

Elimina la sangría de la selección.

Retroceder en Historial Arriba

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

Avanzar en Historial Abajo

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

Autocompletar Tab

See Auto Completion.

Vista Principal

Atajos de Teclado

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

  • Retroceso / Suprimir – Borra caracteres.

  • Ctrl-Retroceso / Ctrl-Suprimir – Borra palabras.

  • Intro – Ejecuta el comando.

  • Mayús-Intro – Agrega al historial de comandos sin ejecutar.

Uso

Alias

Algunas variables y módulos están disponibles para su comodidad:

  • C: Acceso rápido a bpy.context.

  • D: Acceso rápido a bpy.data.

  • bpy: Módulo API Python de Blender de nivel superior.

Primer vistazo al entorno de la consola

To see the list of global functions and variables, type dir() and press Return to execute it.

../_images/editors_python-console_dir.png

Finalización Automática

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

Ejemplos

bpy.context

This module gives you access to the current scene, the currently selected objects, the current object mode, and so on.

Nota

Para que los siguientes comandos muestren el resultado adecuado, asegúrese de haber seleccionado los objetos en la Vista 3D.

../_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.