Std SendToPythonConsole: Difference between revisions

From FreeCAD Documentation
(add note how python console is opened and keyboard focus set in 0.20)
(Moved the description of the new features to the usage section.)
Line 24: Line 24:


<!--T:4-->
<!--T:4-->
The '''Std SendToPythonConsole''' command creates a variable in the [[Python_console|Python console]] referencing a selected object, also (as of 0.20) opens the console if it's not already open and sets the keyboard focus to it. If a subshape of the object is selected two additional variables are created, one referencing the shape of the object and the other referencing the subshape itself. The variables and the code involved can be used to development Python code.
The '''Std SendToPythonConsole''' command creates a variable in the [[Python_console|Python console]] referencing a selected object. If a subshape of the object is selected two additional variables are created, one referencing the shape of the object and the other referencing the subshape itself. The variables and the code involved can be used to development Python code.


</translate>
</translate>
Line 44: Line 44:
#* Select the {{MenuCommand|[[Image:Std_SendToPythonConsole.svg|16px]] Send to Python Console}} option from the [[Tree_view|Tree view]] context menu or [[3D_view|3D view]] context menu.
#* Select the {{MenuCommand|[[Image:Std_SendToPythonConsole.svg|16px]] Send to Python Console}} option from the [[Tree_view|Tree view]] context menu or [[3D_view|3D view]] context menu.
#* Use the keyboard shortcut: {{KEY|Ctrl}}+{{KEY|Shift}}+{{KEY|P}}.
#* Use the keyboard shortcut: {{KEY|Ctrl}}+{{KEY|Shift}}+{{KEY|P}}.
# If required the [[Python_console|Python console]] opens. {{Version|0.20}}
# The [[Python_console|Python console]] receives the keyboard focus. {{Version|0.20}}





Revision as of 10:16, 15 December 2021

Std SendToPythonConsole

Menu location
Edit → Send to Python Console
Workbenches
All
Default shortcut
Ctrl+Shift+P
Introduced in version
0.19
See also
None

Description

The Std SendToPythonConsole command creates a variable in the Python console referencing a selected object. If a subshape of the object is selected two additional variables are created, one referencing the shape of the object and the other referencing the subshape itself. The variables and the code involved can be used to development Python code.

>>> ### Begin command Std_SendToPythonConsole
>>> obj = App.getDocument("Unnamed").getObject("Box")
>>> shp = App.getDocument("Unnamed").getObject("Box").Shape
>>> elt = App.getDocument("Unnamed").getObject("Box").Shape.Edge8
>>> ### End command Std_SendToPythonConsole

Example output: an edge of a Part Box was selected

Usage

  1. Select a single object.
  2. There are several ways to invoke the command:
    • Select the Edit → Send to Python Console option from the menu.
    • Select the Send to Python Console option from the Tree view context menu or 3D view context menu.
    • Use the keyboard shortcut: Ctrl+Shift+P.
  3. If required the Python console opens. introduced in version 0.20
  4. The Python console receives the keyboard focus. introduced in version 0.20