EzyCad scripting
EzyCad embeds script consoles that drive the live document through a public Python-first API under ezy. Lua mirrors the same namespaces (required for WebAssembly). Remote --listen clients use the same Python tree.
Use ezy.help() (or help()) in a console for a short built-in summary.
Availability
Lua |
Python |
|
|---|---|---|
Desktop (Windows) |
Always (built-in Lua library) |
Only if the app was built with Python enabled ( |
WebAssembly |
Yes |
No (not shipped in the browser build). |
Opening the consoles
View -> Lua Console - Toggles the Lua console and script editor tabs.
View -> Python Console - Same layout for Python when the feature is compiled in.
Visibility is remembered with other panes (see usage.md -> Help and Settings).
Layout
Output / history - Results and errors from executed lines.
Input line - Enter a fragment and run it (same as a one-off at the interactive prompt).
Script tabs - Files under
res/scripts/lua(*.lua) orres/scripts/python(*.py) are loaded as editable buffers; Lua scripts are also run on startup so you can define helpers (seebasic.lua/basic.py).
Paths are relative to the app working directory on desktop; on WASM, Lua scripts are under the preloaded /res/scripts/lua tree.
Public API (Python)
Canonical surface (also available in Lua with the same names):
ezy.log / ezy.msg / ezy.help / ezy.get_mode / ezy.set_mode
ezy.save_occt_view_settings / ezy.occt_view_settings_json
ezy.view.*
ezy.view.curr_sketch.* # same object as ezy.sketch
ezy.Shp
Aliases (compatibility): global view is ezy.view; global Shp is ezy.Shp; help() is ezy.help(). ezy.view.curr_sketch is the same object as ezy.sketch. Flat view.add_sketch / add_edge / finish_sketch_edges forward to view.curr_sketch.*.
print is redirected to ezy.log in both consoles.
ezy
Method |
Purpose |
|---|---|
|
Print to the console and the main Log pane |
|
Show a status message |
|
Current application mode name (string) |
|
Switch mode by name |
|
Write settings JSON (including view colors) |
|
Settings JSON string |
|
Print binding summary |
ezy.view
Method |
Purpose |
|---|---|
|
Number of sketches |
|
Number of 3D shapes |
|
Add a box; returns |
|
Add a sphere; returns |
|
Boolean union of two or more |
|
Subtract tools from body; returns |
|
Boolean intersection; returns |
|
Remove one or more |
|
Shape by 0-based index (raises |
|
List of selected document |
|
0-based indices of selected document shapes |
|
Camera vectors: |
|
Set camera vectors |
|
Current sketch API (same as |
ezy.view.curr_sketch / ezy.sketch
Indices are 0-based in Python. Prefer view.curr_sketch for inspection; ezy.sketch is the same object and also used for creation helpers.
Method |
Purpose |
|---|---|
|
Name of the current sketch ( |
|
Read nodes |
|
Read length dimensions |
|
New sketch on |
|
Add a linear edge to the current sketch |
|
Rebuild closed-face topology after bulk edge import |
ezy.Shp
Method |
Purpose |
|---|---|
|
Shape name |
|
Visibility |
Lua notes
Lua exposes the same ezy / ezy.view / ezy.sketch layout. Differences:
Topic |
Lua |
Python |
|---|---|---|
Shape index |
1-based; out of range returns |
0-based; raises |
Selected idx |
1-based in |
0-based |
Sketch index |
1-based for |
0-based |
Methods |
Prefer |
|
WASM |
Available |
Not built |
Sample scripts
res/scripts/python/basic.py-dump_view()usingezy.view(and a legacyviewalias line).res/scripts/python/sierpinski.py- Sierpinski triangle; callcreate_sierpinski_sketch().res/scripts/lua/basic.lua-kv(obj)helper viaezy.log.res/scripts/lua/sierpinski.lua- Same idea for Lua; callcreate_sierpinski_sketch().
Limitations
The API is small and may change between versions; prefer
ezy.help()after upgrades.Scripting is for automation and inspection, not a full replacement for the GUI workflow.
Heavy work on the UI thread can block the app; keep snippets short.
Only APIs under
ezy(and documented aliases) are the supported public scripting contract.
Remote Python (--listen)
Desktop builds with embedded Python can accept console snippets over TCP while the GUI runs. The remote client talks to the same ezy tree as the in-app console.
Launch (default host is localhost when you pass only a port):
EzyCad.exe --listen 8765
EzyCad.exe --listen 127.0.0.1:8765
Bind 0.0.0.0 only if you intentionally expose the port on the network (no authentication).
Importable client (ezycad)
Install is optional. If scripts/ is already on your Python path (as in many IPython setups), just import ezycad. Otherwise either::
pip install -e .
or::
import sys
sys.path.insert(0, r"C:\src\EzyCad\scripts")
import ezycad
Then (keep the connection open — avoid with in IPython if you will call app again later)::
import ezycad
app = ezycad.connect() # 127.0.0.1:8765; EzyCad must be running with --listen
app.ezy.log("hello from remote")
print(app.view.sketch_count())
print(app.view.curr_sketch.node_count())
print(app.ezy.get_mode())
# app.close() when done
If you see a connection / socket error, EzyCad was closed or app was already closed — call ezycad.connect() again.
CLI
python -m ezycad --port 8765
python scripts/ezycad_remote.py -c "ezy.log('hello')"
Raw execute / eval still return a Result (ok / output / result / error). Typed methods raise ezycad.EzyCadError on failure and unwrap simple values (ints, tuples, dicts) from the remote repr.
For general application behavior, see usage.md.