run_python
Execute Python code within FreeCAD to extend capabilities, automate workflows, and directly manipulate documents. Returns output, errors, and return values.
Instructions
Execute Python inside FreeCAD. The escape hatch for anything the typed tools cannot do.
Preloaded names: App/FreeCAD, Gui/FreeCADGui, and doc (the active
document). Globals persist between calls, so you can build state incrementally.
A trailing expression is returned like a REPL; in statement mode, assign to
result to return a value. The document is recomputed afterwards.
Returns stdout, stderr, the value, and a full traceback on failure.
Example -- a sketch-based pad: body = doc.addObject("PartDesign::Body", "Body") sketch = body.newObject("Sketcher::SketchObject", "Sketch") import Part sketch.addGeometry(Part.Circle(App.Vector(0,0,0), App.Vector(0,0,1), 10), False) pad = body.newObject("PartDesign::Pad", "Pad") pad.Profile = sketch pad.Length = 25 result = pad.Name
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| document | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||