execute_python
Executes Python code inside Fusion 360's main thread for custom API operations when no dedicated tool fits.
Instructions
Run Python code inside Fusion 360 on its main thread. Use it only when no dedicated tool can do the job.
In scope: adsk (adsk.core, adsk.fusion), app (adsk.core.Application), ui,
design (active adsk.fusion.Design or None), root (design.rootComponent or
None) and params (the params argument, default {}).
Units: the Fusion API itself works in CENTIMETRES and RADIANS. Convert yourself: 25 mm -> 2.5, 90 deg -> math.pi / 2. Strings passed to adsk.core.ValueInput.createByString are Fusion expressions ("25 mm", "width / 2").
Returns JSON {"result", "stdout", "stderr"}: result is the value of the variable
result after the code runs (JSON as is, otherwise its repr); stdout/stderr are
captured and cut at 64 KiB with a truncation marker. If the code raises, the result
is an error FUSION_API_ERROR with the traceback in details, and timeline items the
code added are rolled back (parametric designs only).
Example: code = "sk = root.sketches.add(root.xYConstructionPlane)\n" "sk.sketchCurves.sketchCircles.addByCenterRadius(" "adsk.core.Point3D.create(0, 0, 0), params['r_mm'] / 10)\n" "result = sk.name" params = {"r_mm": 12.5}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Python source to run inside Fusion | |
| params | No | JSON values made available to the code as `params` | |
| timeout_s | No | Seconds to wait for the code to finish |