# Editable plugin instances

RC129 adds editable plugin instances to JavaScript API v1. These tools can use a selected drawing object as a reference, generate native CAD and record the parameters that produced it. Open a calibrated board and choose an unlocked CAD or Trace layer to create an instance.

RC136 adds saved recipe inspection, selection of recipe members, variations, and opt-in live preview. Managed output is tied together by its recipe identity across native layers. **Plugin tools → Select recipe members** selects the linked output, including any Scope Note. The saved recipe contains input values and their version. The plugin computes the geometry from those values when it runs.

From RC132, a managed member can be a [Scope Note](/plugins/authoring.md#create-a-scope-note). Keep its stable role and scope to retain its reference across regenerations. Use a [managed plain-text label](/plugins/managed-text-v1.md) for titles and annotations.

From RC134, a managed Scope Note uses A-NOTES by default. The geometry and note are one editable instance and one Undo step even on separate layers. A Trace instance keeps its Scope Notes on Trace. In edit mode use `instance.layerId` for the original drawing layer and `instance.members[i].layerId` for each member's location. Any member can reopen the same instance. Enable and unlock A-NOTES before previewing a mixed instance. From RC173, managed plain-text labels go on A-TEXT, and manual text edits follow their roles when the instance regenerates.

## Try a stair

1. Load the [editable stair example](/plugins/example-stair-session.snipplugin) through **Modules → Load plugin**, review its capabilities and choose **Run tool**.
2. Enter the dimensions and choose **Preview**. When the tool requests a reference, select a native line and choose **Use drawing selection**. The start and direction of the line locate the plan. The line remains editable on its own layer.
3. Inspect the stair plan, cut line, fine hidden continuation, optional developed elevation and calculation text. Choose **Add instance** to place them in one Undo step.
4. Select any member and choose **Plugin tools → Edit selected plugin object**. Change its parameters, preview the replacement and choose **Apply edit**. Save and reopen the board to check the saved values. The same plugin ID must be present to edit the instance again.

The example is a straight stair used to verify the host. The staircase module has its own tool and validation rules.

## Inspect a recipe and create a variation

1. Load [Curved stair recipe](/plugins/example-curved-recipe.snipplugin) through **Modules → Load plugin** on a calibrated scratch Board with writable A-DIMS and A-NOTES layers. Run the tool, choose **Preview**, then **Add instance**. The example creates a plan, developed elevation, native run dimension and calculation Scope Note.
2. Select any member. Choose **Plugin tools → Inspect saved recipe** to see the saved inputs. Choose **Edit selected plugin object** to change that instance in place.
3. Select a member of the original and choose **Plugin tools → Create variation**, then pick a new drawing point. The matching installed plugin opens with the saved inputs. Change **Going** from 280 mm to 320 mm and wait for the preview. Choose **Add instance** to create the variation.
4. Inspect or edit each result separately. The original going is 280 mm. The variation has a different instance ID and retains 320 mm and the new picked location. One Undo removes its plan, elevation, run dimension and Scope Note together.

The example illustrates the recipe workflow. It uses line segments along a curve and a schematic elevation.

## Write an editing tool

Declare `board.pick` for reference capture and `drawing.instance` for instance context and proposals. Declare `ui.form` for parameter controls. The normal [package schema](/plugins/package.schema.json) and [TypeScript declarations](/plugins/api-v1.d.ts) apply.

| Call | Behaviour |
| --- | --- |
| `await snip.board.pick({title,key})` | Pauses the tool while the user selects and confirms native CAD on the open board. An optional stable `key` identifies the reference across previews. Returns a bounded subset of IDs, types, layer IDs, lock state and model bounds, plus available geometry including native open-polyline segments. |
| `await snip.instance.context()` | Returns an edit session with `instance` or a create session with `instance:null`. A variation adds a read-only `sourceInstance` and `targetPoint` to a create session. Snapshots carry the tool version, parameters, parameter version, original coordinate frame, member roles and IDs. |
| `await snip.instance.propose({title,parameterVersion,parameters,members})` | Previews one managed instance. Each member has a stable role, a native shape and optional [appearance settings](/plugins/authoring.md#specify-fill-and-outline-appearance), including solid fill and vector hatching from RC131. Returns `{previewOnly:true,objects}`. The host supplies ownership and the proposed target, and the user applies it in X8SNIP. |

Use the [managed proposal schema](/plugins/instance-propose.schema.json). Declare a unique role for each output, such as `plan.outline`, `plan.cut`, `dimension.developed-run` or `calculation`. A role that stays in the output keeps its object ID. New roles receive new IDs and omitted roles are removed from that instance on Apply. Start with saved parameters in edit mode. Use `parameterVersion` to read older parameter data explicitly before proposing an upgrade.

Read a variation's defaults from `instance ?? sourceInstance`. The picked `targetPoint` is in model millimetres on the active grid, with positive Y up. Reposition the saved baseline or route relative to that point in the plugin, then save the new placement in `parameters`. The original frame maps the recipe to the Board and exposes its pixel origin, rotation in degrees and pixels per millimetre. The host keeps the original instance intact and records the source instance ID and parameter version on the new variation. It supplies the lineage automatically.

Use `snip.ui.form({title,fields,livePreview:true})` to opt in. Edits to valid inputs regenerate the preview after a short pause. The last valid preview stays visible as a guide during recalculation. Apply is available once the preview matches the current inputs and Board revision. Use **Preview** to start with the defaults. Use a stable reference key, such as `"route"`, so unchanged selections can be reused. Use **Pick new reference** when changing the reference.

Coordinates follow the model millimetres and positive Y-up of the active grid. A [native DIM](/plugins/authoring.md#create-a-native-dimension) is managed by its role and lives on A-DIMS even when the plan lives on another layer. A calculation Scope Note can live on A-NOTES as a member of the same instance. Notes have a top-left model anchor, width and height in model mm and a text size in paper mm. From RC135, the host stages up to 800 members and 4,000 vertices in one proposal. The JSON request limit is 1,000,000 characters. Each simple polygon supports 3–128 points. Use a small JSON parameter record with up to 16,000 characters. Keep personally identifying or secret data out of the saved parameters.

The host stores instance metadata on the native geometry, so it follows a native board save and package. Each instance has its own ID. The installed plugin is separate from the drawing, and the geometry is available without it. An independent object copy remains editable as native CAD. A copied object ID does not become another member of the original instance.

Open an edit on the original model grid and calibration. Board changes invalidate a staged preview, and a locked, missing or independently changed member stops replacement. Use the normal CAD tools to edit individual native members where needed. Save the board package to preserve the editable instance and parameters; PDF and DXF are drawing exchanges.

The [Python and MCP gateway](/plugins/gateway.md#managed-recipes) uses the same hosted recipe workflow for managed connector output. Use a stable connector ID and supply the reproducible parameters alongside the proposed geometry. Additive `drawing.propose` and gateway `propose` remain available for ordinary CAD output.
