Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Turn the reference grid on and off

The Grid command is checkable and presentation-only. This page runs it with no window, shows the view request it returns, and reads the one switch every grid backend agrees on.

Generated page. tools/userdocs.py writes it from tools/workflows/06_grid_visibility.py. Edit the workflow, not this page; python3 tools/userdocs.py --check fails when the two disagree.

Requires: the FerroCAD facade and ferrocad_shell; no GPU and no window.

1. Start from the default

FerroCAD.Grid is the semantic settings object for the reference grid. enabled is the switch a provider reads; it defaults to off.

import json
import ferrocad_shell

FerroCAD.Grid.reset()
Read backValue
FerroCAD.Grid.enabledfalse

2. Run the command

App_ToggleGrid is registered by the shell and is checkable. It flips FerroCAD.Grid.enabled and returns a view request; the shell applies that request and mirrors the result into FerroCADGui.ViewState.

first = json.loads(ferrocad_shell.run_command("App_ToggleGrid"))
Read backValue
Response{“ok”: true, “view”: {“grid”: true, “grid_alpha”: 1.0, “grid_color”: “#94a3b8”, “grid_major”: 100.0, “grid_minor”: 10.0, “grid_radius”: 0.0}}
FerroCAD.Grid.enabledtrue

3. Push the state the window would push

With no window, nothing has mirrored the request yet, so the check mark still reads the old state. set_view_state is the call the shell makes after it applies a request.

ferrocad_shell.set_view_state(json.dumps(first["view"]))
checked = {
    c["id"]: c["checked"]
    for c in json.loads(ferrocad_shell.commands())
    if c["id"] == "App_ToggleGrid"
}
Read backValue
App_ToggleGrid checked{“App_ToggleGrid”: true}
FerroCADGui.ViewState.gridtrue

4. Turn it off again

second = json.loads(ferrocad_shell.run_command("App_ToggleGrid"))
ferrocad_shell.set_view_state(json.dumps(second["view"]))
Read backValue
Response{“ok”: true, “view”: {“grid”: false, “grid_alpha”: 1.0, “grid_color”: “#94a3b8”, “grid_major”: 100.0, “grid_minor”: 10.0, “grid_radius”: 0.0}}
FerroCAD.Grid.enabledfalse

Every grid backend reads this one switch. A provider that kept its own copy would keep drawing after the toggle, which is exactly the defect docs/tasks/grid-visibility.md fixed.