Std SendToPythonConsole

This page has been updated for FreeCAD v26.3.

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 variables in the Python Console referencing selected objects and selected subobjects, along with some other useful variables. They can be used in the development of Python code.

The following variables are created:

Variable Referenced object(s)
sels A list of selection objects (one for each selected object)
sel The last item in sels (belonging to the last selected object)
doc The document containing the selected objects
objs A list with an item for each selected object:

The selected object itself (if it is not a Link)
The linked object (if the selected object is a Link)

obj The last item in objs (belonging to the last selected object)
lnks A list with an item for each selected object:

The selected object itself (if it is a Link)
None (if the selected object is not a Link)

lnk The last item in lnks (belonging to the last selected object)
shps A list with an item for each obj in objs:

The Shape property of obj (for objects that have that property)
The Mesh property of obj (for Mesh objects)
The Points property of obj (for Points objects)
None (for other objects)

shp The last item in shps (belonging to the last item in objs)
subs A list with the selected subobjects. The list is empty if no subobjects have been selected.
sub The last item in subs, or None if subs is empty.
names A list with a tuple for each selected object. Each tuple contains the names of the subobjects belonging to that object. The tuple is empty if no subobjects have been selected for the object.
name The last item in the last tuple in names, or None if that tuple is empty.

Usage

  1. Select one or more objects and/or one or more subobjects belonging to one or more objects.
  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.
  4. The Python Console receives the keyboard focus.

Notes

lnk_shps = [Part.getShape(l) if l else None for l in lnks]
lnk_shp = Part.getShape(lnk) if lnk else None