Run script
run_scriptUse this whenever a task needs many reads or writes, or numbers you would work out in your head: sums per class or storey, one element per bay or grid point (louvres of a bay: one element, repeat), walls along an outline. Runs JavaScript; await moddl.<tool>(args) is any tool call, same args; writes inside take guid, guids or a set (many: one call with guids, not one per guid). All writes land as ONE revision; a throw writes nothing. One script per part of the job (a storey; walls, openings, roof), each under 45 s: the person sees no change while one runs, then each land, and can stop you in between. Writes of one tool (set_properties at one guid, create_elements, copy_elements, insert_in_host): moddl.together([{tool, args}]) is one commit, answers in order; a conflict refuses all (try). Return what you need as JSON (max 8 KB), with n and coverage when you sum. A refusal throws ContractError {code, message, at, detail, try, line}; catch it to go on, it still appears in rejected with its line. console.log goes to log. Answers as outside but without checks: those run once at the end over all it wrote, each finding with its line. dry_run runs it all, puts it back and answers the checks and, when it writes, a plan_id; run_script with that plan_id alone lands exactly that result in seconds, PLAN_CHANGED if the model was written since; never rerun the script (as slow as the dry_run). Time limit 150 s, moddl calls included; at any limit (SCRIPT_LIMIT) nothing is written, finished writes stay a plan_id (try). Lost to a timeout? Repeat with its request_id; without, get_history shows whether it landed. Not callable inside: run_script, export_ifc, undo, restore_revision, render_view, draw_section. No Date, no Math.random, no I/O; at most 200 moddl calls, 1 MB per call argument; a request_id once per script. Limits: get_guide topic script.
Example: const f = await moddl.find_elements({filter:{class:['IfcColumn']},fields:['hull.center_x'],limit:500}); return {n: f.target.n, xs: f.rows.map(r => r['hull.center_x'].value)}
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "run_script"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note | No | Your note, stored with the new revision | |
| script | No | JavaScript body; top-level await and return allowed. Exactly one of script and plan_id | |
| dry_run | No | Preview: the planned effect and a plan_id, nothing written | |
| plan_id | No | From a dry_run of run_script: lands that result unchanged. The human sees the result of the latest dry_run in the viewer until it lands or the model is written | |
| contacts | No | The contact checks at the end. fast: touch and gap between two planar bodies, approximate (source mesh, n_pairs_mesh); clash stays exact. exact: every pair measured exactly. Default: exact, but pairs with an IfcGeographicElement and lost_contact fast | |
| request_id | No | Your id for this call: a repeat answers the first result and writes nothing |