femm_run_script
Run multi-line MicroPython scripts with FEMM commands as globals, either in the current session to modify its model or in batch mode as a separate engine.
Instructions
Run a multi-line MicroPython script with FEMM's commands as globals (mi_addnode(...) etc.,
no femm. prefix). Give code or path (.py).
mode=inprocess (default): written to <work_dir>/scripts and executed inside this session's
engine with exec(open(p).read()) (VERIFIED on FEMM 5): it sees and changes the session's
model; set a global result (or result_var) to return a value; print() output is NOT
captured (the engine's stdout is discarded).
mode=batch: runs femm_headless --port <free> -run script.py args... as a separate engine
(fresh state, exits at the end); returns stdout, stderr and exit code (1 on a script
error, with the message in stderr). Use for long independent jobs or sys.argv-driven scripts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | ||
| code | No | ||
| mode | No | inprocess | |
| path | No | ||
| session | No | main | |
| timeout | No | ||
| result_var | No | result |