polyfoammesh.commercial.journal

Journal / Macro Recorder — action recording and playback.

Every user action can be recorded into a replayable journal and played back against different geometry files for automation.

Concepts:
  • JournalEntry: a single recorded action with timestamp and params.

  • Journal: a list of entries that can be saved/loaded as JSON.

  • Recorder: context manager that captures actions.

  • Player: replays a journal against new geometry.

Usage:

journal = Journal()
with journal.recording():
    # ... user performs actions ...
    journal.record("set_cell_sizes", max_cell=0.05, min_cell=0.01)
    journal.record("set_boundary_layers", n_layers=5)
    journal.record("run_mesh")

journal.save("macro.json")

# Playback on different geometry
player = JournalPlayer(journal)
player.play("new_geometry.step")

Classes

Journal()

A recordable and replayable macro journal.

JournalEntry([action, params, timestamp, ...])

A single recorded action.

JournalPlayer(journal)

Replays a journal against one or more geometry files.

class polyfoammesh.commercial.journal.JournalEntry(action='', params=<factory>, timestamp='', duration_s=0.0)[source]

Bases: object

A single recorded action.

Parameters:
action: str = ''
params: dict[str, Any]
timestamp: str = ''
duration_s: float = 0.0
to_dict()[source]
Return type:

dict[str, Any]

class polyfoammesh.commercial.journal.Journal[source]

Bases: object

A recordable and replayable macro journal.

Usage:

journal = Journal()
journal.record("load_geometry", path="model.step")
journal.record("set_cell_sizes", max_cell=0.05, min_cell=0.01)
journal.save("macro.json")
property is_recording: bool
start_recording()[source]

Start recording actions.

Return type:

None

stop_recording()[source]

Stop recording and return captured entries.

Return type:

list[JournalEntry]

record(action, **params)[source]

Record a single action with its parameters.

Parameters:
  • action (str) – Action name (e.g. "set_cell_sizes").

  • **params (Any) – Key-value parameters for the action.

Return type:

JournalEntry

Returns:

The created JournalEntry.

property entries: list[JournalEntry]
property entry_count: int
to_dict()[source]
Return type:

dict[str, Any]

save(path)[source]

Save the journal to a JSON file.

Return type:

None

Parameters:

path (Path | str)

classmethod load(path)[source]

Load a journal from a JSON file.

Return type:

Journal

Parameters:

path (Path | str)

to_python_script(target_geometry='')[source]

Generate a Python script from the journal entries.

The script uses the polyfoammesh.commercial.watertight API to replay the recorded actions.

Parameters:

target_geometry (str) – Path to the geometry file to use during playback.

Return type:

str

Returns:

A string containing the complete Python script.

class polyfoammesh.commercial.journal.JournalPlayer(journal)[source]

Bases: object

Replays a journal against one or more geometry files.

Usage:

journal = Journal.load("macro.json")
player = JournalPlayer(journal)
report = player.play("geometry.step")
print(f"Result: {report.cell_count} cells")
Parameters:

journal (Journal)

play(geometry_path, **overrides)[source]

Execute the journal against the given geometry.

Parameters:
  • geometry_path (str) – Path to the geometry file to mesh.

  • **overrides (Any) – Override parameters for specific actions (e.g. max_cell=0.02).

Return type:

Any

Returns:

The WorkflowResult from WatertightWorkflow.