write_featurescript_feature
Author and apply custom Onshape FeatureScript features in one step, creating a Feature Studio element and instantiating it in the target Part Studio.
Instructions
Paradigm escape hatch. Author an arbitrary FeatureScript custom feature (threads, helices, shells, drafts, sweeps along a path, patterns along a curve -- anything our primitives can't express) and apply it to a Part Studio in one call. The system creates a Feature Studio element in the same workspace, uploads your source, confirms it compiles, fetches the sourceMicroversionId, and instantiates a BTMFeature-134 with the correct e{fs_eid}::m{microversion} namespace.
featureScript is a COMPLETE FS source file. Prelude: FeatureScript 2909;\nimport(path:"onshape/std/geometry.fs",version:"2909.0");. Export exactly one defineFeature(...) whose binding name matches the featureType arg. Minimal worked example (offset plane):
FeatureScript 2909;
import(path:"onshape/std/geometry.fs",version:"2909.0");
annotation { "Feature Type Name" : "My feat" }
export const myFeat = defineFeature(function(context is Context, id is Id, definition is map)
precondition { annotation{"Name":"Offset"} isLength(definition.offset, LENGTH_BOUNDS); }
{
opPlane(context, id + "p", {"plane": plane(vector(0,0,definition.offset), vector(0,0,1), vector(1,0,0))});
});parameters is a list of {id, type, value} dicts to bind precondition variables. type ∈ {quantity, string, boolean, real}. For quantity, value is a unit-tagged string like "25 mm" or "0.5 in".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| elementId | Yes | Target Part Studio element ID | |
| documentId | Yes | ||
| parameters | No | Bind precondition variables. Omit if the custom feature takes no inputs. | |
| featureName | Yes | Human-readable name that shows up in the Onshape feature tree. | |
| featureType | Yes | The exported defineFeature binding name. MUST match the `export const <name> = ...` in featureScript. | |
| workspaceId | Yes | ||
| featureScript | Yes | Complete FS source. Must start with `FeatureScript <N>;` where N is the current std library version (currently 2909). | |
| fsElementName | No | Optional name for the Feature Studio element that carries the source. Defaults to ClaudeFS_<featureType>. |