Modeling
Math
Utilities
Onshape features
enums

The Onshape Standard Library

Modeling

geometry

This module makes all Onshape Standard Library features and functions available.

New Feature Studios begin with an import of this module,

import(path : "onshape/std/geometry.fs", version : "");

with current version inserted (e.g. 300.0). This gives that Feature Studio access to all functions, types, enums, and constants defined in the Onshape Standard Library.

common

This module makes most common Onshape Standard Library functions available. It can be imported in place of geometry.fs,

import(path : "onshape/std/common.fs", version : "");

into Feature Studios that do not require the full set of Onshape Standard Library features.

context

Context type

A Context is a builtin that stores modeling data, including bodies (solids, sheets, wires, and points), their constituent topological entities (faces, edges, and vertices), variables, feature error states, etc.

Every Onshape Part Studio uses a single Context. All features, operations, and evaluation functions require a context to operate on. Different contexts do not interact, but data may be transferred from one to another using opMergeContexts.

Each context keeps track of the version of the Onshape Standard Library at which it was created. While regenerating a feature that has been "held back" to an older version, the version reported by the context will be the older version, causing subfeatures and operations to emulate old behavior.

canBeContext (value) predicate

Typecheck for Context

isAtVersionOrLater (versionToCheck is FeatureScriptVersionNumber, versionToCompareAgainst is FeatureScriptVersionNumber) returns boolean

isAtInitialMixedModelingReleaseVersionOrLater (context is Context) returns boolean

Returns true if at or after mixed modeling release version.

Id type

An Id identifies a feature or operation in a context. Each feature, subfeature, and operation must have a unique id. Ids are used in queries, error reporting, and accessing data associated with features.

Ids are hierarchical. That is, each operation's id must have a parent id. The root id is constructed with newId() and subIds are added with the overloaded + operator.

EXAMPLE

id + "foo" represents an id named "foo" whose parent is id

EXAMPLE

id + "foo" + "bar" represents an id named "bar" whose parent equals id + "foo"

Internally, an Id is just an array whose elements are strings, representing the full path of the Id.

EXAMPLE

newId() + "foo" + "bar" is equivalent to ["foo", "bar"] as Id, though the expressions like the latter are not recommended in practice.

Within a feature, all operations' ids should be children of the feature's Id (which is always passed into the feature function as the variable id).

Subfeatures should use a similar pattern. For instance, in the snippet below, mySubfeature is a minimal example following good practices for breaking out a set of operations into a subroutine.

annotation { "Feature Type Name" : "My Feature" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
    precondition {}
    {
        fCuboid(context, id + "startingCube", {
                "corner1" : vector(0, 0, 0) * inch,
                "corner2" : vector(1, 1, 1) * inch
        });
        mySubfeature(context, id + "subFeature", qCreatedBy(id + "startingCube", EntityType.EDGE));
        fCuboid(context, id + "endingCube", {
                "corner1" : vector(0, 0, 0) * inch,
                "corner2" : vector(-1, -1, -1) * inch
        });
    }, {});
function mySubfeature(context is Context, id is Id, entities is Query)
{
    opChamfer(context, id + "chamfer", {
            "entities" : entities,
            "chamferType" : ChamferType.EQUAL_OFFSETS,
            "width" : 0.1 * inch
    });
    opFillet(context, id + "fillet1", {
        "entities" : qCreatedBy(id + "chamfer", EntityType.EDGE),
        "radius" : 0.05 * inch
    });
}

The full id hierarchy must reflect creation history. That is, each Id (including parents) must refer to a contiguous region of operations on the context.

Thus, the following code will fail because id + "extrude" alone refers to two non-contiguous regions of history:

for (var i in [1, 2])
{
    opExtrude(context, id + "extrude" + i, {...}); // Fails on second iteration.
    opChamfer(context, id + "chamfer" + i, {...});
}

For the above code, a pattern like id + i + "extrude" or id + ("loop" ~ i) + "extrude" would work as expected, as would the unnested id + ("extrude" ~ i).

Only the following characters are allowed in a string that makes up an Id: a-z, A-Z, 0-9, _, +, -, /. An asterisk * is allowed at the beginning of the string to mark it an "unstable" component (see below).

canBeId (value) predicate

Typecheck for Id

newId () returns Id

Returns an empty id.

makeId (idComp is string) returns Id

Returns an id specified by the given string.

isTopLevelId (id is Id) predicate

True if the Id represents a top-level feature or default geometry (i.e. if the Id has length 1)

ANY_ID const

The string literal "*", which matches any id inside certain queries.

EXAMPLE

qCreatedBy(id + ANY_ID + "fillet")

unstableIdComponent (addend) returns string

Marks a given id component as "unstable" causing queries to treat it as a wildcard. This is useful for when the id component is not expected to be robust, such as an index into the results of an evaluated query.

setVariable (context is Context, name is string, value)

Attach a variable to the context, which can be retrieved by another feature defined later. If a variable of the same name already exists, this function will overwrite it.

EXAMPLE

setVariable(context, "foo", 1) attaches a variable named "foo", with value set to 1, on the context.
ParameterTypeAdditional Info
value

Can be any value, including an array or map with many elements.

setVariable (context is Context, name is string, value, description is string)

Attach a variable with a description to the context, which can be retrieved by another feature defined later. If a variable of the same name already exists, this function will overwrite it.

EXAMPLE

setVariable(context, "foo", 1, "the foo") attaches a variable named "foo", with value set to 1 and the description set to "the foo", on the context.
ParameterTypeAdditional Info
value

Can be any value, including an array or map with many elements.

description string

A string describing the use or purpose of the variable.

getVariable (context is Context, name is string)

Retrieve a variable attached to the context by name. Throws an exception if variable by the given name is not found.

EXAMPLE

getVariable(context, "foo") returns the value assigned to a previously-set variable named "foo".

Variables on a context can also be accessed within a Part Studio using # syntax (e.g. #foo) inside any parameter which allows an expression.

getVariable (context is Context, name is string, defaultValue)

Retrieve a variable attached to the context by name. If variable by the given name is not found, returns defaultValue

EXAMPLE

getVariable(context, "foo", {}) returns the value assigned to a previously-set variable named "foo". If not found returns empty map.

libraryLanguageVersion ()

Returns the language version of the library. Note: this function calls @getLanguageVersion internally, but if you call @getLanguageVersion directly, you may get a different result. That is because @getLanguageVersion returns the language version of the module making the call (which, for a module in std will coincide with the version of std.)

geomOperations

Operations are the basic modeling primitives of FeatureScript. Operations can do extrusion, filleting, transforms, etc. An operation takes a context, an id, and a definition and modifies the context in accordance with the definition. The modifications can be referenced by the passed-in id. Operations return undefined but can fail by throwing an error or they can report warnings or infos. The status can be read with the getFeature... functions in error.fs.

When an operation parameter that requires one entity receives a query that resolves to multiple entities, it takes the first resolved entity.

The geomOperations.fs module contains wrappers around built-in Onshape operations and no actual logic.

opMoveCurveBoundary (context is Context, id is Id, definition is map)

Trims or extends a wire body to an entity or by a distance.

ParameterTypeAdditional Info
definition map
  • wires
Query

The wire bodies to modify.

  • moveBoundaryType
MoveCurveBoundaryType

Optional

Whether to trim or extend. Default is TRIM.

  • trimTo
Query

Required if moveBoundaryType is TRIM.

Single entity to trim wires to.

  • endCondition
CurveExtensionEndCondition

Optional

If moveBoundaryType is EXTEND defines whether to extend wires by a distance of to an entity. Default is BLIND.

  • extensionDistance
ValueWithUnits

Required if endCondition is BLIND

Distance to extend wires.

  • extendTo
Query

Required if endCondition is BLIND

Single entity to extend wires to.

  • extensionShape
CurveExtensionShape

Optional

Specifies how to transition into the curve extensions. Default is SOFT.

  • helpPoint
Query

Required if endCondition is BLIND

Specifies vertex used to choose a solution. If this is not provided, the closest vertex to the bounding entity will be used.

  • flipHeuristics
boolean

Optional

If true, will trim or extend from the opposite end of wires. Default is false.

opBodyDraft (context is Context, id is Id, definition is map)

Apply draft to a part by adding material. The material is added between reference edges and a parting object. These reference edges can be supplied directly, or they can be inferred from face or part queries.

ParameterTypeAdditional Info
definition map
  • selectionType
BodyDraftSelectionType

Optional

Topology class for input. Default is EDGES

  • topEdges
Query

Required if selectionType is EDGES

Edges to draft above parting entity.

  • bottomEdges
Query

Required if selectionType is EDGES and bothSides is true

Edges to draft with angleBelow.

  • faces
Query

Required if selectionType is FACES

Faces to draft. This will split the face with isoclines those for the draft. Additionally, any existing edges bounding faces will be used if they mark a transition from steep faces to non-steep faces for the given pull direction and draft angle.

  • bodies
Query

Required if selectionType is PARTS

Parts to draft. This is equivalent to supplying all faces of the part in faces.

  • excludeFaces
Query

Optional

Faces of bodies to exclude from drafting.

  • angle
ValueWithUnits

The draft angle above the parting object.

  • bothSides
boolean

Optional

If true, draft on both sides of the parting object. Default is false.

  • pullDirection
ValueWithUnits

The pull direction.

  • draftOnSelf
boolean

Optional

If true, then using the drafted part as the parting object. Default is false.

  • partingObject

Required if draftOnSelf is false

A surface from surfaceGeometry.fs or a query to a face or sheet body.

  • matchFacesAtParting
boolean

Optional

If true, then additional material will be added to make the top and bottom of the draft align. Default is false.

  • matchFaceType
BodyDraftMatchFaceType

Optional

How to add material for matchFacesAtParting Default is REFERENCE_EDGE.

  • cornerType
BodyDraftCornerType

Optional

The corner treatment to apply. Default is EXTEND.

  • concaveRepair
BodyDraftConcaveRepairType

Optional

How to resolve intersecting draft faces. Default is NONE.

  • concaveRepairRadius
ValueWithUnits

Required if concaveRepair is RADIUS or MIX.

The radius for intersection repair.

  • keepMaterial
boolean

Optional

If true, an attempt will be made to keep the regions of the part protruding from the tapered faces. Default is false.

  • showRefs
boolean

Optional

If true, then debug data will be generated to show the parting surface and draft edges.

opBoolean (context is Context, id is Id, definition is map)

Performs a boolean operation on multiple solid and surface bodies.

See also

processNewBodyIfNeeded for merging new solids.

joinSurfaceBodiesWithAutoMatching for merging new surfaces.

ParameterTypeAdditional Info
definition map
  • tools
Query

The tool bodies.

  • targets
Query

Required if OperationType is SUBTRACTION or SUBTRACT_COMPLEMENT, or if targetsAndToolsNeedGrouping is true.

The target bodies.

  • operationType
BooleanOperationType

The boolean operation to perform.

EXAMPLE

BooleanOperationType.UNION will merge any tool bodies that intersect or abut. All tool bodies have to be of the same type (solid or surface). When operating on surfaces, surfaces must have coincident or overlapping edges. When several bodies merge, the identity of the tool that appears earliest in the query is preserved (in particular, body color and body name are taken from it).

EXAMPLE

BooleanOperationType.SUBTRACTION will remove the union of all tools bodies from every target body. All tool bodies must be solid bodies. Target bodies could be either solids or surfaces.

EXAMPLE

BooleanOperationType.INTERSECTION will create the intersection of all tool bodies. All bodies must be solid bodies.

EXAMPLE

BooleanOperationType.SUBTRACT_COMPLEMENT will remove the complement of the union of all tool bodies from every target body. All tool bodies must be solid bodies. Target bodies could be either solids or surfaces.
  • targetsAndToolsNeedGrouping
boolean

Optional

This option is for adjusting the behavior to be more suitable for doing the boolean as part of a body-creating feature (such as extrude). Default is false.

  • keepTools
boolean

Optional

If true, the tools do not get consumed by the operation. Default is false.

  • makeSolid
boolean

Optional

In case of surface union try to join surfaces into a solid. Default is false.

opBoundarySurface (context is Context, id is Id, definition is map)

Creates a boundary surface fitting two ordered sets of profiles.

ParameterTypeAdditional Info
definition map
  • uProfileSubqueries
array

An ordered array of two or fewer queries for the profiles in the u direction. These can be edges or wire bodies.

EXAMPLE

[ profileQuery1, profileQuery2 ]
  • vProfileSubqueries
array

Optional

An ordered array of two or fewer queries for the profiles in the v direction. These can be edges or wire bodies.

EXAMPLE

[ profileQuery1, profileQuery2 ]
  • uDerivativeInfo
array

Optional

An array of maps that contain shape constraints at start and end profiles. Each map entry is required to have a profileIndex that refers to the affected profile. Optional fields include a vector to match surface tangent to, a magnitude, and booleans for matching tangents or curvature derived from faces adjacent to affected profile.

EXAMPLE

[ { "profileIndex" : 0, "vector" : vector(1, 0, 0), "magnitude" : 2., "tangentToPlane" : true}, { "profileIndex" : 1, "adjacentFaces" : qFaces } ] The first map would constrain the resulting boundary surface at the first u profile to be tangent to plane with normal vector(1,0,0) and magnitude 2. The second map constrains the boundary surface at the second u profile to match tangents of faces defined by the query qFaces.
  • vDerivativeInfo
array

Optional

An array of maps analogous to uDerivativeInfo, but for v profiles.

  • showIsocurves
boolean

Optional

Show graphical representation of a subset of isoparameteric curves on each face of the created boundary surface. Default false.

  • curveCount
number

Optional

When showIsocurves is true, the number of curves to draw in each direction of each face's grid. Default 10.

opCreateBSplineCurve (context is Context, id is Id, definition is map)

Generates a wire body given a BSplineCurve definition. The spline must have dimension of 3 and be G1-continuous.

ParameterTypeAdditional Info
definition map
  • bSplineCurve
BSplineCurve

The definition of the spline.

opCreateBSplineSurface (context is Context, id is Id, definition is map)

Generates a sheet body given a BSplineSurface definition. The spline must have dimension of 3 and be G1-continuous.

ParameterTypeAdditional Info
definition map
  • bSplineSurface
BSplineSurface

The definition of the spline surface.

  • boundaryBSplineCurves
array

Optional

An array of BSplineCurves defined in the parameter space of bSplineSurface to use as the boundary of the created sheet body. The boundary must form a single closed loop on the surface. The dimension of each curve must be 2, as the boundaries are being defined in UV space of the created surface. If no boundary is supplied, the created sheet body will cover the full parameter range of bSplineSurface.

  • makeSolid
boolean

Optional

When set to true, the operation will produce a solid instead of a sheet if the surface encloses a region. Default is false.

opCreateCompositePart (context is Context, id is Id, definition is map)

Create a composite part.

ParameterTypeAdditional Info
definition map
  • bodies
Query

Bodies from which to create the composite part. .

  • closed
boolean

Optional

A closed composite part consumes its constituent bodies, so that they are not available interactively for individual selection. Default is false.

opModifyCompositePart (context is Context, id is Id, definition is map)

Modifies a composite part.

ParameterTypeAdditional Info
definition map
  • composite
Query

Existing composite part to modify.

  • toAdd
Query

Bodies to add to the composite part.

  • toRemove
Query

Bodies to remove from the composite part.

opChamfer (context is Context, id is Id, definition is map)

Adds a chamfer to given edges and faces.

ParameterTypeAdditional Info
definition map
  • entities
Query

Edges and faces to chamfer.

  • chamferType
ChamferType

Determines where the new edges of the chamfer are positioned.

EXAMPLE

ChamferType.EQUAL_OFFSETS places both new edges width away from each original edge.

EXAMPLE

ChamferType.TWO_OFFSETS places edges width1 and width2 away.

EXAMPLE

ChamferType.OFFSET_ANGLE places one edge width away, and chamfers at an angle from that edge.
  • width
ValueWithUnits

Required if chamferType is EQUAL_OFFSETS or OFFSET_ANGLE.

EXAMPLE

0.2 * inch
  • width1
ValueWithUnits

Required if chamferType is TWO_OFFSETS.

  • width2
ValueWithUnits

Required if chamferType is TWO_OFFSETS.

  • angle
ValueWithUnits

Required if chamferType is OFFSET_ANGLE.

  • oppositeDirection
boolean

Required if chamferType is OFFSET_ANGLE or TWO_OFFSETS.

true to reverse the two edges.

  • tangentPropagation
boolean

Optional

true to propagate the chamfer along edges tangent to those passed in. Defaults to false.

CurveOnFaceDefinition type

Describes a set of isoparametric curves on a face.

ValueTypeDescription
CurveOnFaceDefinition map
  • face
Query

Face the curves are meant to lie on.

  • creationType
FaceCurveCreationType

Determines the type of curves. Currently supports isoparameter curves only in primary or secondary directions, either equally spaced or defined by a parameter array.

  • names
array

An array of distinct non-empty strings to identify the curves created.

  • nCurves
number

Required if creationType is DIR1_AUTO_SPACED_ISO or DIR2_AUTO_SPACED_ISO

Number of curves.

  • parameters
array

Required if creationType is DIR1_ISO or DIR2_ISO

Parameters to create curves at.

canBeCurveOnFaceDefinition (value) predicate

Typecheck for CurveOnFaceDefinition

curveOnFaceDefinition (face is Query, creationType is FaceCurveCreationType, names is array, nCurves is number) returns CurveOnFaceDefinition

Returns a new CurveOnFaceDefinition.

curveOnFaceDefinition (face is Query, creationType is FaceCurveCreationType, names is array, parameters is array) returns CurveOnFaceDefinition

opCreateCurvesOnFace (context is Context, id is Id, definition is map)

Generates isoparametric curves of faces. That is, for each specified surface parameter value, creates a new wire body following the curve which keeps the surface parameter at that constant value.

ParameterTypeAdditional Info
definition map
  • curveDefinition
array

An array of CurveOnFaceDefinitions that describe group of curves per face.

  • showCurves
boolean

Optional

Whether to display isoparameteric curves in color in the preview.

  • useFaceParameter
boolean

Optional

For Onshape internal use.

opDeleteBodies (context is Context, id is Id, definition is map)

Deletes bodies from the context.

ParameterTypeAdditional Info
definition map
  • entities
Query

Entities to delete. Passing in entities other than bodies deletes their owning bodies.

opDeleteFace (context is Context, id is Id, definition is map)

This is a direct editing operation that attempts to delete faces of a solid body and extend other faces to fill the hole.

ParameterTypeAdditional Info
definition map
  • deleteFaces
Query

Faces to delete.

  • includeFillet
boolean

true to also delete fillets adjacent to the input faces.

  • capVoid
boolean

If capVoid is true and the deleted face cannot be filled by extending the surrounding faces, will attempt to replace the face with a planar face.

  • leaveOpen
boolean

Optional

If leaveOpen is true the void from deleting faces is left open, potentially creating a surface out of a solid body. Default is false.

opDraft (context is Context, id is Id, definition is map)

Applies a given draft angle to faces.

ParameterTypeAdditional Info
definition map
  • draftType
DraftType

Specifies a reference surface (e.g. a neutral plane) or reference entity draft.

EXAMPLE

DraftType.REFERENCE_SURFACE for a reference surface draft
  • draftFaces
Query

Required if draftType is REFERENCE_SURFACE

The faces to draft for a REFERENCE_SURFACE draft.

  • referenceSurface

Required if draftType is REFERENCE_SURFACE

A face or plane that defines the neutral surface for a REFERENCE_SURFACE draft. draftFaces will remain unchanged where they intersect referenceSurface. Can be either a Query or a Plane.

  • referenceEntityDraftOptions
array

Required if draftType is REFERENCE_ENTITY

An array of maps of the form ("face", "references", "angle"). "face" should be a Query for exactly one face. "references" should be a Query for at least one edge attached to the face. The "face" will be drafted while the geometry of the "references" remains unchanged. "angle" is an optional ValueWithUnits parameter between -89.9 and 89.9 degrees which overrides the default angle parameter.

  • pullVec
Vector

The 3d direction relative to which the draft is applied.

EXAMPLE

vector(0, 0, 1) .
  • angle
ValueWithUnits

The draft angle, must be between 0 and 89.9 degrees.

EXAMPLE

3 * degree
  • tangentPropagation
boolean

Optional

For a REFERENCE_SURFACE draft, true to propagate draft across tangent faces. Default is false.

  • referenceEntityPropagation
boolean

Optional

For a REFERENCE_ENTITY draft, true to collect new reference entities and faces by pulling in edges connected to the specified reference edges. Connected edges on the same face or on tangent connected faces will be pulled in. Default is false.

  • reFillet
boolean

Optional

true to attempt to defillet draft faces before the draft and reapply the fillets after. Default is false.

opExtractWires (context is Context, id is Id, definition is map)

Generates wire bodies from the supplied edges. If the edges are disjoint multiple wires will be returned. If the edges overlap or cross, or more than two meet at a point, the function will fail.

ParameterTypeAdditional Info
definition map
  • edges
Query

The edges to be extracted.

opExtrude (context is Context, id is Id, definition is map)

Extrudes one or more edges or faces in a given direction with one or two end conditions. Faces get extruded into solid bodies and edges get extruded into sheet bodies.

ParameterTypeAdditional Info
definition map
  • entities
Query

Edges and faces to extrude.

  • direction
Vector

The 3d direction in which to extrude.

EXAMPLE

evOwnerSketchPlane(context, {"entity" : entities}).normal to extrude perpendicular to the owner sketch

EXAMPLE

evPlane(context, {"face" : entities}).normal to extrude perpendicular to the first planar entity
  • endBound
BoundingType

The type of bound at the end of the extrusion. Cannot be SYMMETRIC or UP_TO_VERTEX.

EXAMPLE

BoundingType.BLIND
  • endDepth
ValueWithUnits

Required if endBound is BLIND.

How far from the entities to extrude.

EXAMPLE

1 * inch
  • endBoundEntity
Query

Required if endBound is UP_TO_SURFACE or UP_TO_BODY.

The face or body that provides the bound.

  • endTranslationalOffset
ValueWithUnits

Optional

The translational offset between the extrude end cap and the end bound entity. The direction vector for this is the same as direction: negative values pull the end cap away from the bound entity when endDepth is positive. endOffset will only have an effect if endBound is UP_TO_SURFACE, UP_TO_BODY, or UP_TO_NEXT.

  • startBound
BoundingType

Optional

The type of start bound. Default is for the extrude to start at entities. Cannot be SYMMETRIC or UP_TO_VERTEX.

  • isStartBoundOpposite

Required if is UP_TO_SURFACE, UP_TO_BODY, or UP_TO_NEXT.

Whether the startBound extends in the opposite direction from the profile as the endBound. Defaults to true if not supplied.

  • startDepth
ValueWithUnits

Required if startBound is BLIND.

How far from the entities to start the extrude. The direction vector for this is the negative of direction: positive values make the extrusion longer when endDepth is positive.

  • startBoundEntity
Query

Required if startBound is UP_TO_SURFACE or UP_TO_BODY.

The face or body that provides the bound.

  • startTranslationalOffset
ValueWithUnits

Optional

The translational offset between the extrude start cap and the start bound entity. The direction vector for this is the negative of direction: negative values pull the end cap away from the bound entity when startDepth is positive. startOffset will only have an effect if startBound is UP_TO_SURFACE, UP_TO_BODY, or UP_TO_NEXT.

opFaceBlend (context is Context, id is Id, definition is map)

Performs a face blend between two walls of faces.

ParameterTypeAdditional Info
definition map
  • side1
Query

First set of faces, must belong to the same body.

  • side2
Query

Second set of faces, must belong to the same body.

  • flipSide1Normal
boolean

Wether to flip side 1's normal.

  • flipSide2Normal
boolean

Wether to flip side 2's normal.

  • propagation
boolean

Optional

Whether to propagate the blend.

  • propagationType
FaceBlendPropagation

Optional

How to propagate the blend. FaceBlendPropagation.TANGENT will propagate over tangent faces. FaceBlendPropagation.ADJACENT will propagate over all adjacent faces. FaceBlendPropagation.CUSTOM allows specification of a maximum angle between faces for propagation. Defaults is FaceBlendPropagation.TANGENT.

  • propagationAngle
ValueWithUnits

Optional

Maximum angle between faces for propagation. Used if propagationType is FaceBlendPropagation.CUSTOM. Default is 0 * radian.

  • crossSection
FaceBlendCrossSection

The cross section type of the blend.

  • spine
Query

Required if crossSection is DISC.

The spine of the blend. The blend's cross section will be orthogonal to the spine.

  • blendControlType
BlendControlType

Whether the blend is controled by a constant radius or a constant width.

  • crossSectionShape
FaceBlendCrossSectionShape

What shape the cross section of the blend will be.

  • radius
ValueWithUnits

Required if blendControlType is RADIUS.

The radius of the cross section.

  • width
ValueWithUnits

Required if blendControlType is WIDTH.

The width of the blend.

  • asymmetric
boolean

Optional

Wether the radius or width is the same on each wall.

  • secondRadius
ValueWithUnits

Required if blendControlType is RADIUS and asymmetric is true.

The radius of the cross section from side 2.

  • widthRatio
number

Required if blendControlType is WIDTH and asymmetric is true.

How the blend will be divided between the walls. If widthRatio < 1, it will be wider towards side 1. If widthRatio > 1, it will be wider towards side 2.

  • rho
number

Required if crossSectionShape is CONIC

Parameter of the conic cross section shape.

  • magnitude
number

Required if crossSectionShape is CURVATURE

Parameter of the curvature cross section shape.

  • tangentHoldLines
boolean

Optional

Whether to use the content of tangentEdges and inverseTangentEdges.

  • tangentEdges
Query

Optional

Edges to use as tangent hold lines.

  • inverseTangentEdges
Query

Optional

Edges to use as inverse tangent hold lines.

  • conicHoldLines
boolean

Optional

Whether to use the content of conicEdges and inverseConicEdges.

  • conicEdges
Query

Optional

Edges to use as conic hold lines.

  • inverseConicEdges
Query

Optional

Edges to use as inverse conic hold lines.

  • hasCliffEdges
boolean

Optional

Whether to use the content of cliffEdges.

  • cliffEdges
Query

Optional

Edges to use as cliff edges.

  • hasCaps
boolean

Optional

Whether to use the content of caps.

  • caps
array

Optional

Entities and flip flags to use as caps. Each map should contain an entity Query element and a flip boolean element.

  • hasLimits
boolean

Optional

Whether to use the content of limitPlane1, limitPlane2, faceLimits and edgeLimit.

  • limitPlane1
Query

Optional

First plane to limit the blend.

  • limitPlane1Flip
boolean

Whether to flip the first plane normal. Defines which side of the plane the blend will be.

  • limitPlane2
Query

Optional

Second plane to limit the blend.

  • limitPlane2Flip
boolean

Whether to flip the first plane normal. Defines which side of the plane the blend will be.

  • faceLimits
Query

Optional

Faces to use as limits to the blend.

  • edgeLimit
array

Optional

Edges and adjacent faces to use as limits. Each map should contain an edge Query element and an edgeLimitSide query element.

  • hasHelpPoint
boolean

Optional

Whether to use the content of helpPoint.

  • helpPoint
Query

Optional

Vertex or mate connector to use as help point. In case the blend parameters create several blends, only the blend closest to the help point will be kept.

  • trim
FaceBlendTrimType

Optional

How to trim the blend.

  • detach
boolean

Optional

Whether not to attach the blend(s) to the sides, creating new sheet bodies.

  • showIsocurves
boolean

Optional

Show graphical representation of a subset of isoparameteric curves of the created surface. Default false.

  • curveCount
number

Optional

When showIsocurves is true, the number of curves to draw in each direction of the grid. Default 10.

opFillet (context is Context, id is Id, definition is map)

For edges, performs a fillet on the edge. For faces, performs a fillet on all edges adjacent to the face.

ParameterTypeAdditional Info
definition map
  • entities
Query

Edges and faces to fillet.

  • radius
ValueWithUnits

The fillet radius.

EXAMPLE

1 * inch
  • tangentPropagation
boolean

Optional

true to propagate the fillet along edges tangent to those passed in. Default is false.

  • crossSection
FilletCrossSection

Optional

Fillet cross section. One of CIRCULAR, CONIC, CURVATURE. Default is CIRCULAR.

  • rho
number

Required if crossSection is CONIC.

A number between 0 and 1, specifying the Rho value of a conic fillet

EXAMPLE

0.01 creates a flat, nearly-chamfered shape.

EXAMPLE

0.99 creates a pointed, nearly-unchanged shape.
  • magnitude
number

Required if crossSection is CURVATURE.

A number between 0 and 1, specifying the magnitude of curvature match.

  • partialFilletBounds
array

Optional

An array of maps representing the boundaries of a partial fillet. Each map should contain a boundaryEdge query, a boundaryParameter value, a isFlipped boolean

EXAMPLE

[{ "boundaryEdge" : edgeQuery0, "boundaryParameter" : 0.3, "isFlipped" : false }, { "boundaryEdge" : edgeQuery1, "boundaryParameter" : 0.6, "isFlipped" : true }]
  • isVariable
boolean

Optional

Fillet controls can be varied at vertices via vertexSettings. Default is false.

  • vertexSettings
array

Optional

An array of maps representing fillet settings at specified vertices. Each map should contain a vertex query, a vertexRadius value, a variableMagnitude if the crossSection is FilletCrossSection.CURVATURE, and a variableRho if the crossSection is FilletCrossSection.CONIC.

EXAMPLE

[{ "vertex" : vertexQuery0, "vertexRadius" : 1 * inch, "variableRho" : 0.2 }, { "vertex" : vertexQuery1, "vertexRadius" : 2 * inch, "variableRho" : 0.8 }]
  • pointOnEdgeSettings
array

Optional

An array of maps representing fillet settings at specified points on edges. Each map should contain an edge query, an edgeParameter value, a pointOnEdgeRadius value, a pointOnEdgeVariablMagnitude if the crossSection is FilletCrossSection.CURVATURE, and a pointOnEdgeVariableRho if the crossSection is FilletCrossSection.CONIC.

EXAMPLE

[{ "edge" : edgeQuery0, "edgeParameter" : 0.3, "pointOnEdgeRadius" : 1 * inch }, { "edge" : edgeQuery1, "edgeParameter" : 0.6, "pointOnEdgeRadius" : 2 * inch }]
  • smoothTransition
boolean

Required if isVariable is true

Whether to create a smoother transition between each vertex.

  • allowEdgeOverflow
boolean

Optional

Allow opFillet to modify nearby edges to maintain the fillet profile. Default is true.

  • keepEdges
Query

Optional

Edges you do not want opFillet to modify if allowEdgeOverflow is true.

  • smoothCorners
boolean

Optional

Allow opFillet to smooth all suitable corners and prevent creation of sharp edges. Default is false.

  • smoothCornerExceptions
Query

Optional

Vertices you do not want opFillet to smooth if smoothCorners is true.

  • createDetachedSurface
boolean

Optional

Operation does not modify the body of the selected edges, but results in surface geometry of fillet. Default is false.

opFillSurface (context is Context, id is Id, definition is map)

Generates a surface body from supplied boundary and internal constraints. The boundaries are defined as edge queries for each continuity constraint. The internal constraints may be defined as a set of support vertices.

ParameterTypeAdditional Info
definition map
  • edgesG0
Query

The edges with position constraints.

  • edgesG1
Query

The edges with tangency constraints.

  • edgesG2
Query

The edges with curvature constraints.

  • guideVertices
Query

The vertices the resulting surface is expected to interpolate.

  • showIsocurves
boolean

Optional

Show graphical representation of a subset of isoparameteric curves of the created surface. Default false.

  • curveCount
number

Optional

When showIsocurves is true, the number of curves to draw in each direction of the grid. Default 10.

opFitSpline (context is Context, id is Id, definition is map)

Creates a 3D cubic spline curve through an array of 3D points.

ParameterTypeAdditional Info
definition map
  • points
array

An array of Vectors with length units for the spline to interpolate. If the first point is the same as the last point, the spline is closed.

EXAMPLE

[
    vector( 1,  1,  1) * inch,
    vector(-1,  1, -1) * inch,
    vector( 1, -1, -1) * inch,
    vector(-1, -1,  1) * inch,
    vector( 1,  1,  1) * inch
]
  • parameters
array

Optional

An array of doubles, parameters corresponding to the points.

  • startDerivative
Vector

Optional

A Vector with length units that specifies the derivative at the start of the resulting spline (according to the arcLengthParameterization set to false).

  • endDerivative
Vector

Optional

A Vector with length units that specifies the derivative at the end of the resulting spline. Ignored if spline is closed.

  • start2ndDerivative
Vector

Optional

A Vector with length units that specifies the second derivative at the start of the resulting spline. Ignored if spline is closed, or if startDerivative is not defined

  • end2ndDerivative
Vector

Optional

A Vector with length units that specifies the second derivative at the end of the resulting spline. Ignored if spline is closed, or if endDerivative is not defined

  • derivatives
map

Optional

A map of derivatives at non-end points. Entries should be index : derivative, where index is an integer between 1 and size(points) - 2 and derivative is a Vector that specifies the derivative at points[index].

opFlipOrientation (context is Context, id is Id, definition is map)

Reverses the orientation of sheet bodies.

ParameterTypeAdditional Info
definition map
  • bodies
Query

Sheet bodies whose orientation should be flipped.

opFullRoundFillet (context is Context, id is Id, definition is map)

Creates a full round fillet, replacing the center face(s) with circular profile face(s) of varying radius, joining the selected side faces.

ParameterTypeAdditional Info
definition map
  • side1Face
Query

A face on one side of the blend.

  • side2Face
Query

A face on another side of the blend.

  • centerFaces
Query

The face(s) to be replaced.

  • tangentPropagation
boolean

Optional

true to propagate the fillet across side face tangencies. Default is true.

opHelix (context is Context, id is Id, definition is map)

Creates a helical and possibly spiral curve.

ParameterTypeAdditional Info
definition map
  • direction
Vector

The direction of the helix axis.

EXAMPLE

vector(0, 0, 1)
  • axisStart
Vector

A point on the helix axis.

EXAMPLE

vector(0, 0, 0) * inch
  • startPoint
Vector

The start point of the infinite helix. Must be off the axis. This is the point at which the created curve would actually start if the first number of interval is 0.

EXAMPLE

vector(1, 0, 0) * inch
  • interval
Vector

An array of two numbers denoting the interval of the helix in terms of revolution counts.

EXAMPLE

[0, 10] will create a curve with 10 revolutions.
  • clockwise
boolean

EXAMPLE

true if this is a clockwise helix when viewed along direction.
  • helicalPitch
ValueWithUnits

Distance along the axis between successive revolutions.

EXAMPLE

0.1 * inch will create a helix with 10 revolutions per inch.

EXAMPLE

0 * inch produces a planar Archimedean spiral.
  • spiralPitch
ValueWithUnits

Change in radius between successive revolutions.

EXAMPLE

0 * inch produces a helix that lies on a cylinder.

opHole (context is Context, id is Id, definition is map) returns array

Creates hole tools referencing a set of targets, optionally subtracting the tools from the targets. If some tools cannot be built, the operation will still succeed and indicate in its return value which holes failed to build. If no tools can be built, the operation will fail.

ParameterTypeAdditional Info
definition map
  • holeDefinition
HoleDefinition

The definition of the shape of the desired holes.

EXAMPLE

holeDefinition([holeProfile(HolePositionReference.AXIS_POINT, 0 * inch, 0.1 * inch), holeProfile(HolePositionReference.AXIS_POINT, 1 * inch, 0 * inch)])
  • axes
array

An array of Lines each of whose origin represents the start position of a hole, and whose direction represents the drill direction of the hole.

EXAMPLE

[line(vector(-1, -1, 0) * inch, vector(0, 0, -1)), line(vector(1, 1, 0) * inch, vector(0, 0, -1))]
  • identities
array

Optional

An array of queries, one per axis in axes, used to disambiguate each of the created holes. Each query should resolve to exactly one entity. Providing this information does not change the geometric outcome, but stabilizes references to the holes with respect to upstream changes to the model.

  • targets
Query

Required if holeDefinition contains any profiles that do not reference HolePositionReference.AXIS_POINT, or if subtractFromTargets is true

A set of bodies to target. The shape of the produced holes is dependent on the shape of these targets (as specified in the supplied HoleDefinition), so the full set of targeted bodies should always be supplied, even if subtractFromTargets is false.

  • subtractFromTargets
boolean

Optional

true if the hole geometry should be subtracted from the targets. false if the targets should not be modified, and the hole tools should be outputted as new solid bodies. Default is true. To subtract from a subset of targets, set this to true and supply a set of excluded targets as targetsToExcludeFromSubtraction. Removing the set of excluded targets from targets instead of using targetsToExcludeFromSubtraction is not the correct way to call this interface, and may result in the shape of the hole changing.

  • targetsToExcludeFromSubtraction
Query

Optional

If supplied and subtractFromTargets is true, the given targets are excluded from the subtraction. Ignored if subtractFromTargets is false

  • keepTools
boolean

Optional

If subtractFromTargets is true, controls whether the hole tools should be outputted as new solid bodies. Default is false. Ignored if subtractFromTargets is false; in that case hole tools are always outputted as new solid bodies.

Return typeDescription
array

An array representing target intersection information for each hole. The array is aligned with the axes input. Each item in the array is a map containing a boolean field success, which indicates whether the tool was successfully built. If success is true the map will contain three additional entries: targetToDepthExtremes, positionReferenceInfo and holeDepth.

The value of targetToDepthExtremes is a map mapping the targets that the given hole intersects to a map of intersection information for those targets. Only targets that are intersected by the hole will be present in the map. Each map key is a Query for one of the targets, and the corresponding value is itself a map of the form { "firstEntrance" : firstEntranceDistance, "fullEntrance" : fullEntranceDistance, "firstExit" : firstExitDistance, "fullExit" : fullExitDistance }

firstEntranceDistance, fullEntranceDistance, firstExitDistance, and fullExitDistance are ValueWithUnits representing distances, along the axis, from the origin point of the axis to various important markers on the infinite hole cylinder. firstEntranceDistance and fullEntranceDistance represent the range over which the infinite hole cylinder enters the part, with firstEntranceDistance representing where the infinite hole cylinder first enters the part, and fullEntranceDistance representing where the infinite hole cylinder fully enters the part. These values are distinct when the entrance face into the part is slanted (or otherwise irregular). firstExitDistance and fullExitDistance similarly represent the range over which the infinite hole cylinder exits the part.

The value of positionReferenceInfo is a map whose keys are the HolePositionReferences found in the holeDefinition and whose value is a map of the form { "referenceRootStart" : referenceRootStartDistance, "referenceRootEnd" : referenceRootEndDistance, "target" : targetQuery }.

referenceRootStartDistance is a ValueWithUnits representing the distance, along the axis, from the origin point of the axis to the first coincidence between the infinite hole cylinder and the reference in question. referenceRootEndDistance is a similar measurement to the last coincidence between the infinite hole cylinder and the reference in question. For flat references, such as a TARGET_START referencing the top face of a cube, these two values will be the same. The values will differ for slanted (or otherwise irregular) references where the infinite hole cylinder interacts with the reference over a range, rather than at a single distance.

targetQuery is a Query for the target that defines that position reference.

holeDepth is a ValueWithUnits representing the distance, along the axis from the first entrance of the intersected targets to the termination entity. Used for references such as UP_TO_ENTITY and UP_TO_NEXT to get a calculated depth of a hole.

EXAMPLE

// For an opHole operation creating two holes, both going into two stacked
// parts, the first of which being 1 inch thick with a slightly slanted top
// and flat bottom and the second being 3 inches thick with a flat top and
// bottom, and the holeDefinition referencing both TARGET_START and
// LAST_TARGET_START the return value may look like:
[
    { // First hole (successful)
        "success" : true,
        "targetToDepthExtremes" : {
                    (firstTargetQuery)  : {
                            "firstEntrance" : 0.1 * inch,
                            "fullEntrance" : 0.3 * inch,
                            "firstExit" : 1 * inch,
                            "fullExit" : 1 * inch
                        },
                    (secondTargetQuery) : {
                            "firstEntrance" : 1 * inch,
                            "fullEntrance" : 1 * inch,
                            "firstExit" : 4 * inch,
                            "fullExit" : 4 * inch
                        }
                },
        "positionReferenceInfo" : {
                    HolePositionReference.TARGET_START : {
                            "referenceRootStart" : 0.1 * inch,
                            "referenceRootEnd" : 0.3 * inch,
                            "target" : firstTargetQuery
                        },
                    HolePositionReference.LAST_TARGET_START : {
                            "referenceRootStart" : 1 * inch,
                            "referenceRootEnd" : 1 * inch,
                            "target" : secondTargetQuery
                        },
                }
    },
    { // Second hole (successful)
        "success" : true,
        "targetToDepthExtremes" : {
                    (firstTargetQuery)  : {
                            "firstEntrance" : 0.4 * inch,
                            "fullEntrance" : 0.6 * inch,
                            "firstExit" : 1 * inch,
                            "fullExit" : 1 * inch
                        },
                    (secondTargetQuery) : {
                            "firstEntrance" : 1 * inch,
                            "fullEntrance" : 1 * inch,
                            "firstExit" : 4 * inch,
                            "fullExit" : 4 * inch
                        }
                },
        "positionReferenceInfo" : {
                    HolePositionReference.TARGET_START : {
                            "referenceRootStart" : 0.4 * inch,
                            "referenceRootEnd" : 0.6 * inch,
                            "target" : firstTargetQuery
                        },
                    HolePositionReference.LAST_TARGET_START : {
                            "referenceRootStart" : 1 * inch,
                            "referenceRootEnd" : 1 * inch,
                            "target" : secondTargetQuery
                        },
                }
    },
    { // Third hole (unsuccessful)
        "success" : false
    }
]

opImportForeign (context is Context, id is Id, definition is map)

Brings foreign geometry into the context. This function is used for importing uploaded parts.

ParameterTypeAdditional Info
definition map
  • blobData
CADImportData

Reference to a blob element hosting uploaded CAD data.

  • flatten
boolean

Optional

Whether to flatten assemblies; defaults to false.

  • yAxisIsUp
boolean

Optional

If true, the y axis in the import maps to the z axis and z maps to -y. If false (default), the coordinates are unchanged.

  • isModifiable
boolean

Optional

Whether the imported data is modifiable (default) or not.

opCreateIsocline (context is Context, id is Id, definition is map)

Creates wires corresponding to the given faces's isocline edges. Each isocline follows a path along a face with a constant angle in the (-90, 90) degree range (e.g., lines of latitude on a sphere). This angle is the face tangent plane's angle with respect to the direction with its sign determined by the dot product of direction and the face normal, and is analogous to the angle used in draft analysis. Depending on the face geometry, there may be zero, one, or multiple isoclines on each face.

ParameterTypeAdditional Info
definition map
  • faces
Query

The faces on which to imprint isoclines.

  • direction
Vector

A reference direction.

  • angle
ValueWithUnits

The isocline angle with respect to the direction in the (-90, 90) degree range.

opLoft (context is Context, id is Id, definition is map)

Creates a surface or solid loft fitting an ordered set of profiles, optionally constrained by guide curves.

ParameterTypeAdditional Info
definition map
  • profileSubqueries
array

An ordered array of queries for the profiles. For a solid loft, these must be sheet bodies, faces, or vertices. For a surface loft, these could be wire bodies, sheet bodies, faces, edges, or vertices.

EXAMPLE

[ profileQuery1, profileQuery2 ]
  • guideSubqueries
array

Optional

An array of queries for guide curves. Each guide curve should intersect each profile once.

  • connections
array

Optional

An array of maps to define multiple profile alignments. Each connection map should contain:

(1) connectionEntities query describing an array of vertices or edges (one per profile),

(2) connectionEdges an array of individual queries for edges in connectionEntities. The order of individual edge queries should be synchronized with connectionEdgeParameters.

(3) connectionEdgeParameters array - an ordered and synchronized array of parameters on edges in connectionEdgeQueries

EXAMPLE

[ {"connectionEntities" : qVertexAndEdge1, "connectionEdges" : [qEdge1], "connectionEdgeParameters" : [0.25]} {"connectionEntities" : qVertexAndEdge2, "connectionEdges" : [qEdge2], "connectionEdgeParameters" : [0.75]}]
  • connectionsArcLengthParameterization
boolean

Optional

Defaults to false for better performance. Controls interpretation of connectionEdgeParameters. If evDistance, evEdgeTangentLine etc. are called in conjunction with opLoft the same value should be passed as arcLengthParameterization there.

  • makePeriodic
boolean

Optional

Defaults to false. A closed guide creates a periodic loft regardless of this option.

  • bodyType
ToolBodyType

Optional

Specifies a SOLID or SURFACE loft. Default is SOLID.

  • trimGuidesByProfiles
boolean

Optional

If false (default) use full length of guides. If true restrict resulting surface by the first and last profile. Meaningful only for non-periodic surface loft.

  • trimProfiles
boolean

Optional

If false (default) use full length of profiles. If true restrict resulting surface by the first and last guide or connection. Meaningful only for surface loft with open profiles.

  • derivativeInfo
array

Optional

An array of maps that contain shape constraints at start and end profiles. Each map entry is required to have a profileIndex that refers to the affected profile. Optional fields include a vector to match surface tangent to, a magnitude, and booleans for matching tangents or curvature derived from faces adjacent to affected profile.

EXAMPLE

[ { "profileIndex" : 0, "vector" : vector(1, 0, 0), "magnitude" : 2., "tangentToPlane" : true}, { "profileIndex" : 1, "matchCurvature" : true, "adjacentFaces" : qFaces } ] The first map would constrain the resulting loft at the start profile to be tangent to plane with normal vector(1,0,0) and magnitude 2. The second map constrains the loft at the end profile to match the curvature of faces defined by the query qFaces.
  • showIsocurves
boolean

Optional

Show graphical representation of a subset of isoparameteric curves on each face of the created loft. Default false.

  • curveCount
number

Optional

When showIsocurves is true, the number of curves to draw in each direction of each face's grid. Default 10.

  • loftTopology
LoftTopology

Optional

Specifies topology of lofted body. Default is MINIMAL.

opMateConnector (context is Context, id is Id, definition is map)

Creates a mate connector, which represents a coordinate system in the context. Currently it is a special type of point body.

ParameterTypeAdditional Info
definition map
  • coordSystem
CoordSystem

The mate connector coordinate system.

  • owner
Query

The owner body of the mate connector: when the owner is brought into an assembly, owned mate connectors will be brought in and move rigidly with it. If the query resolves to multiple bodies, the first is taken as the owner.

opMergeContexts (context is Context, id is Id, definition is map) returns array

Bring all of the information from contextFrom into context. This is used, for example, for the Derived feature.

ParameterTypeAdditional Info
context Context

The target context.

definition map
  • contextFrom
Context

The source context. It is rendered unusable by this operation.

EXAMPLE

MyPartStudio::build()
  • trackThroughMerge
array

Optional

Array of queries to map evaluation result in contextFrom to context post-merge

Return typeDescription
array

Returns array of the same size as trackThroughMerge with evaluation results for each query(array of arrays of transient queries).

opModifyFillet (context is Context, id is Id, definition is map)

This is a direct editing operation that modifies or deletes fillets.

ParameterTypeAdditional Info
definition map
  • faces
Query

The fillets to modify.

  • modifyFilletType
ModifyFilletType

Whether to change the fillet radii or remove them altogether.

  • radius
ValueWithUnits

Required if modifyFilletType is CHANGE_RADIUS.

The new radius.

  • reFillet
boolean

Required if modifyFilletType is CHANGE_RADIUS.

true to reapply adjacent fillets. Default is false.

opMoveFace (context is Context, id is Id, definition is map)

This is a direct editing operation that applies a transform to one or more faces.

ParameterTypeAdditional Info
definition map
  • moveFaces
Query

The faces to transform.

  • transform
Transform

The transform to apply to the face.

EXAMPLE

transform(vector(0, 0, 1) * inch) will translate the face 1 inch along the world's z-axis.
  • reFillet
boolean

Optional

true to attempt to defillet moveFaces prior to the move and reapply the fillet after. Default is false.

  • mergeFaces
boolean

Optional

true to remove redundant edges from moveFaces. Default is true.

opOffsetFace (context is Context, id is Id, definition is map)

This is a direct editing operation that offsets one or more faces.

ParameterTypeAdditional Info
definition map
  • moveFaces
Query

The faces to offset.

  • offsetDistance
ValueWithUnits

The positive or negative distance by which to offset.

EXAMPLE

0.1 * inch will offset the face 0.1 inches, normal to the face.
  • reFillet
boolean

Optional

true to attempt to defillet moveFaces prior to the offset and reapply the fillet after. Default is false.

  • mergeFaces
boolean

Optional

true to remove redundant edges from moveFaces. Default is true.

opPattern (context is Context, id is Id, definition is map)

Patterns input faces and/or bodies by applying transforms to them. The original faces and bodies are preserved.

ParameterTypeAdditional Info
definition map
  • entities
Query

Bodies and faces to pattern.

  • transforms
array

An array of Transforms to apply to entities. The transforms do not have to be rigid.

  • instanceNames
array

An array of distinct non-empty strings the same size as transforms to identify the patterned entities. Similar to an Id, an instance names may consist only of letters, numbers, and any of +, -, /, _.

  • copyPropertiesAndAttributes
boolean

Optional

If true (default), copies properties and attributes to patterned entities.

opPlane (context is Context, id is Id, definition is map)

Creates a construction plane.

ParameterTypeAdditional Info
definition map
  • plane
Plane

The plane to create.

EXAMPLE

plane(vector(0, 0, 6) * inch, vector(0, 0, 1))
  • width
ValueWithUnits

Optional

The side length of the construction plane, as it is initially displayed.

  • height
ValueWithUnits

Optional

The side length of the construction plane, as it is initially displayed.

  • defaultType
DefaultPlaneType

Optional

For Onshape internal use.

opPolyline (context is Context, id is Id, definition is map)

Creates a polyline passing through an array of 3D points.

ParameterTypeAdditional Info
definition map
  • points
array

An array of Vectors with length units corresponding the points of the polyline. If the firstpoint is the same as the last point, the polyline is closed.

EXAMPLE

[
    vector( 1,  1,  1) * inch,
    vector(-1,  1, -1) * inch,
    vector( 1, -1, -1) * inch,
    vector(-1, -1,  1) * inch,
    vector( 1,  1,  1) * inch
]
  • bendRadii
array

Optional

An array of ValueWithUnits, corresponding to the bend radii at each point. The value at index i corresponds to the bend at the point at index i + 1 in points. A value of 0 * meter means no bend at the corresponding point. Its size should be size(points) - 2 for an open polyline, size(points) - 1 for a closed one.

opDropCurve (context is Context, id is Id, definition is map)

Projects curves on a face.

ParameterTypeAdditional Info
definition map
  • tools
Query

The edges to project.

  • targets
Query

The faces/bodies the edges are to be projected onto.

  • projectionType
ProjectionType

Projection method.

  • direction
Vector

Optional

The direction in which to project the curve. Required if projectionType is ProjectionType.DIRECTION.

opIntersectFaces (context is Context, id is Id, definition is map)

Intersect two faces, creating curves appropriately.

ParameterTypeAdditional Info
definition map
  • tools
Query

First array of faces to intersect.

  • targets
Query

Second array of faces to intersect.

opSphere (context is Context, id is Id, definition is map)

Creates a sphere.

ParameterTypeAdditional Info
definition map
  • radius
ValueWithUnits

The radius of the sphere.

EXAMPLE

1 * inch
  • center
Vector

The location of the center of the sphere.

EXAMPLE

vector(1, 1, 1) * inch

opSplineThroughEdges (context is Context, id is Id, definition is map)

Creates a 3D spline curve representing a sequence of edges. The edges must form a tangent-continuous chain.

ParameterTypeAdditional Info
definition map
  • edges
Query

Edges to approximate.

opSplitEdges (context is Context, id is Id, definition is map)

Splits an array of edges with an entity or at specified parameters.

ParameterTypeAdditional Info
definition map
  • edges
Query

Edges to split.

  • parameters
array

An array of array of parameters. Each edge gets split at the parameter values at the matching index in this array.

  • splittingSurface
Query

A sheet body, a construction plane or a face to cut with. Can be either a Query or a Plane. Either splittingSurface or parameters must be specified but not both.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter returned for edges measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-calculate parameterization. Default is true.

opPoint (context is Context, id is Id, definition is map)

Creates a construction point (a BodyType.POINT with one vertex).

ParameterTypeAdditional Info
definition map
  • point
Vector

The location of the point.

EXAMPLE

vector(0, 0, 1) * inch
  • origin
boolean

Optional

For Onshape internal use.

opReplaceFace (context is Context, id is Id, definition is map)

This is a direct editing operation that replaces the geometry one or more faces with that of another face, possibly with an offset.

ParameterTypeAdditional Info
definition map
  • replaceFaces
Query

The faces whose geometry to replace.

  • templateFace
Query

The face whose geometry to use as the replacement.

  • offset
ValueWithUnits

Optional

The positive or negative distance by which to offset the resulting face.

  • oppositeSense
boolean

Optional

If true, flip the surface normal of the resulting face, which may be necessary to match the surface normals of surrounding faces. Default is false.

opRevolve (context is Context, id is Id, definition is map)

Revolves edges and faces about an axis to produce sheet and solid bodies. The edges and faces may abut, but not strictly intersect the axis.

ParameterTypeAdditional Info
definition map
  • entities
Query

The edges and faces to revolve.

  • axis
Line

The axis around which to revolve.

EXAMPLE

line(vector(0, 0, 0) * inch, vector(0, 0, 1))
  • angleForward
ValueWithUnits

The angle where the revolve ends relative to entities. Normalized to the range \[0, 2 PI).

EXAMPLE

30 * degree
  • angleBack
ValueWithUnits

Optional

The angle where the revolve starts relative to entities. Normalized to the range \[0, 2 PI). If angleForward == angleBack, the revolve is a full (360-degree) revolve. Defaults to 0.

opRuledSurface (context is Context, id is Id, definition is map)

Creates a ruled surface along a set of paths. Direction of ruled surface is specified with either ruledDirection or angleFromFaces.

ParameterTypeAdditional Info
definition map
  • path
Query

The edges that form the paths for the ruled surface.

  • cornerType
RuledSurfaceCornerType

Optional

How corners in the ruled surface are handled. Default is RuledSurfaceCornerType.SPUN.

  • useCubicInterpolation
boolean

Optional

Ruled surface will use a cubic interpolation if true. Otherwise, a linear interpolation will be used. Default is true.

  • width
ValueWithUnits

The width of the ruled surface.

  • ruledSurfaceType
RuledSurfaceType

Specifies how the ruled surface is constructed.

  • ruledDirection
Vector

Required if ruledSurfaceType is ALIGNED_WITH_VECTOR

Ruled surface will be aligned with this vector.

  • angle
ValueWithUnits

The angle at which the ruled surface meets reference faces or ruledDirection. Default is 0.

  • referenceFaces
Query

Required if ruledSurfaceType is ANGLE_FROM_FACE

A set of faces from which to measure angleFromFaces.

  • vertexOverrides
map
    • vertex
Query

A vertex on the path where the override is applied.

    • ruledDirection
Vector

If specified, override will specify local direction of ruled surface along this vector.

    • width
ValueWithUnits

Required if ruledDirection != undefined or angleFromFaces != undefined

Width of ruled surface at this override.

    • angleFromFaces
ValueWithUnits

If specified, override will specify direction as an angle to reference faces. This is only applicable if angleFromFaces is also specified at the top level.

    • upToEntity
Query

If specified, override will specify that ruled surface touches upToEntity at override.

opShell (context is Context, id is Id, definition is map)

Create a shell of a solid body with uniform thickness. The bodies that are passed in are hollowed, omitting the walls on the face entities passed in.

ParameterTypeAdditional Info
definition map
  • entities
Query

The faces to shell and solid bodies to hollow.

  • thickness
ValueWithUnits

The distance by which to shell. Positive means shell outward, and negative means shell inward.

opSplitPart (context is Context, id is Id, definition is map)

Split solid, sheet, and wire bodies with the given sheet body.

ParameterTypeAdditional Info
definition map
  • targets
Query

The solid, sheet, and wire bodies to split.

  • tool

A sheet body, a construction plane or a face to cut with. Can be either a Query or a Plane. If a planar face is passed in, the split will extend the plane infinitely unless useTrimmed is true.

  • keepTools
boolean

Optional

If false, the tool is deleted. Default is false.

  • keepType
SplitOperationKeepType

Optional

Controls which pieces to keep. Default is KEEP_ALL.

  • useTrimmed
boolean

Optional

If true, the trimmed face boundaries are used as the tool, rather than the underlying surface. Default is false.

opSplitFace (context is Context, id is Id, definition is map)

Split faces with the given edges or faces.

ParameterTypeAdditional Info
definition map
  • faceTargets
Query

The faces to split.

  • edgeTools
Query

Optional

The edges to cut with.

  • projectionType
ProjectionType

Optional

Edge projection method. Default is ProjectionType.NORMAL_TO_TARGET

  • direction
Vector

Required if edgeTools are present and projectionType is ProjectionType.DIRECTION.

The projection direction.

  • faceTools
Query

Optional

The faces to cut with.

  • bodyTools
Query

Optional

The sheet or wire bodies to cut with.

  • keepToolSurfaces
boolean

Optional

If true, the bodyTools do not get consumed by the operation. Default is true.

  • planeTools
Query

Optional

These planar faces are treated as infinite, rather than bounded to the face extents.

  • extendToCompletion
boolean

Optional

if true, imprinted edges are extended to complete split of faces. Default is false.

  • mutualImprint
boolean

Optional

if true and only bodyTools are supplied target faces are used to split faces of bodyTools. Default is false.

SplitByIsoclineResult type

Map containing the results of splitting faces by their isoclines. Some faces may have been split, others may have been left intact.

ValueTypeDescription
SplitByIsoclineResult map
  • steepFaces
array

An array of steep faces.

  • nonSteepFaces
array

An array of non-steep faces.

  • boundaryEdges
array

An array of edges at the transition from non-steep faces to steep faces.

opSplitByIsocline (context is Context, id is Id, definition is map)

Split the given faces by isocline edges. Each isocline follows a path along a face with a constant angle in the (-90, 90) degree range (e.g., lines of latitude on a sphere). This angle is the face tangent plane's angle with respect to the direction with its sign determined by the dot product of direction and the face normal, and is analogous to the angle used in draft analysis. Depending on the face geometry, there may be zero, one, or multiple isoclines on each face. The isocline edges are created as new edges which split the provided faces. The resulting faces are either steep (i.e., the angle is less than the input angle) or non-steep. To instead leave the original faces intact, you can first extract the faces with opExtractSurface(), and create isoclines on the resulting surfaces. The isocline edges can be queried for with qCreatedBy. The split orientation is consistent such that the non-steep faces are always in "front" of the split, and can be reliably queried for with qSplitBy:

EXAMPLE

const isoclineEdges = qCreatedBy(id + "splitByIsocline1", EntityType.EDGE);
const steepFaces = qSplitBy(id + "splitByIsocline1", EntityType.FACE, true);
const nonSteepFaces = qSplitBy(id + "splitByIsocline1", EntityType.FACE, false);

Note that qSplitBy will return only those faces that were split, while the returned SplitByIsoclineResult will include the intact faces as well.

ParameterTypeAdditional Info
definition map
  • faces
Query

The faces on which to imprint isoclines.

  • direction
Vector

A reference direction.

  • angle
ValueWithUnits

The isocline angle with respect to the direction in the (-90, 90) degree range.

SplitBySelfShadowResult type

Map containing the results of splitting bodies by their shadow curves. Some faces may have been split, others may have been left intact.

ValueTypeDescription
SplitBySelfShadowResult map
  • visibleFaces
array

An array of visible faces.

  • invisibleFaces
array

An array of invisible faces.

opSplitBySelfShadow (context is Context, id is Id, definition is map)

Splits the faces of the given bodies into visible and invisible regions with respect to the given viewDirection, creating shadow curves as necessary. A shadow curve represents the transition of one face from visible to invisible. Depending on the geometry, there may be zero, one, or more shadow curves per face. The shadow curve edges are created as new edges which split the faces of the provided bodies. Each of the resulting faces is wholly visible or wholly invisible. Edge-on faces are considered invisible. The shadow curve edges can be queried for with qCreatedBy. The split orientation is consistent such that the visible faces are always in "front" of the split, and can be reliably queried for with qSplitBy:

EXAMPLE

const shadowEdges = qCreatedBy(id + "splitBySelfShadow1", EntityType.EDGE);
const invisibleFaces = qSplitBy(id + "splitBySelfShadow1", EntityType.FACE, true);
const visibleFaces = qSplitBy(id + "splitBySelfShadow1", EntityType.FACE, false);

Note that qSplitBy will return only those faces that were split, while the returned SplitBySelfShadowResult will include the intact faces as well.

ParameterTypeAdditional Info
definition map
  • bodies
Query

The bodies which cast shadows and on which to imprint shadow curves.

  • viewDirection
Vector

The viewing direction.

opSweep (context is Context, id is Id, definition is map)

Sweep the given edges and faces along a path resulting in solid and/or sheet bodies.

ParameterTypeAdditional Info
definition map
  • profiles
Query

Edges and faces to sweep.

  • path
Query

Edges that comprise the path along which to sweep. The edges can be in any order but must form a connected path.

  • keepProfileOrientation
boolean

Optional

If true, the profile maintains its original orientation as it is swept. If false (default), the profile rotates to remain normal to the path.

  • lockFaces
Query

Optional

Keep profile aligned to the normals of these faces.

  • lockDirection
Query

Optional

Keep profile perpendicular to this direction.

  • profileControl
ProfileControlMode

Optional

Default is NONE

EXAMPLE

ProfileControlMode.KEEP_ORIENTATION the profile maintains its original orientation as it is swept.

EXAMPLE

ProfileControlMode.LOCK_DIRECTION the profile is perpendicular to given direction.

EXAMPLE

ProfileControlMode.LOCK_FACES the profile is aligned to the normals of given faces.

opThicken (context is Context, id is Id, definition is map)

Thicken sheet bodies and faces into solid bodies.

ParameterTypeAdditional Info
definition map
  • entities
Query

The sheet bodies and faces to thicken.

  • thickness1
ValueWithUnits

The distance by which to thicken in the direction along the normal.

  • thickness2
ValueWithUnits

The distance by which to thicken in the opposite direction.

  • keepTools
boolean

Optional

Default is true. If false the operation will attempt to delete the entities. The operation will not delete sheet bodies unless the sheet body or all faces of the sheet body are selected. The operation will not delete sketches or solid bodies.

opTransform (context is Context, id is Id, definition is map)

Applies a given transform to one or more bodies. To make transformed copies of bodies, use opPattern.

ParameterTypeAdditional Info
definition map
  • bodies
Query

The bodies to transform.

  • transform
Transform

The transform to apply.

EXAMPLE

transform(vector(0, 0, 1) * inch) will translate the body 1 inch along the world's z-axis.

EXAMPLE

rotationAround(myLine, 30 * degree) will rotate around a Line object.

EXAMPLE

scaleUniformly(factor) will scale uniformly about the origin.

EXAMPLE

scaleUniformly(factor, point) will scale uniformly about a given point.

EXAMPLE

toWorld(cSys) will (somewhat counterintuitively) perform a transform such that geometry on the world's origin and axes will move to the cSys origin and axes.

EXAMPLE

fromWorld(cSys) will (somewhat counterintuitively) perform a transform such that geometry on the cSys origin and axes will move to the world origin and axes.

EXAMPLE

transform2 * transform1 will perform transform1, followed by transform2.

opWrap (context is Context, id is Id, definition is map)

Wraps or unwraps faces from one surface onto another. The location and orientation of the wrapped faces on the destination surface are controlled by the anchorPoint and anchorDirection of the source and destination WrapSurfaces. The entities of the operation are not affected, the result of this operation is a new set of surface bodies or imprinted edges representing the wrapped or unwrapped faces. Faces that are topologically connected will remain topologically connected in the result body for WrapType.SIMPLE and WrapType.TRIM. This operation currently supports wrapping from a plane onto a cylinder, and unwrapping from a cylinder onto a plane.

(Formerly opRoll)

ParameterTypeAdditional Info
definition map
  • wrapType
WrapType

The type of wrap to execute.

EXAMPLE

WrapType.SIMPLE wraps entities around the infinite definition of destination.
  • entities
Query

Faces to wrap from source to destination.

  • source
WrapSurface

The surface to wrap from. All entities must lie on this surface.

  • destination
WrapSurface

The surface to wrap onto. Must be defined using the face field for WrapType.TRIM or WrapType.IMPRINT.

  • orientWithDestination
boolean

Optional

If true (default), the normals of the resulting surface will point in the same direction as the destination. If false, the normals of the resulting surface will point in the opposite direction. For the purpose of this parameter, the normals of a WrapSurface defined by an infinite Cylinder are always pointing outwards.

primitives

cube (context is Context, id is Id, definition is map)

Create a cube of a specified size, with one corner on the origin.

ParameterTypeAdditional Info
definition map
  • sideLength
ValueWithUnits

EXAMPLE

1 * inch

sphere (context is Context, id is Id, definition is map)

Feature creating a sphere. Internally, calls opSphere.

ParameterTypeAdditional Info
definition map
  • center
Query

A vertex query marking the sphere's center.

  • radius
ValueWithUnits

EXAMPLE

1 * inch

fCuboid (context is Context, id is Id, definition is map)

Create a simple rectangular prism between two specified corners.

ParameterTypeAdditional Info
definition map
  • corner1
Vector

EXAMPLE

vector(0, 0, 0) * inch
  • corner2
Vector

EXAMPLE

vector(1, 1, 1) * inch

fCylinder (context is Context, id is Id, definition is map)

Create a simple cylindrical solid between two points, with a specified radius.

ParameterTypeAdditional Info
definition map
  • topCenter
Vector

A 3D length vector in world space.

EXAMPLE

vector(0, 0, 0) * inch
  • bottomCenter
Vector

A 3D length vector in world space.

EXAMPLE

vector(1, 1, 1) * inch
  • radius
ValueWithUnits

EXAMPLE

1 * inch

fCone (context is Context, id is Id, definition is map)

Create a solid cone, possibly truncated.

ParameterTypeAdditional Info
definition map
  • topCenter
Vector

EXAMPLE

vector(1, 1, 1) * inch
  • bottomCenter
Vector

EXAMPLE

vector(0, 0, 0) * inch
  • topRadius
ValueWithUnits

The radius at the top center.

EXAMPLE

1 * inch
  • bottomRadius
ValueWithUnits

The radius at the bottom center.

EXAMPLE

0 * inch produces a standard, non-truncated cone.

fEllipsoid (context is Context, id is Id, definition is map)

Create an ellipsoid (that is, a sphere scaled independently along the three major axes).

ParameterTypeAdditional Info
definition map
  • center
Vector

EXAMPLE

vector(0, 0, 0) * inch
  • radius
Vector

The three radii, as measured along the x, y, and z axes.

EXAMPLE

vector(0.5 * inch, 1 * inch, 2 * inch)

sketch

Functions used to create sketches, and add entities to sketches.

A sketch used in FeatureScript generally has the following form:

var sketch1 = newSketch(context, id + "sketch1", {
        "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});
skRectangle(sketch1, "rectangle1", {
        "firstCorner" : vector(0, 0),
        "secondCorner" : vector(1, 1)
});
skSolve(sketch1);
extrude(context, id + "extrude1", {
        "entities" : qSketchRegion(id + "sketch1"),
        "endBound" : BoundingType.BLIND,
        "depth" : 0.5 * inch
});

A Sketch object should always be created first, with either newSketch or newSketchOnPlane.

Next, any number of sketch entities may be added to the sketch using the functions in this module. The inputs to sketch functions usually involve 2D Vectors, which are positions relative to the sketch plane's origin and x-axis. To create such a point based on a projected 3D point in world space, use worldToPlane(Plane, Vector).

When building sketches in FeatureScript, constraints may be added, but are almost always unnecessary, since you already have the ability to place the entities precisely where you intend them to be.

Finally, the sketch is solved and added to the context by calling skSolve. As a result of skSolve, all edges of the sketch will become WIRE bodies in the context. Any regions enclosed in the sketch will become SURFACE bodies in the context. Any vertices which are not edge endpoints (such as points created by skPoint or the center point of skCircle) will become POINT bodies in the context. These newly created bodies can be queried for and used in all subsequent operations and features.

Sketch type

A Sketch object represents a Onshape sketch, to which sketch entities can be added.

Sketches can be created by calls to newSketch or newSketchOnPlane.

canBeSketch (value) predicate

Typecheck for builtin Sketch

isIdForSketch (context is Context, id is Id)

Check whether an Id represents a Sketch operation.

newSketch (context is Context, id is Id, value is map) returns Sketch

Create a new sketch on an existing planar entity. The sketch coordinate system follows the canonical plane orientation and the sketch origin is the projection of the world origin onto the plane.

To make a sketch in the coordinate system of an arbitrary Plane, use newSketchOnPlane.

ParameterTypeAdditional Info
value map
  • sketchPlane
Query

A Query for a single, planar entity.

EXAMPLE

qCreatedBy(makeId("Top"), EntityType.FACE) to sketch on default "Top" plane.
  • disableImprinting
boolean

Optional

Prevents sketchPlane from imprinting on the sketch. Default is false.

newSketchOnPlane (context is Context, id is Id, value is map) returns Sketch

Create a new sketch on a custom plane, specified by a Plane object. The sketch coordinate system will match the coordinate system of the plane.

ParameterTypeAdditional Info
value map
  • sketchPlane
Plane

EXAMPLE

plane(vector(0, 0, 0) * inch, vector(0, 0, 1)) to sketch on the world XY plane.

skSolve (sketch is Sketch)

Solve any constraints in the sketch and add all sketch entities form the sketch to its context.

Even if there are no constraints, a sketch must be solved before its entities are created.

skPoint (sketch is Sketch, pointId is string, value is map) returns map

Add a point to a sketch.

ParameterTypeAdditional Info
value map
  • position
Vector

EXAMPLE

vector(0, 1) * inch
ReturnTypeDescription
map
  • pointId

skLineSegment (sketch is Sketch, lineId is string, value is map) returns map

Add a line segment to a sketch.

ParameterTypeAdditional Info
value map
  • start
Vector

EXAMPLE

vector(0, 0) * inch
  • end
Vector

EXAMPLE

vector(1, 1) * inch
  • construction
boolean

Optional

true for a construction line

ReturnTypeDescription
map
  • startId
  • endId

skText (sketch is Sketch, textId is string, value is map) returns map

Add a text rectangle to a sketch.

ParameterTypeAdditional Info
value map
  • text
string

A string of text to write. May contain newlines (encoded as \n).

  • fontName
string

A font name, with extension ".ttf" or ".otf". To change font weight, replace "-Regular" with "-Bold", "-Italic", or "-BoldItalic".

Must be one of the following fonts:

EXAMPLE

"OpenSans-Regular.ttf" Sans-serif font. Default if no match is found.

EXAMPLE

"AllertaStencil-Regular.ttf" Stencil font. No bold/italic options.

EXAMPLE

"Arimo-Regular.ttf" Sans-serif font.

EXAMPLE

"DroidSansMono.ttf" Monospaced sans-serif font. No bold/italic options.

EXAMPLE

"NotoSans-Regular.ttf" Sans-serif font.

EXAMPLE

"NotoSansCJKjp-Regular.otf" Japanese font. No italic options.

EXAMPLE

"NotoSansCJKkr-Regular.otf" Korean font. No italic options.

EXAMPLE

"NotoSansCJKsc-Regular.otf" Chinese (simplified) font. No italic options.

EXAMPLE

"NotoSansCJKtc-Regular.otf" Chinese (traditional) font. No italic options.

EXAMPLE

"NotoSerif-Regular.ttf" Serif font.

EXAMPLE

"RobotoSlab-Regular.ttf" Sans-serif font. No italic options.

EXAMPLE

"Tinos-Regular.ttf" Serif font. Metrically compatible with Times New Roman.
  • construction
boolean

Optional

true for a construction line

  • firstCorner
Vector

Optional

One corner of the rectangle into which the text will be placed. Text will start at the left of the rectangle and extend to the right, overflowing the right if necessary. The first line of text will fill the height of the rectangle, with subsequent lines below the rectangle (or above if mirrored vertically).

EXAMPLE

vector(0, 0) * inch
  • secondCorner
Vector

Optional

The other corner of the rectangle into which the text will be placed. Text will start at the left of the rectangle and extend to the right, overflowing the right if necessary. The first line of text will fill the height of the rectangle, with subsequent lines below the rectangle (or above if mirrored vertically).

EXAMPLE

vector(1, 1) * inch
  • mirrorHorizontal
boolean

Optional

true for flipping text horizontally

  • mirrorVertical
boolean

Optional

true for flipping text vertically

ReturnTypeDescription
map
  • textId

skImage (sketch is Sketch, imageId is string, value is map) returns map

Add an image rectangle and return ids of corner points.

To use an image uploaded in your document, import the image (possibly into a namespace).

ParameterTypeAdditional Info
value map
  • blobInfo
map

EXAMPLE

BLOB_DATA will use the image from an image file imported into this Feature Studio.

EXAMPLE

MyImage::BLOB_DATA will use an image imported into the namespace MyImage (e.g. using MyImage::import(...))
  • firstCorner
Vector

One corner of the rectangle into which the image will be placed.

EXAMPLE

vector(0, 0) * inch
  • secondCorner
Vector

The other corner of the rectangle into which the image will be placed.

EXAMPLE

vector(1, 1) * inch
ReturnTypeDescription
map
  • imageId

skCircle (sketch is Sketch, circleId is string, value is map) returns map

Add a circle to a sketch.

ParameterTypeAdditional Info
value map
  • center
Vector

EXAMPLE

vector(0, 0) * inch
  • radius
ValueWithUnits

EXAMPLE

1 * inch
  • construction
boolean

Optional

true for a construction line

ReturnTypeDescription
map
  • centerId

skEllipse (sketch is Sketch, ellipseId is string, value is map) returns map

Add an ellipse to a sketch.

ParameterTypeAdditional Info
value map
  • center
Vector

EXAMPLE

vector(0, 0) * inch
  • majorRadius
ValueWithUnits

EXAMPLE

2 * inch
  • minorRadius
ValueWithUnits

EXAMPLE

1 * inch
  • majorAxis
Vector

Optional

A unitless 2D direction, specifying the orientation of the major axis

  • construction
boolean

Optional

true for a construction line

ReturnTypeDescription
map
  • centerId

skArc (sketch is Sketch, arcId is string, value is map) returns map

Add an arc through three points to a sketch.

ParameterTypeAdditional Info
value map
  • start
Vector

EXAMPLE

vector(1, 0) * inch
  • mid
Vector

EXAMPLE

vector(0, 1) * inch
  • end
Vector

EXAMPLE

vector(-1, 0) * inch
  • construction
boolean

Optional

true for a construction line

ReturnTypeDescription
map
  • startId
  • endId

skEllipticalArc (sketch is Sketch, arcId is string, value is map) returns map

Add an elliptical arc to a sketch. The ellipse has a period of 1, a parameter of 0 at the major axis and 0.25 at the minor axis. The arc is drawn counterclockwise from the start point to the end point.

ParameterTypeAdditional Info
value map
  • center
Vector

EXAMPLE

vector(0, 0) * inch
  • majorAxis
Vector

The direction, in sketch coordinates, in which the major axis of the ellipse lies.

EXAMPLE

normalize(vector(1, 1))
  • minorRadius
ValueWithUnits

A non-negative value with length units.

EXAMPLE

1 * inch
  • majorRadius
ValueWithUnits

A non-negative value with length units. Does not need to be greater than the minor radius.

EXAMPLE

2 * inch
  • startParameter
number

The parameter of the start point.

EXAMPLE

0
  • endParameter
number

The parameter of the end point.

EXAMPLE

0.25
  • construction
boolean

Optional

true for a construction line

ReturnTypeDescription
map
  • startId
  • endId

skFitSpline (sketch is Sketch, splineId is string, value is map)

Create an interpolated spline through the given points.

ParameterTypeAdditional Info
value map
  • points

An array of points. If the start and end points are the same, the spline is closed.

EXAMPLE

[
    vector( 0,  0) * inch,
    vector( 0, -1) * inch,
    vector( 1,  1) * inch,
    vector(-1,  0) * inch,
    vector( 0,  0) * inch
]
  • parameters

Optional

An array of doubles, parameters corresponding to the points.

  • construction
boolean

Optional

true for a construction line

  • startDerivative
Vector

Optional

A 2D Vector with length units that specifies the derivative at the start of the resulting spline. Ignored if spline is closed.

  • endDerivative
Vector

Optional

A 2D Vector with length units that specifies the derivative at the end of the resulting spline. Ignored if spline is closed.

skBezier (sketch is Sketch, bezierId is string, value is map)

Create a Bezier curve from the given control points.

ParameterTypeAdditional Info
value map
  • points

An array of points.

EXAMPLE

[
       vector( 0, 0) * inch,
       vector( 0, 1) * inch,
       vector( 1, 1) * inch,
       vector( 1, 0) * inch
]
  • construction
boolean

Optional

true for a construction line

skRectangle (sketch is Sketch, rectangleId is string, value is map)

Add a rectangle (four line segments, properly constrained) to a sketch.

ParameterTypeAdditional Info
value map
  • firstCorner
Vector

EXAMPLE

vector(0, 0) * inch
  • secondCorner
Vector

EXAMPLE

vector(1, 1) * inch
  • construction
boolean

Optional

true for a construction line

skRegularPolygon (sketch is Sketch, polygonId is string, value is map)

Add a regular polygon to the sketch. Unconstrained.

ParameterTypeAdditional Info
value map
  • center
Vector

EXAMPLE

vector(0, 0) * inch
  • firstVertex
Vector

Distance to the center determines the radius.

EXAMPLE

vector(0, 1) * inch
  • sides
number

Number of polygon sides. Must be an integer 3 or greater.

  • construction
boolean

Optional

true for a construction line

skPolyline (sketch is Sketch, polylineId is string, value is map)

Add a polyline (line segments, optionally with constrained endpoints) or a polygon to a sketch.

ParameterTypeAdditional Info
value map
  • points
array

An array of points, each a Vector of two lengths. If first and last point are the same, the polyline is closed.

EXAMPLE

[
    vector( 0,  0) * inch,
    vector( 0, -1) * inch,
    vector( 1,  1) * inch,
    vector(-1,  0) * inch,
    vector( 0,  0) * inch
]
  • construction
boolean

Optional

true for a construction line. Default false.

  • constrained
boolean

Optional

true if constraints should be created. Default false.

skConstraint (sketch is Sketch, constraintId is string, value is map)

Add a constraint.

ParameterTypeAdditional Info
value map
  • constraintType
ConstraintType
  • length
ValueWithUnits

Optional

For constraints that require a length. Must have length units.

  • angle
ValueWithUnits

Optional

For constraints that require a angle. Must have angle units.

query

Functions for constructing queries. Features that take queries as inputs should re-export this module.

Queries are used to refer to topological entities (vertices, edges, faces, and bodies) that FeatureScript operation and evaluation functions work on. A query is a map that contains instructions for how to find entities. For example, a query for all edges in a context looks like qEverything(EntityType.EDGE). Many queries can take subqueries as arguments, allowing for more complex nested queries.

Queries in general do not contain a list of entities in any form. Rather, they contain criteria that specify a subset of the topological entities in a context. To get an array of the entities (if any) which match a query in a context, use evaluateQuery. There is no need to evaluate a query before passing it into a function, including any of the Standard Library's operation and evaluation functions.

There are two general types of queries: state-based and historical. State-based queries select entities based on the model state, e.g. "All edges adjacent to a cylindrical face which touches this point." Historical queries select entities based on the model history, e.g. "the edge that was generated by feature extrude_1_id from sketch vertex vertex_id from sketch sketch_id." State-based queries cannot refer to entities that have been deleted. Most automatically-generated queries are historical, while queries more commonly used in manually written code are state-based.

Query type

A Query identifies a specific subset of a context's entities (points, lines, planes, and bodies).

The fields on a Query map depend on its QueryType, and may include one or more subqueries.

ValueTypeDescription
Query map
  • queryType
QueryType
  • entityType
EntityType

Optional

canBeQuery (value) predicate

Typecheck for Query

BodyType enum

Specifies the topological type of a body.

All bodies have EntityType.BODY, but will generally own many entities of other EntityTypes.

For example, the result of an extrude with NewBodyOperationType.NEW is a body. This body will have BodyType.SOLID for a solid extrude, and BodyType.SHEET for a surface extrude. This extrude operation will create many geometric entities in the context (faces, edges, or vertices), which are owned by the body, and have the BodyType of their owning body.

See also

qBodyType

ValueDescription
SOLID

A three-dimensional part (e.g. the result of a solid extrude)

SHEET

A two-dimensional sheet body (e.g. a sketch region, or the result of a surface extrude)

WIRE

A one-dimensional curve (e.g. a sketch line or curve, or the result of opHelix)

POINT

A zero-dimensional point (e.g. a sketch point, or the result of opPoint)

MATE_CONNECTOR

A part studio mate connector.

COMPOSITE

A composite part body, which can contain bodies of any other type

EntityType enum

Specifies the topological type of a given entity. Used in several queries as a filter, or on any query explicitly with qEntityFilter

Thus, one can obtain all the vertices in a part studio with qEverything(EntityType.VERTEX), and can obtain all the vertices attached to solid bodies with qBodyType(qEverything(EntityType.VERTEX), BodyType.SOLID)

A query for every part in a part studio is qBodyType(qEverything(EntityType.BODY), BodyType.SOLID)

ValueDescription
VERTEX

A zero-dimensional point or vertex

EDGE

A one-dimensional line, curve, or edge

FACE

A two-dimensional surface, planar face, or non-planar face

BODY

A solid, surface, wire, or point body

AdjacencyType enum

Specifies the adjacency type of queried entities.

See also

qAdjacent

ValueDescription
VERTEX

Entities share at least a vertex

EDGE

Entities share at least an edge

GeometryType enum

Specifies the geometric type of queried entities.

See also

qGeometry

ValueDescription
LINE

A straight line or edge

CIRCLE

A circle of constant radius

ARC

A segment of a circle

OTHER_CURVE

Any one-dimensional entity which is not described above (e.g. splines, ellipses, etc.)

PLANE

A construction plane or planar face

CYLINDER

A surface which forms the side of a right circular cylinder

CONE

A surface which forms the side of a right circular cone

SPHERE

A surface which forms the boundary of a sphere

TORUS

A surface which forms the boundary of a torus

REVOLVED

A surface constructed by revolving a curve around an axis (unless it is simplified to one of the types above)

EXTRUDED

A surface constructed by extruding or sweeping a curve along a line (unless it is simplified to one of the types above)

OTHER_SURFACE

Any two-dimensional entity which is not described above (e.g. the side of an arbitrary loft)

ALL_MESH

A surface or a body that is fully mesh or an edge between two mesh surfaces.

MIXED_MESH

A body that contains both mesh and non-mesh surfaces or an edge between a mesh and a non-mesh surfaces.

MESH

A surface that is mesh, a body that contains mesh surfaces or an edge bordering a mesh surface.

CapType enum

Specifies which cap queried entities should belong to.

See also

qCapEntity

ValueDescription
START

finds entities belonging to the start cap

END

finds entities belonging to the end cap

EITHER

finds entities belonging to either cap

ConstructionObject enum

Specifies whether the entity was created for construction (e.g. a construction line or construction plane).

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Edges to use", "Filter" : EntityType.EDGE && ConstructionObject.NO }
definition.edges is Query;

See also

qConstructionFilter

ValueDescription
YES

Matches only entities which are created for construction

NO

Matches only entities which are not created for construction

SMFlatType enum

Specifies whether an entity appears in the sheet metal flat view, or the main view.

See also

qSheetMetalFlatFilter

ValueDescription
YES

Matches entities which belong to a flattened sheet metal part.

NO

Matches entities which do not belong to a flattened sheet metal part.

AllowMeshGeometry enum

Specifies whether we allow meshes. Default is NO.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Bodies", "Filter" : EntityType.BODY && AllowMeshGeometry.YES }
definition.body is Query;
ValueDescription
YES

Allow meshes

NO

Disallow meshes

AllowFlattenedGeometry enum

Specifies whether we allow flat entities. Default is NO.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Bodies", "Filter" : EntityType.BODY && AllowFlattenedGeometry.YES }
definition.body is Query;
ValueDescription
YES

Allow flat entities

NO

Disallow flat entities

ActiveSheetMetal enum

Specifies whether the entities should belong to an active sheet metal model.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Sheet metal bodies", "Filter" : EntityType.BODY && ActiveSheetMetal.YES }
definition.body is Query;
ValueDescription
YES

matches only entities which belong to an active sheet metal model

NO

matches only entities which do not belong to an active sheet metal model

SheetMetalDefinitionEntityType enum

Specifies geometry corresponding to a certain type of topological entity in the sheet metal master body for active sheet metal models.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Sheet metal definition edges", "Filter" : SheetMetalDefinitionEntityType.EDGE }
definition.entities is Query;
ValueDescription
VERTEX

matches entities defined by a sheet metal master body vertex. This includes vertices, edges, and faces at the corners, bend ends, fillets, and chamfers of sheet metal models.

EDGE

matches entities defined by a sheet metal master body edge. This includes edges and faces along the sides of sheet metal walls.

FACE

matches entities defined by a sheet metal master body face. This includes faces of sheet metal walls.

ModifiableEntityOnly enum

Specifies whether we allow modifiable only entities. It is default to NO.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Bodies", "Filter" : EntityType.BODY && ModifiableEntityOnly.YES }
definition.body is Query;

See also

qModifiableEntityFilter

ValueDescription
YES

Only allow modifiable entities

NO

Allow both modifiable and unmodifiable entities

AllowEdgePoint enum

Specifies whether we allow edge points. Default is YES.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Corners", "Filter" : EntityType.VERTEX && AllowEdgePoint.NO }
definition.body is Query;
ValueDescription
YES

Allow edge points

NO

Disallow edge points

MeshGeometry enum

Specifies whether the entities are mesh geometries.

See also

qMeshGeometryFilter

ValueDescription
YES

Matches only entities (edges, faces, and bodies) which are meshes

NO

Matches only entities (edges, faces, and bodies) which are not meshes

SketchObject enum

Specifies whether the entity is a part of a sketch.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Sketch curves", "Filter" : EntityType.EDGE && SketchObject.YES }
definition.curves is Query;

See also

qSketchFilter

ValueDescription
YES

Matches only entities which are part of a sketch

NO

Matches only entities which are not part of a sketch

QueryFilterCompound enum

A set of convenience filters, which are expanded during precondition processing. Can be used as a filter on query parameters, just like their corresponding expansions:

annotation { "Name" : "Axis", "Filter" : QueryFilterCompound.ALLOWS_AXIS }
definition.axis is Query;
ValueDescription
ALLOWS_AXIS

Equivalent to GeometryType.LINE || GeometryType.CIRCLE || GeometryType.ARC || GeometryType.CYLINDER || BodyType.MATE_CONNECTOR and can be processed with evAxis

ALLOWS_DIRECTION

Equivalent to GeometryType.LINE || GeometryType.CIRCLE || GeometryType.ARC || GeometryType.CYLINDER || GeometryType.PLANE and can be processed with extractDirection

ALLOWS_PLANE

Equivalent to GeometryType.PLANE || BodyType.MATE_CONNECTOR and can be processed with evPlane

ALLOWS_VERTEX

Equivalent to EntityType.VERTEX || BodyType.MATE_CONNECTOR and can be processed with evVertexPoint

CompareType enum

Specifies a method of comparing two items.

See also

qFilletFaces

ValueDescription
EQUAL
LESS
LESS_EQUAL
GREATER
GREATER_EQUAL

Consumed enum

Specifies whether to filter or allow bodies (and their vertices, edges, and faces) consumed by closed composite parts.

See also

qConsumed

ValueDescription
YES

Matches only bodies that are consumed

NO

Matches only bodies that are not consumed

CompositePartType enum

Specifies whether to filter or allow closed or open composite parts.

See also

qCompositePartTypeFilter

ValueDescription
OPEN

Matches only open composite parts

CLOSED

Matches only closed composite parts

InContextObject enum

Specifies whether an entity is from an assembly context.

Can be used in a filter on a query parameter to only allow certain selections:

annotation { "Name" : "Edges to use", "Filter" : EntityType.EDGE && InContextObject.NO }
definition.edges is Query;
ValueDescription
YES

Matches only entities which are from an assembly context

NO

Matches only entities which are not from an assembly context

qNothing () returns Query

An empty query, which does not resolve to any entities.

qEverything (entityType is EntityType) returns Query

A query for all entities of a specified EntityType in the context.

See also

qAllModifiableSolidBodies

ParameterTypeAdditional Info
entityType EntityType

Optional

qEverything () returns Query

A query for all entities in the context.

qAllNonMeshSolidBodies () returns Query

A query for all solid bodies that do not have mesh geometry.

qAllSolidBodies () returns Query

A query for all solid bodies.

qAllModifiableSolidBodiesNoMesh () returns Query

A query for all solid bodies that do not have mesh geometry or in context geometry, i.e. every non-mesh-containing part displayed in the Part Studio's "Parts" list.

See also

qAllModifiableSolidBodies

qAllModifiableSolidBodies () returns Query

A query for all modifiable solid bodies, including mesh-containing bodies.

See also

qAllModifiableSolidBodiesNoMesh

qNthElement (queryToFilter is Query, n is number) returns Query

A query for one entity in queryToFilter at a specified index. The order of entities resolved by a query is deterministic but arbitrary.

ParameterTypeAdditional Info
queryToFilter Query

A query which resolves to at least n+1 entities

n number

Zero-based index of entity in queryToFilter.

EXAMPLE

0 indicates the first entity

EXAMPLE

-1 indicates the last entity

qEntityFilter (queryToFilter is Query, entityType is EntityType) returns Query

A query for entities in a queryToFilter which match a given EntityType.

qHasAttribute (name is string) returns Query

Query for all entities marked with an attribute with name name

See also

setAttribute

qHasAttribute (queryToFilter is Query, name is string) returns Query

Query for all entities in queryToFilter marked with an attribute with name name

See also

setAttribute

qHasAttributeWithValue (name is string, value) returns Query

Query for all entities marked with an attribute with name name and value exactly equal to value

See also

setAttribute

qHasAttributeWithValue (queryToFilter is Query, name is string, value) returns Query

Query for all entities in queryToFilter marked with an attribute with name name and value exactly equal to value

See also

setAttribute

qHasAttributeWithValueMatching (name is string, attributePattern is map) returns Query

Query for all entities marked with an attribute with name name and a map value matching every key-value pair in the provided attributePattern map.

See also

setAttribute

ParameterTypeAdditional Info
attributePattern map

EXAMPLE

{
    "key1" : valueToMatch,
}

qHasAttributeWithValueMatching (queryToFilter is Query, name is string, attributePattern is map) returns Query

Query for all entities in queryToFilter marked with an attribute with name name and a map value matching every key-value pair in the provided attributePattern map.

See also

setAttribute

ParameterTypeAdditional Info
attributePattern map

EXAMPLE

{
    "key1" : valueToMatch,
}

qAttributeFilter (queryToFilter is Query, attributePattern) returns Query

Note: This query is used only for legacy unnamed attributes, which are still supported but no longer reccommended. See the Attributes module for details.

A query for entities in a queryToFilter which have been assigned a legacy unnamed attribute matching a given attributePattern.

ParameterTypeAdditional Info
attributePattern

Will only resolve to queries whose legacy unnamed attributes match the type (and possibly the values) of this pattern.

If attributePattern has a type tag, will only match attributes with that same type tag.

EXAMPLE

{} as MyCustomType will match all attributes with type tag MyCustomType

If the attribute has no type tag (i.e. it is a standard type like string or map), will match all attributes with that same standard type.

EXAMPLE

"asdf" will match all string attributes.

EXAMPLE

{} will match all map attributes.

If the attribute is a map, will only match maps which have identical values for every key-value pair in the pattern

EXAMPLE

{ "odd" : true } matches all unnamed map attributes that have a field "odd" whose value is true.

EXAMPLE

{ "odd" : true } as MyCustomType matches all unnamed map attributes with the that have a field "odd" whose value is true.

qAttributeQuery (attributePattern) returns Query

Note: This query is used only for legacy unnamed attributes, which are still supported but no longer reccommended. See the Attributes module for details.

A query for all entities which have been assigned a legacy unnamed attribute matching a given attributePattern. Equivalent to qAttributeFilter(qEverything(), attributePattern)

qCreatedBy (featureId is Id, entityType is EntityType) returns Query

A query for all the entities created by a feature or operation. The feature is given by its feature id, which was passed into the the operation function in order to create the feature.

An entity is "created by" an operation if the entity was added to the context as part of that operation. Entities modified, but not created, by an operation are not returned by this query.

If an entity is split (as in a split part operation), the resulting entities are "created by" both the original entity's creator and the split part operation.

If two entities are merged (as in a union of coincident faces), that entity is "created by" the creators of each merged entity, as well as the merging operation itself.

If a sketch's feature id is specified, returns a query for all sketch regions, points, and wire bodies created by the specified sketch.

ParameterTypeAdditional Info
featureId Id

The Id of the specified feature.

EXAMPLE

id + "extrude1"
entityType EntityType

Optional

qCreatedBy (featureId is Id) returns Query

qCreatedBy (features is FeatureList) returns Query

qCreatedBy (features is FeatureList, entityType is EntityType) returns Query

qCapEntity (featureId is Id, capType is CapType, entityType is EntityType) returns Query

A query for start/end cap vertex, edge, and face entities created by featureId. Cap entities are produced by extrude, revolve, sweep, loft and thicken features

ParameterTypeAdditional Info
entityType EntityType

Optional

qCapEntity (featureId is Id, capType is CapType) returns Query

qNonCapEntity (featureId is Id, entityType is EntityType) returns Query

A query for vertex, edge, and face entities created by featureId that are not cap entities. Cap entities are produced by extrude, revolve, sweep, loft and thicken features

ParameterTypeAdditional Info
entityType EntityType

Optional

qNonCapEntity (featureId is Id) returns Query

qOpHoleProfile (featureId is Id, filters is map) returns Query

A query for the profile edges or vertices created by an opHole operation.

ParameterTypeAdditional Info
featureId Id

The Id of the specified operation.

EXAMPLE

id + "hole1"
filters map
  • name
string

Optional

Filter the query for profiles with a given name. See name field of HoleProfile.

  • identity
Query

Optional

Filter the query for the hole associated with the given identity entity. See identities parameter of opHole.

qOpHoleProfile (featureId is Id) returns Query

qOpHoleFace (featureId is Id, filters is map) returns Query

A query for the hole faces created by an opHole operation.

ParameterTypeAdditional Info
featureId Id

The Id of the specified operation.

EXAMPLE

id + "hole1"
filters map
  • name
string

Optional

Filter the query for faces with a given name. See faceNames field of HoleDefinition.

  • identity
Query

Optional

Filter the query for the hole associated with the given identity entity. See identities parameter of opHole.

qOpHoleFace (featureId is Id) returns Query

qToleranceFilter (queryToFilter is Query) returns Query

qUnion (subqueries is array) returns Query

A query for entities which match any of a list of queries.

qUnion is guaranteed to preserve order. That is, entities which match queries earlier in the subqueries input list will also be listed earlier in the output of evaluateQuery.

qUnion (query1 is Query, query2 is Query) returns Query

qUnion (query1 is Query, query2 is Query, query3 is Query) returns Query

qUnion (query1 is Query, query2 is Query, query3 is Query, query4 is Query) returns Query

qIntersection (subqueries is array) returns Query

A query for entities which match all of a list of queries. qIntersection preserves the order of the first subquery.

qIntersection (query1 is Query, query2 is Query) returns Query

qSubtraction (query1 is Query, query2 is Query) returns Query

A query for entities which match query1, but do not match query2. qSubtraction preserves the order of query1.

qSymmetricDifference (query1 is Query, query2 is Query) returns Query

A query for entities which match either query1 or query2, but not both.

qOwnedByBody (body is Query, entityType is EntityType) returns Query

A query for all of the entities (faces, vertices, edges, and bodies) in a context which belong to a specified body or bodies.

ParameterTypeAdditional Info
entityType EntityType

Optional

qOwnedByBody (body is Query) returns Query

qOwnedByBody (queryToFilter is Query, body is Query) returns Query

A query for all of the entities which match a queryToFilter, and belong to the specified body or bodies.

qOwnerBody (entities is Query) returns Query

A query for each body that any of the given entities belong to.

If a body is passed in, the result will include that body itself.

qContainedInCompositeParts (compositeParts is Query) returns Query

A query for each part contained in compositeParts.

qCompositePartsContaining (bodies is Query) returns Query

A query for each composite part containing bodies.

qCompositePartsContaining (bodies is Query, compositePartType is CompositePartType) returns Query

A query for each composite part of the given type containing bodies.

qFlattenedCompositeParts (entities is Query) returns Query

A query for non-composite entities in entities and constituents of composite parts in entities.

qConsumed (queryToFilter is Query, consumed is Consumed) returns Query

A query for all entities in queryToFilter which are consumed by any closed composite part, or all entities of queryToFilter which are not consumed by any closed composite part.

qCompositePartTypeFilter (queryToFilter is Query, compositePartType is CompositePartType) returns Query

A query for all bodies in queryToFilter which are either open or closed composite parts, depending on the second parameter.

qSourceMesh (selectedMeshVertices is Query, entityType is EntityType) returns Query

A query for each mesh element that any selectedMeshVertices belong to. selectedMeshVertices should be the point bodies created when a user selects a mesh vertex. Mesh vertices which have not been selected cannot be queried in FeatureScript

ParameterTypeAdditional Info
selectedMeshVertices Query

One or more mesh vertices whose owning elements are queried.

entityType EntityType

The type of resulting entities. Can be EntityType.BODY, EntityType.FACE or EntityType.EDGE.

qSourceMesh (selectedMeshVertices is Query) returns Query

Deprecated: Use qSourceMesh with EntityType.BODY

qAdjacent (seed is Query, adjacencyType is AdjacencyType, entityType is EntityType) returns Query

A query for entities that are adjacent to the given seed entities.

ParameterTypeAdditional Info
seed Query

One or more entities whose adjacent neighbors are queried. The result does not include the original seed entities (unless they are adjacent to other seed entities)

adjacencyType AdjacencyType

EXAMPLE

AdjacencyType.VERTEX will return entities that share at least a vertex with the seed entities.

EXAMPLE

AdjacencyType.EDGE will return entities that share at least an edge with the seed entities. For example, qAdjacent(whiteSquareOnChessBoard, AdjacencyType.EDGE) would return all four surrounding black squares, but not the four diagonal white squares.
entityType EntityType

Optional

The type of resulting entities

qAdjacent (seed is Query, adjacencyType is AdjacencyType) returns Query

qVertexAdjacent (query is Query, entityType is EntityType) returns Query

Deprecated: Use qAdjacent with AdjacencyType.VERTEX

qEdgeAdjacent (query is Query, entityType is EntityType) returns Query

Deprecated: Use qAdjacent with AdjacencyType.EDGE

qEdgeTopologyFilter (queryToFilter is Query, edgeTopologyType is EdgeTopology) returns Query

A query for edges in a queryToFilter which match a given EdgeTopology.

qEdgeVertex (edgeQuery is Query, atStart is boolean)

A query for the start or end vertices of edges.

qGeometry (queryToFilter is Query, geometryType is GeometryType) returns Query

A query for all entities in queryToFilter with a specified GeometryType.

qBodyType (queryToFilter is Query, bodyType is BodyType) returns Query

A query for all entities in queryToFilter which are bodies of the a specified BodyType, or are owned by bodies with the specified BodyType

qBodyType (queryToFilter is Query, bodyTypes is array) returns Query

A query for all entities in queryToFilter with any of a list of BodyTypes.

ParameterTypeAdditional Info
bodyTypes array

An array of BodyTypes.

qConstructionFilter (queryToFilter is Query, constructionFilter is ConstructionObject) returns Query

A query for all construction entities or all non-construction entities in queryToFilter.

See also

ConstructionObject

qActiveSheetMetalFilter (queryToFilter is Query, activeSheetMetal is ActiveSheetMetal) returns Query

A query for all entities in queryToFilter belonging to an active sheet metal part.

See also

ActiveSheetMetal

qSheetMetalFlatFilter (queryToFilter is Query, filterFlat is SMFlatType) returns Query

A query for all entities in queryToFilter belonging to a flattened sheet metal part.

See also

SMFlatType

qSMFlatFilter (subquery is Query, filterFlat is SMFlatType) returns Query

Deprecated: Use qSheetMetalFlatFilter

qPartsAttachedTo (sheetMetalEntities is Query) returns Query

A query for parts to which sheetMetalEntities are attached (e.g. sheet metal bend line entities are attached to a flattened sheet metal part)

qCorrespondingInFlat (entitiesInFolded is Query) returns Query

A query for entities in sheet metal flattened body corresponding to any entitiesInFolded which are part of 3D sheet metal bodies

qMeshGeometryFilter (queryToFilter is Query, meshGeometryFilter is MeshGeometry) returns Query

A query for all mesh entities or all non-mesh entities in queryToFilter.

A body is considered a "mesh entity" if any of its faces or edges have mesh geometry.

See also

MeshGeometry

qModifiableEntityFilter (queryToFilter is Query) returns Query

A query for all modifiable entities in queryToFilter.

An entity is considered non-modifiable if it is an in-context entity.

See also

ModifiableEntityOnly

qAllModifiableSolidBodies

qSketchFilter (queryToFilter is Query, sketchObjectFilter is SketchObject) returns Query

A query for all sketch entities, or all non-sketch entities in queryToFilter.

qParallelPlanes (queryToFilter is Query, referencePlane is Plane, allowAntiparallel is boolean) returns Query

A query for all planar face entities that are parallel to the referencePlane.

ParameterTypeAdditional Info
referencePlane Plane

The plane to reference when checking for parallelism.

allowAntiparallel boolean

Whether to also return entities that are antiparallel.

qParallelPlanes (queryToFilter is Query, referencePlane is Plane) returns Query

A query for all planar face entities in queryToFilter that are parallel to the referencePlane.

ParameterTypeAdditional Info
referencePlane Plane

The plane to reference when checking for parallelism.

qParallelPlanes (queryToFilter is Query, normal is Vector, allowAntiparallel is boolean) returns Query

A query for all planar face entities in queryToFilter that are parallel to a plane specified by the normal vector.

ParameterTypeAdditional Info
normal Vector

The normal vector to reference when checking for parallelism.

allowAntiparallel boolean

Whether to also return entities that are antiparallel.

qPlanesParallelToDirection (queryToFilter is Query, direction is Vector) returns Query

A query for all planar faces in queryToFilter that are parallel to the given direction vector (i.e., the plane normal is perpendicular to direction).

qFacesParallelToDirection (queryToFilter is Query, direction is Vector) returns Query

A query for all faces in queryToFilter that are parallel to the given direction vector e.g. if it is a planar face, the plane normal is perpendicular to direction if it is a cylindrical face, the axis is parallel to direction if it is an extruded face, the extrude direction is parallel to direction

qParallelPlanes (queryToFilter is Query, normal is Vector) returns Query

A query for all planar face entities in queryToFilter that are parallel to a plane specified by the normal vector.

ParameterTypeAdditional Info
normal Vector

The normal vector to reference when checking for parallelism.

qConvexConnectedFaces (seed is Query) returns Query

A query for a set of faces connected to seed via convex edges, flood-filling across any number of convex edges.

A convex edge is an edge which forms a convex angle along the full length of the edge. A convex angle is strictly less than 180 degrees for flat faces, or faces with negative curvature. If one face has positive curvature, and the other has flat or positive curvature, a convex angle is less than or equal to 180 degrees. Thus, the two bounding edges of an exterior fillet are considered convex.

qConcaveConnectedFaces (seed is Query) returns Query

A query for a set of faces connected to seed via concave edges, flood-filling across any number of concave edges.

A concave edge is an edge which forms a concave angle along the full length of the edge. A concave angle is strictly greater than 180 degrees for flat faces, or faces with positive curvature. If one face has negative curvature, and the other has flat or negative curvature, a concave angle is less than or equal to 180 degrees. Thus, the two bounding edges of an interior fillet are considered concave.

qTangentConnectedFaces (seed is Query) returns Query

A query for a set of faces connected to seed via tangent edges, flood-filling across any number of tangent edges.

A tangent edge is an edge joining two faces such that the surface direction is continuous across the edge, at every point along the full length of the edge.

qTangentConnectedFaces (seed is Query, angleTolerance is ValueWithUnits) returns Query

A query for a set of faces connected to seed via tangent edges, flood-filling across any number of tangent edges.

A tangent edge is an edge joining two faces such that the surface direction is continuous across the edge, up to the given angleTolerance, at every point along the full length of the edge.

qTangentConnectedEdges (seed is Query) returns Query

A query for a chain of tangent edges connected to seed via tangent vertices, chaining across any number of tangent vertices.

qLoopEdges (seed is Query) returns Query

A query for a set of edges defining a loop. If the seed has laminar edges, this query will extend to include all laminar loops that contain any seed edges. If the seed has faces, the result will include the loops forming the outer boundary of the joined faces.

qParallelEdges (queryToFilter is Query, direction is Vector) returns Query

A query for all linear edges in queryToFilter which are parallel (or anti-parallel) to the given direction.

qParallelEdges (queryToFilter is Query, edges is Query) returns Query

A query to find all linear edges in queryToFilter which are parallel (or anti-parallel) to any linear edge in edges.

qLoopBoundedFaces (faceAndEdge is Query) returns Query

Given a face and an edge, query for all faces bounded by the given face, on the side of the given edge.

For example, to select an entire pocket, pass in the face which surrounds the pocket, and an edge of the face which touches that pocket.

ParameterTypeAdditional Info
faceAndEdge Query

Should match a face and an edge. If multiple faces and edges match, used the first face and the first edge.

qFaceOrEdgeBoundedFaces (faceAndBoundingEntities is Query) returns Query

Given a seed face and bounding entities, matches all adjacent faces inside the bounding entities, expanding from the seed face.

ParameterTypeAdditional Info
faceAndBoundingEntities Query

A Query for the seed face, followed by any boundary faces or edges. The seed face must be first, so a qUnion should be used to guarantee the order.

qHoleFaces (seed is Query) returns Query

Given a single face inside a hole or hole-like geometry, returns all faces of that hole.

ParameterTypeAdditional Info
seed Query

A query for a single face inside the hole.

qSketchRegion (featureId is Id, filterInnerLoops is boolean) returns Query

A query for all fully enclosed, 2D regions created by a sketch.

ParameterTypeAdditional Info
featureId Id

The feature id of the Sketch being queried.

filterInnerLoops boolean

Optional

Specifies whether to exclude sketch regions fully contained in other sketch regions. A region whose border has a vertex or edge on the outside boundary is not considered "contained." Default is false.

qSketchRegion (featureId is Id) returns Query

qUniqueVertices (vertices is Query) returns Query

A query that filters out duplicate vertices. When duplicates are found, the vertex with the lowest deterministic ID is used.

qMateConnectorsOfParts (parts is Query) returns Query

A query for all mate connectors owned by parts.

qFilletFaces (facesToCompareTo is Query, compareType is CompareType) returns Query

A query for fillet faces of radius equal to, less than or equal to, or greater than or equal to the input faces. If facesToCompareTo does not match one or more fillet faces, the resulting query will not match any faces. Will find the fillet radius from each face and compare to find faces of all fillets on that body that satisfy the compareType.

If facesToCompareTo resolves to multiple fillet faces, all are matched independently. That is, qFilletFaces(qUnion([q1, q2], compareType)) returns the same thing as qUnion([qFilletFaces(q1, compareType), qFilletFaces(q2, compareType)]).

qMatching (referenceEntities is Query) returns Query

Matches any faces or edges within owner bodies of entities in referenceEntities which are geometrically identical (same size and shape) to the face or edge in referenceEntities.

If referenceEntities resolves to multiple entities, all are matched independently. That is, qMatching(qUnion([q1, q2])) returns the same thing as qUnion([qMatching(q1), qMatching(q2)]).

qPatternInstances (featureId is Id, instanceNames is array, entityType is EntityType) returns Query

A query for entities created by a specific instance or instances of an opPattern operation.

ParameterTypeAdditional Info
featureId Id

The Id of the specified feature.

EXAMPLE

id + "pattern1"
instanceNames array

The names of the instances to query for, a subset of the instanceNames passed into the opPattern operation.

qPatternInstances (featureId is Id, instanceName is string, entityType is EntityType) returns Query

qDependency (dependentEntities is Query) returns Query

A query for the true dependency of the given dependentEntities. For instance, the true dependency of the extruded body will be the face or sketch edges of the profile from which it is extruded.

qLaminarDependency (dependentEntities is Query) returns Query

A query for the true dependency of the given dependentEntities, specifically for use with wire edges that have been created from laminar edges. If the immediate dependency is not laminar then it will track back until it reaches a laminar dependency (if there is one).

qContainsPoint (queryToFilter is Query, point is Vector) returns Query

A query for all entities (bodies, faces, edges, or points) in queryToFilter containing a specified point.

ParameterTypeAdditional Info
point Vector

A 3D point, in world space.

qIntersectsLine (queryToFilter is Query, line is Line) returns Query

A query for all entities (bodies, faces, edges, or points) in queryToFilter touching a specified infinite line.

qIntersectsPlane (queryToFilter is Query, plane is Plane) returns Query

A query for all entities (bodies, faces, edges, or points) in queryToFilter touching a specified infinite plane.

ParameterTypeAdditional Info
plane Plane

EXAMPLE

plane(vector(0, 0, 0) * meter, vector(0, 0, 1))

qInFrontOfPlane (queryToFilter is Query, plane is Plane) returns Query

A query for all entities (bodies, faces, edges, or points) in queryToFilter in front of a specified infinite plane. Entities intersecting the plane will not be resolved. Only entities completely on one side or coincident with the plane will be selected. Use flip(plane) to query entities on the other side of the plane. For example, for the XY plane through the origin with the normal (0, 0, 1), qInFrontOfPlane will resolve the vertices (1, 1, 0) and (1, 1, 1) but not the vertex (1, 1, -1).

ParameterTypeAdditional Info
plane Plane

EXAMPLE

plane(vector(0, 0, 0) * meter, vector(0, 0, 1))

qCoincidesWithPlane (queryToFilter is Query, plane is Plane) returns Query

A query for all entities (bodies, faces, edges, or points) in queryToFilter coinciding with a specified infinite plane.

ParameterTypeAdditional Info
plane Plane

EXAMPLE

plane(vector(0, 0, 0) * meter, vector(0, 0, 1))

qWithinRadius (queryToFilter is Query, point is Vector, radius is ValueWithUnits) returns Query

A query for all entities (bodies, faces, edges or points) in queryToFilter that are within a specified radius from a point.

ParameterTypeAdditional Info
point Vector

The point from which to check distance from.

radius ValueWithUnits

The distance away from the point.

qClosestTo (queryToFilter is Query, point is Vector) returns Query

A query for the entity in queryToFilter closest to a point.

In the case of a tie, resolves to all entities within TOLERANCE.zeroLength of being the closest.

ParameterTypeAdditional Info
point Vector

A position vector for the point to find entities closest to.

qFarthestAlong (queryToFilter is Query, direction is Vector) returns Query

A query for the entity in queryToFilter farthest along a direction in world space. In the case of a tie, resolves to all entities within TOLERANCE.zeroLength of being the farthest.

ParameterTypeAdditional Info
direction Vector

A vector for the direction to find the entity farthest away.

qLargest (queryToFilter is Query) returns Query

A query to find the largest entity (by length, area, or volume) in queryToFilter.

If queryToFilter contains entities of different dimensionality (e.g. both solid bodies and faces), only entities of the highest dimension are considered. Entities are compared by length, area or volume. Multiple entities may be returned if they tie within tolerance.

qSmallest (queryToFilter is Query) returns Query

A query to find the smallest entity (by length, area, or volume) in queryToFilter.

If queryToFilter contains entities of different dimensionality (e.g. solid bodies and faces), only entities of the highest dimension are considered. Entities are compared by length, area or volume. Multiple entities may be returned if they tie within tolerance.

dummyQuery (operationId is Id, entityType is EntityType) returns Query

qSplitBy (featureId is Id, entityType, backBody is boolean) returns Query

Given the id of a split feature, get entities of a given EntityType on the front or the back side of the split. For a split by face or part, the front denotes the body in the direction of the split tool's surface normal, and the back denotes the body opposite the normal. For a split by isocline, the front denotes non-steep faces and edges, and the back denotes steep entities.

ParameterTypeAdditional Info
featureId Id

EXAMPLE

id + "split1"
backBody boolean

EXAMPLE

false indicates the entities in the front.

EXAMPLE

true indicates the entities in the back.

sketchEntityQuery (operationId is Id, entityType, sketchEntityId is string) returns Query

Gets the wire body entities created for a specific sketch entity. If the sketch id created multiple sketch entities, will return all the wire bodies.

ParameterTypeAdditional Info
operationId Id

Id of the sketch feature.

entityType

EXAMPLE

EntityType.EDGE to match the edges on the wire bodies.

EXAMPLE

EntityType.BODY to match the bodies themselves.

EXAMPLE

undefined to match both.
sketchEntityId string

Sketch id.

evaluateQuery (context is Context, query is Query) returns array

Returns an array of queries for the individual entities in a context which match a specified query. The returned array contains exactly one transient query for each matching entity at the time of the call. If the context is modified, the returned queries may become invalid and no longer match an entity.

It is usually not necessary to evaluate queries, since operation and evaluation functions can accept non-evaluated queries. Rather, the evaluated queries can be used to count the number of entities (if any) that match a query, or to iterate through the list to process entities individually.

The order of entities returned by this function is arbitrary (and generally not predictable) except in the case of a qUnion query. In that case, the entities matched by earlier queries in the argument to qUnion are returned first.

areQueriesEquivalent (context is Context, first is Query, second is Query) returns boolean

Returns true if the supplied queries evaluate to the same set of entities. This function is order-invariant, so if the two queries evaluate to the same entities, but in a different order, the function will still return true.

isQueryEmpty (context is Context, query is Query) returns boolean

Returns true if query evaluates to nothing. Equivalent to evaluateQuery(context, query) == [] or size(evaluateQuery(context, query)) == 0, but faster than either of those approaches if the query is not empty.

evaluate

Evaluation functions return information about the topological entities in the context, like bounding boxes, tangent planes, projections, and collisions. Evaluation functions take a context and a map that specifies the computation to be performed and return a ValueWithUnits, a FeatureScript geometry type (like Line or Plane), or a special type like DistanceResult. They may also throw errors if a query fails to evaluate or the input is otherwise invalid.

evApproximateCentroid (context is Context, arg is map) returns Vector

Find the centroid of an entity or group of entities. This is equivalent to the center of mass for a constant density object. Warning: This is an approximate value and it is not recommended to use this for modeling purposes that will be negatively affected in case the approximation changes. Consider using the center of a bounding box instead.

ParameterTypeAdditional Info
arg map
  • entities
Query

The entities to take the center of mass of.

MassProperties type

The result of an evApproximateMassProperties call.

ValueTypeDescription
MassProperties map
  • mass
ValueWithUnits

The total mass.

  • centroid
Vector

The center of mass with respect to the given reference frame, or with respect to the origin if a reference frame is not specified.

  • inertia
MatrixWithUnits

The 3D inertia tensor, with units of mass * length ^ 2. Evaluated with respect to the reference frame, or with respect to the centroid if a reference frame is not specified.

  • volume
ValueWithUnits

Total volume. Only returned for solid bodies.

  • area
ValueWithUnits

Total area. Only returned for faces.

  • length
ValueWithUnits

Total length. Only returned for edges.

  • count
number

Total count. Only returned for vertices.

evApproximateMassProperties (context is Context, arg is map) returns MassProperties

Calculates approximate mass properties of an entity or group of entities. Returns mass, centroid, inertia tensor, and volume/area/length/count for bodies/faces/edges/vertices, respectively. Warning: These are approximate values and it is not recommended to use them for modeling purposes that will be negatively affected in case the approximation changes.

ParameterTypeAdditional Info
arg map
  • entities
Query

The entities of which to compute mass properties. Only entities of the highest dimensionality will be considered.

  • density
ValueWithUnits

The density of the entities, with appropriate units.

EXAMPLE

1 * kilogram / meter ^ 3 could be the density of 3D solid bodies

EXAMPLE

1 * kilogram / meter ^ 2 could be the density of 2D faces or sheet bodies

EXAMPLE

1 * kilogram / meter could be the density of 1D edges or wire bodies

EXAMPLE

1 * kilogram could be the mass of each 0D vertex or point body
  • referenceFrame
CoordSystem

Optional

Optional coordinate system. Defaults to the centroid with world axes for the inertia tensor, and world coordinates for the centroid.

evArea (context is Context, arg is map) returns ValueWithUnits

Return the total area of all the entities. If no matching 2D faces are found the total area will be zero.

ParameterTypeAdditional Info
arg map
  • entities
Query

evAxis (context is Context, arg is map) returns Line

If the query finds one entity with an axis -- a line, circle, plane, cylinder, cone, sphere, torus, mate connector, or revolved surface -- return the axis. Otherwise throw an exception.

ParameterTypeAdditional Info
arg map
  • axis
Query

evBox3d (context is Context, arg is map) returns Box3d

Find a bounding box around an entity, optionally with respect to a given coordinate system. There is also an option to use a faster but less accurate method.

ParameterTypeAdditional Info
arg map
  • topology
Query

The entity to find the bounding box of.

  • cSys
CoordSystem

Optional

The coordinate system to use (if not the standard coordinate system).

  • tight
boolean

Optional

Get the tightest possible bounding box. Defaults to true.

EXAMPLE

true for a bounding box precisely at the extents of the given entities (and no bigger).

EXAMPLE

false for a bounding box at least as big as the given entities, using a faster algorithm.

evCollision (context is Context, arg is map) returns array

Find collisions between tools and targets. Each collision is a map with field type of type ClashType and fields target, targetBody, tool, and toolBody of type Query.

ParameterTypeAdditional Info
arg map
  • tools
Query
  • targets
Query

evCornerType (context is Context, arg is map) returns map

Return the type of corner found at a vertex of a sheet metal model

ParameterTypeAdditional Info
arg map
  • vertex
Query
ReturnTypeDescription
map
  • cornerType
SMCornerType

the type of the corner

  • primaryVertex
Query

the vertex that defines the corner

  • allVertices
array

array of transient queries for all definition vertices associated with the corner

ThrowsAdditional info
GBTErrorStringEnum.BAD_GEOMETRY

The query does not evaluate to a single vertex

evCurveDefinition (context is Context, arg is map) returns map

Given a query for a curve, return a Circle, Ellipse, Line, or BSplineCurve value for the curve. If the curve is none of these types, return a map with unspecified contents.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to evaluate.

  • returnBSplinesAsOther
boolean

Optional

If true, do not return B-spline curves (to avoid the associated time cost). Default is false.

ThrowsAdditional info
GBTErrorStringEnum.INVALID_INPUT

The first resolved entity was not an edge.

GBTErrorStringEnum.CANNOT_RESOLVE_ENTITIES

Input entities are invalid or there are no input entities.

evApproximateBSplineCurve (context is Context, arg is map) returns BSplineCurve

Given a query for a curve, return its approximation (or exact representation if possible) as a B-spline. The options forceCubic and forceNonRational may be used to restrict the type of spline that is returned, but even if these options are false, a cubic non-rational spline may be returned.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to approximate.

  • forceCubic
boolean

Optional

If true, a cubic spline will be returned. Defaults to false.

  • forceNonRational
boolean

Optional

If true, a non-rational spline will be returned. Defaults to false.

  • tolerance
number

Optional

Specifies the desired approximation tolerance: the maximum distance (in meters) between the original curve and the returned spline representation. Default is 1e-6, minimum is 1e-8, and maximum is 1e-2.

DistanceResult type

The result of an evDistance call -- information about the extremal distance and the attaining point / line / entity.

ValueTypeDescription
DistanceResult map
  • distance
ValueWithUnits

The minimal or maximal distance.

  • sides
array

An array of 2 maps, containing information about where the extremum was found for each side. Each map has a:

point (Vector) : The position in world space that is closest or farthest to the other side. The distance field is measured between the two values of point.

index (integer) : the index into the line or point array or into the query results, if a query is passed in.

parameter (number or length or array of two numbers) : If the index refers to an edge, the parameter is a number between 0 and 1 (unless extend for that side was passed in). It is in the form that evEdgeTangentLine and evEdgeCurvature consume (with arcLengthParameterization set to the same value that was passed into evDistance).

If the index refers to a point, the parameter is 0.

If the index refers to a Line, the parameter is a length representing the distance along the direction.

If the index refers to a face, the parameter is a 2D Vector in the form that evFaceTangentPlane consumes. If this face is a mesh or a plane, the parameter is a 2D Vector of zeroes.

If the index refers to a Plane, the parameter is a 2D Vector representing the lengths along the plane's x and y axes.

evDistance (context is Context, arg is map) returns DistanceResult

Computes the minimum or maximum distance between geometry on side0 and geometry on side1. "Geometry" means entities, points, or lines. When the minimum or the maximum is not uniquely defined, ties will be broken arbitrarily.

EXAMPLE

evDistance(context, { "side0" : vector(1, 2, 3) * meter, "side1" : query }).distance returns the minimum distance from any entity returned by query to the point (1, 2, 3) meters.

EXAMPLE

result = evDistance(context, { "side0" : qEverything(EntityType.VERTEX), "side1" : qEverything(EntityType.VERTEX), "maximum" : true }) computes the pair of vertices farthest apart. qNthElement(qEverything(EntityType.VERTEX), result.sides[0].index) queries for one of these vertices.

See also

DistanceResult

ParameterTypeAdditional Info
arg map
  • side0

One of the following: A query, or a point (3D Length Vector), or a Line, or a Plane, or an array of points, or an array of Lines, or an array of Planes.

EXAMPLE

qNthElement(qEverything(EntityType.FACE), 0) or vector(1, 2, 3) * meter or line(vector(1, 0, 1) * meter, vector(1, 1, 1) or plane(vector(1,1,1) * meter, vector(0,0,1), vector(1,0,0)).
  • extendSide0
boolean

Optional

If true and side0 is a query, bodies will be ignored and edges and faces extended to their possibly infinite underlying surfaces. Defaults to false.

  • side1

Like side0.

  • extendSide1
boolean

Optional

Like extendSide0.

  • maximum
boolean

Optional

If true, compute the maximum instead of the minimum. Defaults to false. Not allowed to be true if a line is passed in in either side or if either extend is true.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter returned for edges measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-calculate parameterization. This field only controls the parameter returned for edges. It does not control the parameter returned for points, Lines, faces, or Planes.

  • useFaceParameter
boolean

Optional

For Onshape internal use.

RaycastResult type

Map containing the results of one collision between a ray and an entity.

ValueTypeDescription
RaycastResult map
  • entity
Query

A query for the entity hit by the ray.

  • entityType
EntityType

The type of the entity.

  • parameter

Parameters for where the ray hit the entity. A unitless 2-vector for a face, a number for an edge, else undefined.

  • intersection
Vector

Intersection point.

  • distance
ValueWithUnits

Distance of the intersection point from the ray origin.

evRaycast (context is Context, arg is map) returns array

Detect intersections between a ray and the given entities.

ParameterTypeAdditional Info
arg map
  • entities
Query

A query for target entities. If bodies are provided, the result will contain intersections for individual entities owned by the body.

  • ray
Line

The ray to intersect the entities. Because the passed-in Line is interpreted as a ray, by default, intersections with entities "behind" the ray origin are not detected. includeIntersectionsBehind can be set to true if those intersections are desired.

EXAMPLE

line(vector(0, 0, 0) * inch, vector(1, 0, 0)) specifies the positive x-axis
  • closest
boolean

Optional

Get only the closest intersection with any of the entities. Defaults to true.

  • includeIntersectionsBehind
boolean

Optional

Return intersections that are behind the ray origin. Defaults to false. Cannot be set to true if closest is true.

Return typeDescription
array

An array of RaycastResults for each intersection in front of the ray, ordered from closest to farthest.

evEdgeConvexity (context is Context, arg is map) returns EdgeConvexityType

Return the convexity type of the given edge, CONVEX, CONCAVE, SMOOTH, or VARIABLE. If the edge is part of a body with inside and outside convex and concave have the obvious meanings.

ParameterTypeAdditional Info
arg map
  • edge
Query
ThrowsAdditional info
GBTErrorStringEnum.TOO_MANY_ENTITIES_SELECTED

The query evaluates to more than one entity

GBTErrorStringEnum.BAD_GEOMETRY

The query does not evaluate to a single edge.

EdgeCurvatureResult type

The result of an evEdgeCurvature call -- a coordinate system for the Frenet frame and the curvature defined at a point

ValueTypeDescription
EdgeCurvatureResult map
  • frame
CoordSystem

The frame. The Z vector is the tangent, the X vector is the normal and the Y vector is the binormal

  • curvature
ValueWithUnits

The curvature (inverse length units).

evEdgeCurvature (context is Context, arg is map) returns EdgeCurvatureResult

Return a Frenet frame along an edge, with curvature. If the curve has zero curvature at an evaluated point then the returned normal and binormal are arbitrary and only the tangent is significant.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to use

EXAMPLE

qNthElement(qEverything(EntityType.EDGE), 1)
  • parameter
number

A number in the range 0..1 indicating the point along the curve to evaluate the frame at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization. The parameterization is identical to that used by evEdgeTangentLines. Results obtained with arcLengthParameterization will have lower accuracy due to approximation.

  • face
Query

Optional

If present, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. Must be adjacent to edge.

ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_LINE

A frame could not be calculated for the specified input.

evEdgeCurvatures (context is Context, arg is map) returns array

Return Frenet frames along an edge, with curvature. If the curve has zero curvature at an evaluated point then the returned normal and binormal are arbitrary and only the tangent is significant.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to use

EXAMPLE

qNthElement(qEverything(EntityType.EDGE), 1)
  • parameters
array

An array of numbers in the range 0..1 indicating points along the curve to evaluate frames at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization. The parameterization is identical to that used by evEdgeTangentLines. Results obtained with arcLengthParameterization will have lower accuracy due to approximation.

  • face
Query

Optional

If present, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. Must be adjacent to edge.

Return typeDescription
array

An array of EdgeCurvatureResults.

ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_LINE

A frame could not be calculated for the specified input.

curvatureFrameTangent (curvatureResult is EdgeCurvatureResult) returns Vector

Returns the tangent vector of a curvature frame

Return typeDescription
Vector

A unit 3D vector in world space.

curvatureFrameNormal (curvatureResult is EdgeCurvatureResult) returns Vector

Returns the normal vector of a curvature frame

Return typeDescription
Vector

A unit 3D vector in world space.

curvatureFrameBinormal (curvatureResult is EdgeCurvatureResult) returns Vector

Returns the binormal vector of a curvature frame

Return typeDescription
Vector

A unit 3D vector in world space.

evEdgeTangentLine (context is Context, arg is map) returns Line

Return one tangent Line to an edge.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to use

EXAMPLE

qNthElement(qEverything(EntityType.EDGE), 1)
  • parameter
number

A number in the range 0..1 indicating a point along the curve to evaluate the tangent at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization.

  • face
Query

Optional

If present, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. Must be adjacent to edge.

ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_LINE

A tangent line could not be evaluated for the given query.

evEdgeTangentLines (context is Context, arg is map) returns array

Return tangent lines to a edge.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to use

EXAMPLE

qNthElement(qEverything(EntityType.EDGE), 1)
  • parameters
array

An array of numbers in the range 0..1 indicating points along the curve to evaluate tangents at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization.

  • face
Query

Optional

If present, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. Must be adjacent to edge.

Return typeDescription
array

An array of Lines.

ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_LINE

A tangent line could not be evaluated for the given query.

evEdgeCurvatureDerivative (context is Context, arg is map) returns Vector

Evaluate the derivative of the curvature vector with respect to arc length, that is, the third derivative of the curve with respect to arc length.

ParameterTypeAdditional Info
arg map
  • edge
Query

The curve to use

EXAMPLE

qNthElement(qEverything(EntityType.EDGE), 1)
  • parameter
number

A number in the range 0..1 indicating a point along the curve to evaluate the tangent at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization.

ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_LINE

The curvature derivative could not be evaluated for the given query.

evFacePeriodicity (context is Context, arg is map) returns array

Return the periodicity in primary and secondary direction of a face, returned in an array of booleans.

A particular direction is periodic when the face's underlying surface definition is wrapped along that direction. For instance, if primary direction is periodic, the parameters [0, v] and [1, v] will prepresent the same point for all valid v. If the secondary direction is periodic, the parameters [u, 0] and [u, 1] represent the same point for all valid u.

ParameterTypeAdditional Info
arg map
  • face
Query

The face on which to evaluate periodicity

  • trimmed
boolean

Optional

If true (default), return trimmed face periodicity instead of the underlying surface's.

FaceCurvatureResult type

The result of an evFaceCurvature call -- principal directions and curvatures at a point.

The curvature along a particular direction (in the tangent plane) is the inverse of the radius of curvature in that direction. This curvature is positive if the radius of curvature points away from the normal direction, negative if it points along the normal direction, or zero if there is no curvature in that direction. The principal curvatures at a point are the directions of minimal and maximal curvature along the surface at that point.

ValueTypeDescription
FaceCurvatureResult map
  • minCurvature
ValueWithUnits

The smaller of the two principal curvatures (inverse length units).

  • maxCurvature
ValueWithUnits

The larger of the two principal curvatures (inverse length units).

  • minDirection
Vector

A 3D unit vector corresponding to minCurvature.

  • maxDirection
Vector

A 3D unit vector corresponding to maxCurvature.

evFaceCurvature (context is Context, arg is map) returns FaceCurvatureResult

Given a face, calculate and return principal curvatures at a point on that face, specified by its parameter-space coordinates.

EXAMPLE

 // Ellipsoid measuring 10in x 4in x 6in
fEllipsoid(context, id + "ellipsoid", {
            "center" : vector(0, 0, 0) * inch,
            "radius" : vector(5 * inch, 2 * inch, 3 * inch)
        });
const ellipseFace = qCreatedBy(id + "ellipsoid", EntityType.FACE);
const topPoint = vector(0, 0, 3) * inch; // Point on top of ellipsoid
const distanceResult = evDistance(context, { // Closest position to topPoint on ellipseFace
            "side0" : ellipseFace,
            "side1" : topPoint
        });
var uvCoordinatesAtTopPoint = distanceResult.sides[0].parameter;
var curvatureResult = evFaceCurvature(context, {
        "face" : ellipseFace,
        "parameter" : uvCoordinatesAtTopPoint
    });
//  curvatureResult is {
//      minCurvature: 3 * inch / (5 * inch)^2,
//      maxCurvature: 3 * inch / (2 * inch)^2,
//      minDirection: vector(1, 0, 0),
//      maxDirection: vector(0, 1, 0)
//  }
ParameterTypeAdditional Info
arg map
  • face
Query

The face on which to evaluate the curvature. The face cannot be a mesh.

EXAMPLE

qNthElement(qEverything(EntityType.FACE), 1)
  • parameter
Vector

a 2d unitless parameter-space vector specifying the location on the face. The coordinates are relative to the parameter-space bounding box of the face.

EXAMPLE

vector(0.5, 0.5)

evFaceCurvatures (context is Context, arg is map) returns array

Given a face, calculate and return an array of principal curvatures at points on that face, specified by its parameter-space coordinates.

ParameterTypeAdditional Info
arg map
  • face
Query

A single face on which to evaluate the curvatures. The face cannot be a mesh.

EXAMPLE

qNthElement(qEverything(EntityType.FACE), 1)
  • parameters
array

an array of 2d unitless parameter-space vectors specifying locations on the face. The coordinates are relative to the parameter-space bounding box of the face.

EXAMPLE

[ vector(0.5, 0.5), vector(0, 1) ]
Return typeDescription
array

An array of FaceCurvatureResults.

evFaceCurvatureDerivative (context is Context, arg is map) returns MatrixWithUnits

Given a face, calculate and return the derivative of the second fundamental form of the face in a given direction.

The second fundamental form is a matrix that may be computed from the principal curvatures of a surface as

const curvature = evFaceCurvature(context, { ... });
const secondFF = - curvature.minCurvature * transpose(matrix([curvature.minDirection])) * matrix([curvature.minDirection])
                 - curvature.maxCurvature * transpose(matrix([curvature.maxDirection])) * matrix([curvature.maxDirection]);
ParameterTypeAdditional Info
arg map
  • face
Query

The face on which to evaluate the curvature. The face cannot be a mesh.

EXAMPLE

qNthElement(qEverything(EntityType.FACE), 1)
  • parameter
Vector

a 2d unitless parameter-space vector specifying the location on the face. The coordinates are relative to the parameter-space bounding box of the face.

EXAMPLE

vector(0.5, 0.5)
  • direction
Vector

a 3d unitless vector specifying a direction in the tangent plane of the face. It should be a unit vector perpendicular to the face's normal at the given point.

Return typeDescription
MatrixWithUnits

A 3x3 matrix with units of length ^ -2.

evFaceNormalAtEdge (context is Context, arg is map) returns Vector

Return the surface normal of a face at a position on one of its edges.

If the first result is not a face, throw an exception.

ParameterTypeAdditional Info
arg map
  • edge
Query
  • face
Query
  • parameter
number

A number in the range 0..1 indicating a point along the edge to evaluate the tangent at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization.

  • usingFaceOrientation
boolean

Optional

If true, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. If false, use the default orientation of the edge, which is the same orientation used by evEdgeTangentLine. Default is false.

evFaceTangentPlaneAtEdge (context is Context, arg is map) returns Plane

Return a Plane tangent to face at a position on one of its edges.

If the first result is not a face, throw an exception.

ParameterTypeAdditional Info
arg map
  • edge
Query
  • face
Query
  • parameter
number

A number in the range 0..1 indicating a point along the edge to evaluate the tangent at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization.

  • usingFaceOrientation
boolean

Optional

If true, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. If false, use the default orientation of the edge, which is the same orientation used by evEdgeTangentLine. Default is false.

evFaceTangentPlanesAtEdge (context is Context, arg is map)

Return an array of Planes tangent to a face at an array of parameters on one of its edges. The x-direction of the plane is oriented with the tangent of the edge with respect to usingFaceOrientation.

If the first result is not a face, throw an exception.

ParameterTypeAdditional Info
arg map
  • edge
Query
  • face
Query
  • parameters
array

An array of numbers in the range 0..1 indicating points along the edge to evaluate the tangent at.

  • arcLengthParameterization
boolean

Optional

If true (default), the parameter measures distance along the edge, so 0.5 is the midpoint. If false, use an arbitrary but faster-to-evaluate parameterization.

  • usingFaceOrientation
boolean

Optional

If true, the edge orientation used is such that walking along the edge with "up" being the face normal will keep face to the left. If false, use the default orientation of the edge, which is the same orientation used by evEdgeTangentLine. Default is false.

evFaceTangentPlane (context is Context, arg is map) returns Plane

Given a face, calculate and return a Plane tangent to that face, where the plane's origin is at the point specified by its parameter-space coordinates.

ParameterTypeAdditional Info
arg map
  • face
Query

The face to evaluate. The face cannot be a mesh.

EXAMPLE

qNthElement(qEverything(EntityType.FACE), 1)
  • parameter
Vector

2d unitless parameter-space vector specifying the location of tangency on the face. The coordinates are relative to the parameter-space bounding box of the face.

EXAMPLE

vector(0.5, 0.5) places the origin at the bounding box's center.
ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_PLANE

Could not find a tangent plane or there was a problem with face parameterization.

evFaceTangentPlanes (context is Context, arg is map) returns array

Given a face, calculate and return an array of Planes tangent to that face, where each plane's origin is located at the point specified by its parameter-space coordinates.

ParameterTypeAdditional Info
arg map
  • face
Query

The face to evaluate. The face cannot be a mesh.

EXAMPLE

qNthElement(qEverything(EntityType.FACE), 1)
  • parameters
array

an array of 2d unitless parameter-space vectors specifying locations of tangency on the face. The coordinates are relative to the parameter-space bounding box of the face.

EXAMPLE

[ vector(0.5, 0.5), vector(0, 1) ]
  • returnUndefinedOutsideFace
boolean

Optional

If true, the function will only return a plane if vector is on the face, otherwise returns undefined. Default is false.

ThrowsAdditional info
GBTErrorStringEnum.NO_TANGENT_PLANE

Could not find a tangent plane or there was a problem with face parameterization.

evFilletRadius (context is Context, arg is map) returns ValueWithUnits

Given a face of a constant radius fillet, return the radius of fillet.

ParameterTypeAdditional Info
arg map
  • face
Query
ThrowsAdditional info
GBTErrorStringEnum.BAD_GEOMETRY

The first resolved entity was not a filleted face.

evLength (context is Context, arg is map) returns ValueWithUnits

Return the total length of all the entities (if they are edges) and edges belonging to entities (if they are bodies). If no edges are found the total length will be zero.

ParameterTypeAdditional Info
arg map
  • entities
Query

evLine (context is Context, arg is map) returns Line

If the edge is a line, return a Line value for the given edge.

ParameterTypeAdditional Info
arg map
  • edge
Query
ThrowsAdditional info
GBTErrorStringEnum.INVALID_INPUT

The first resolved entity was not a line.

evMateConnector (context is Context, arg is map) returns CoordSystem

Gets the coordinate system of the given mate connector

ParameterTypeAdditional Info
arg map
  • mateConnector
Query

The mate connector to evaluate.

evOwnerSketchPlane (context is Context, arg is map) returns Plane

Return the plane of the sketch that created the given entity.

ParameterTypeAdditional Info
arg map
  • entity
Query

The sketch entity. May be a vertex, edge, face, or body.

  • checkAllEntities
boolean

Optional

If true, the function will only return a plane if all entities queried under 'entity' share coplanar sketch planes. Otherwise, the plane will only be evaluated for the first entity in the query. Default is false.

ThrowsAdditional info
GBTErrorStringEnum.CANNOT_RESOLVE_PLANE

Entities were not created by a sketch or do not share the same sketch plane.

evPlane (context is Context, arg is map) returns Plane

If the face is a planar face or a mate connector, return the Plane it represents.

ParameterTypeAdditional Info
arg map
  • face
Query
ThrowsAdditional info
GBTErrorStringEnum.CANNOT_RESOLVE_PLANE

The first resolved entity was not a planar face or mate connector.

evPlanarEdge (context is Context, arg is map) returns Plane

If the edge lies in a plane, return a Plane it lies in.

ParameterTypeAdditional Info
arg map
  • edge
Query
ThrowsAdditional info
GBTErrorStringEnum.CANNOT_RESOLVE_PLANE

The first resolved entity was not a planar edge.

evPlanarEdges (context is Context, arg is map) returns Plane

If all the edges in a query share the same plane, return a Plane they lie in.

ParameterTypeAdditional Info
arg map
  • edges
Query
ThrowsAdditional info
GBTErrorStringEnum.CANNOT_RESOLVE_PLANE

Edges in the query were either not planar or do not share the same plane.

evSurfaceDefinition (context is Context, arg is map) returns map

Return a descriptive value for a face, or the first face if the query finds more than one. Return a Cone, Cylinder, Plane, Sphere, Torus, or BSplineSurface as appropriate for the face, or an unspecified map value if the face is none of these with surfaceType filled of type SurfaceType

ParameterTypeAdditional Info
arg map
  • face
Query
  • returnBSplinesAsOther
boolean

Optional

If true, do not return B-spline surfaces (to avoid the associated time cost). Default is false.

ThrowsAdditional info
"GBTErrorStringEnum.CANNOT_RESOLVE_PLANE"

The first result is not a face.

evApproximateBSplineSurface (context is Context, arg is map) returns map

Given a query for a face, return its approximation as a B-spline, including trim boundaries. The options forceCubic and forceNonRational may be used to restrict the type of spline that is returned for the surface, but even if these options are false, a cubic non-rational spline may be returned.

The returned representation includes a surface, the boundary loop as 2D splines in UV space, and any interior loops. The returned UV curves are typically degree 1 or 2 and non-rational. For periodic surfaces, outer and inner loops are not clearly defined and relying on them is not recommended.

ParameterTypeAdditional Info
arg map
  • face
Query

The curve to approximate.

  • forceCubic
boolean

Optional

If true, the returned surface will be a cubic spline. This does not affect the trim curves. Defaults to false.

  • forceNonRational
boolean

Optional

If true, the returned surface will be non-rational. Defaults to false.

  • tolerance
number

Optional

Specifies the desired approximation tolerance: the maximum distance (in meters) between the original face and the returned spline representation. Default is 1e-6, minimum is 1e-8, and maximum is 1e-4. The tolerance for trim curves is 10x the specified value.

ReturnTypeDescription
map
  • bSplineSurface
BSplineSurface

the underlying 3D surface

  • boundaryBSplineCurves
array

array of 2D BSplineCurves representing the trimming boundary of the face. May be empty if the face is the entirety of the surface.

  • innerLoopBSplineCurves
array

array of arrays of 2D BSplineCurves representing the inner loops (if any) of the trimming boundary of the face.

evVertexPoint (context is Context, arg is map) returns Vector

Return the coordinates of a point, or the origin of a mate connector.

ParameterTypeAdditional Info
arg map
  • vertex
Query

evVolume (context is Context, arg is map) returns ValueWithUnits

Return the total volume of all the entities. If no matching 3D bodies are found, the total volume will be zero.

ParameterTypeAdditional Info
arg map
  • entities
Query
  • accuracy
VolumeAccuracy

Math

box

This module refers to 3D bounding boxes, e.g. the result of a call to evBox3d.

This is not to be confused with the box standard type used for references.

Box3d type

A three-dimensional bounding box.

ValueTypeDescription
Box3d map
  • minCorner
Vector

A 3D position representing the corner with the smallest x, y, and z coordinates.

  • maxCorner
Vector

A 3D position representing the corner with the largest x, y, and z coordinates.

canBeBox3d (value) predicate

Typecheck for Box3d

box3d (minCorner is Vector, maxCorner is Vector) returns Box3d

Construct a bounding box from two opposite corners.

box3d (pointArray is array) returns Box3d

Construct a bounding box containing all points in pointArray

transformBox3d (boxIn is Box3d, transformation is Transform) returns Box3d

Return a box aligned with transformed coordinate system containing the input box

extendBox3d (bBox is Box3d, absoluteValue is ValueWithUnits, factor is number) returns Box3d

Return an enlarged bounding box. The box is scaled by 1 + factor around its midpoint, and then each face is moved outward by absoluteValue (inward if absoluteValue is negative).

ParameterTypeAdditional Info
absoluteValue ValueWithUnits

The absolute distance to move each face of the box. The corners move sqrt(3) times as far.

factor number

The relative amount to expand the box, with 0 leaving it unchanged.

box3dCenter (bBox is Box3d) returns Vector

Return the center of the bounding box.

box3dDiagonalLength (bBox is Box3d) returns ValueWithUnits

Return the length of the diagonal from the minCorner to the maxCorner of the bounding box.

insideBox3d (point is Vector, bBox is Box3d) predicate

Whether the specified point is within the bounding box.

coordSystem

WORLD_ORIGIN const

Position of the world origin, equivalent to vector(0, 0, 0) * meter

X_DIRECTION const

Direction parallel to the X axis, equivalent to vector(1, 0, 0)

Y_DIRECTION const

Direction parallel to the Y axis, equivalent to vector(0, 1, 0)

Z_DIRECTION const

Direction parallel to the Z axis, equivalent to vector(0, 0, 1)

WORLD_COORD_SYSTEM const

The world coordinate system, equivalent to coordSystem(vector(0, 0, 0) * meter, vector(1, 0, 0), vector(0, 0, 1))

CoordSystem type

A right-handed Cartesian coordinate system. Used for converting points and geometry between different reference frames, or for creating planes and mate connectors.

The y-axis of a coordinate system is not stored, but it can be obtained by calling the yAxis function, which simply performs a cross product.

See also

toWorld(CoordSystem)

fromWorld(CoordSystem)

coordSystem(Plane)

plane(CoordSystem)

opMateConnector

ValueTypeDescription
CoordSystem map
  • origin
Vector

A 3D point, in world space, representing the origin of the coordinate system.

  • xAxis
Vector

A 3D unit vector, in world space, representing the x-axis of the coordinate system.

  • zAxis
Vector

A 3D unit vector, in world space, representing the z-axis of the coordinate system. Must be perpendicular to the xAxis.

coordSystem (origin is Vector, xAxis is Vector, zAxis is Vector) returns CoordSystem

Creates a Cartesian coordinate system.

See also

CoordSystem

ParameterTypeAdditional Info
origin Vector

A 3D point in world space.

xAxis Vector

A 3D vector in world space. Need not be normalized.

zAxis Vector

A 3D vector in world space. Need not be normalized but must be orthogonal to xAxis.

tolerantEquals (cSys1 is CoordSystem, cSys2 is CoordSystem) predicate

Check that two CoordSystems are the same up to tolerance.

toWorld (cSys is CoordSystem, pointInCSys is Vector) returns Vector

Convert a specified point from a specified coordinate system into world space.

EXAMPLE

toWorld(cSys, vector(0, 0, 0)) equals cSys.origin
ParameterTypeAdditional Info
pointInCSys Vector

A 3D vector, measured with respect to the cSys provided.

Return typeDescription
Vector

A 3D vector in world space.

toWorld (cSys is CoordSystem) returns Transform

Returns a Transform which will transform coordinates measured in cSys into world coordinates.

EXAMPLE

toWorld(cSys) * vector(0, 0, 0) equals cSys.origin

When used in operations which place or move parts (like opTransform, opPattern, or addInstance), this transform will (somewhat counterintuitively) move parts from the world origin and orientation to the cSys origin and orientation.

fromWorld (cSys is CoordSystem, worldPoint is Vector) returns Vector

Convert a specified point from world space into a specified coordinate system.

EXAMPLE

fromWorld(cSys, cSys.origin) equals vector(0, 0, 0)
ParameterTypeAdditional Info
worldPoint Vector

A 3D vector, measured in world space.

Return typeDescription
Vector

A 3D vector measured in cSys

fromWorld (cSys is CoordSystem) returns Transform

Returns a Transform which will transform coordinates measured in world space into cSys coordinates.

EXAMPLE

fromWorld(cSys) * cSys.origin equals vector(0, 0, 0)

When used in operations which place or move parts (like opTransform, opPattern, or addInstance), this transform will (somewhat counterintuitively) move parts from the cSys origin and orientation to the world origin and orientation.

scaleNonuniformly (xScale is number, yScale is number, zScale is number, cSys is CoordSystem) returns Transform

Returns a Transform that represents 3 independent scalings along the X, Y, and Z axes of a particular cSys, centered around cSys.origin.

yAxis (cSys is CoordSystem) returns Vector

Returns the y-axis of a coordinate system

Return typeDescription
Vector

A 3D vector in world space.

toString (cSys is CoordSystem) returns string

Returns a representation of the coordinate system as a string.

curveGeometry

X_AXIS const

The global X axis, equivalent to line(vector(0, 0, 0) * meter, vector(1, 0, 0))

Y_AXIS const

The global Y axis, equivalent to line(vector(0, 0, 0) * meter, vector(0, 1, 0))

Z_AXIS const

The global Z axis, equivalent to line(vector(0, 0, 0) * meter, vector(0, 0, 1))

Line type

Represents a parameterized line in 3D space.

ValueTypeDescription
Line map
  • origin
Vector

A point on the line, as a 3D Vector with length units.

  • direction
Vector

A unitless normalized 3D Vector.

canBeLine (value) predicate

Typecheck for Line

line (origin is Vector, direction is Vector) returns Line

Creates a line from a point and a direction.

ParameterTypeAdditional Info
direction Vector

The direction gets normalized by this function.

tolerantEquals (line1 is Line, line2 is Line) predicate

Check that two Lines are the same up to tolerance, including checking that they have the same origin.

To check if two Lines are equivalent (rather than equal), use collinearLines.

collinearLines (line1 is Line, line2 is Line) returns boolean

Returns true if the two lines are collinear.

transform (from is Line, to is Line) returns Transform

Returns the transformation that transforms the line from to the line to (including the origin) using the minimum rotation angle.

project (line is Line, point is Vector) returns Vector

Returns the projection of the point onto the line. See also other overloads of project.

rotationAround (line is Line, angle is ValueWithUnits) returns Transform

Returns a Transform that represents the rotation around the given line by the given angle. The rotation is counterclockwise looking against the line direction.

LineLineIntersection type

Represents an intersection between two lines. Depending on the lines, this intersection may be a point, a line, or nothing.

ValueTypeDescription
LineLineIntersection map
  • dim
number

Integer representing the dimension of the intersection.

EXAMPLE

0 indicates that intersection is a 3D length Vector.

EXAMPLE

1 indicates that intersection is a Line. (i.e. the lines are collinear)

EXAMPLE

-1 indicates that the intersection does not exist.
  • intersection

undefined or Vector or Line (depending on dim) that represents the intersection.

canBeLineLineIntersection (value) predicate

Typecheck for LineLineIntersection

intersection (line1 is Line, line2 is Line) returns LineLineIntersection

Returns a LineLineIntersection representing the intersection between two lines. If the lines are collinear, line1 will be stored in the intersection field of that LineLineIntersection.

isPointOnLine (point is Vector, line is Line) returns boolean

Returns true if the point lies on the line.

toString (value is Line) returns string

Circle type

Represents a circle in 3D space.

ValueTypeDescription
Circle map
  • coordSystem
CoordSystem

The circle lies in the xy plane of this coordinate system and the origin of its parameterization is the x axis.

  • radius
ValueWithUnits

The radius of the circle.

canBeCircle (value) predicate

Typecheck for Circle

circle (cSys is CoordSystem, radius is ValueWithUnits) returns Circle

Returns a new Circle in the given coordinate system cSys.

circle (center is Vector, xDirection is Vector, normal is Vector, radius is ValueWithUnits) returns Circle

Returns a new Circle with the given parameters. xDirection and normal must be perpendicular.

tolerantEquals (circle1 is Circle, circle2 is Circle) predicate

Check that two Circles are the same up to tolerance, including the coordinate system.

toString (value is Circle) returns string

Ellipse type

Represents an ellipse in 3D space.

ValueTypeDescription
Ellipse map
  • coordSystem
CoordSystem

The ellipse lies in the xy plane of this coordinate system and the x axis corresponds to the major radius.

  • majorRadius
ValueWithUnits

The larger of the two radii.

  • minorRadius
ValueWithUnits

The smaller of the two radii.

canBeEllipse (value) predicate

Typecheck for Ellipse

ellipse (cSys is CoordSystem, majorRadius is ValueWithUnits, minorRadius is ValueWithUnits) returns Ellipse

Returns a new Ellipse with the given parameters.

ellipse (center is Vector, xDirection is Vector, normal is Vector, majorRadius is ValueWithUnits, minorRadius is ValueWithUnits) returns Ellipse

Returns a new Ellipse with the given parameters. xDirection and normal must be perpendicular.

tolerantEquals (ellipse1 is Ellipse, ellipse2 is Ellipse) predicate

Check that two Ellipses are the same up to tolerance, including the coordinate system.

toString (value is Ellipse) returns string

KnotArray type

An array of non-decreasing numbers representing the knots of a spline

canBeKnotArray (value) predicate

Typecheck for KnotArray

knotArray (value is array) returns KnotArray

Cast an array on non-decreasing numbers to a KnotArray

knotArrayIsCorrectSize (knots is KnotArray, degree is number, nControlPoints is number) predicate

Assure that size(knotArray) is 1 + degree + nControlPoints

BSplineCurve type

The definition of a spline in 3D or 2D world space, or unitless 2D parameter space.

See also

bSplineCurve(map)

ValueTypeDescription
BSplineCurve map
  • degree
number

The degree of the spline.

  • dimension
number

The dimension of the spline. Must be 2 or 3.

  • isRational
boolean

Whether the spline is rational.

  • isPeriodic
boolean

Whether the spline is periodic.

  • controlPoints
array

An array of control points of the required dimension. Size should be at least degree + 1. 2D spline control points can have world space units, or be unitless if they are intended to represent locations in parameter space (e.g. as a boundary input to opCreateBSplineSurface).

  • weights
array

Required if isRational is true

An array of unitless values with the same size as the control points array.

  • knots
KnotArray

An array of non-decreasing knots of size equal to 1 + degree + size(controlPoints)

canBeBSplineCurve (value) predicate

Typecheck for BSplineCurve

bSplineCurve (definition is map) returns BSplineCurve

Returns a new BSplineCurve, adding knot padding and control point overlap as necessary.

EXAMPLE

opCreateBSplineCurve(context, id + "bSplineCurve1", {
            "bSplineCurve" : bSplineCurve({
                        "degree" : 2,
                        "isPeriodic" : false,
                        "controlPoints" : [
                                vector(0, 0, 0) * inch,
                                vector(1, 0, 0) * inch,
                                vector(1, 1, 0) * inch,
                                vector(0, 1, 0) * inch],
                        "knots" : knotArray([0, .2, 1]) // Will be padded to [0, 0, 0, .2, 1, 1, 1]
                    })
        });

Creates a spline starting at the origin, moving first quickly along the x-axis (toward the second point), and finishing on the y-axis.

EXAMPLE

opCreateBSplineCurve(context, id + "bSplineCurve1", {
            "bSplineCurve" : bSplineCurve({
                        "degree" : 3,
                        "isPeriodic" : true,
                        "controlPoints" : [
                                vector(0, 0, 0) * inch,
                                vector(1, 0, 0) * inch,
                                vector(1, 1, 0) * inch,
                                vector(0, 1, 0) * inch], // Will be overlapped by repeating the first 3 points
                        "knots" : knotArray([0, .25, .5, .75, 1]) // Same as default when no knots provided. Will be padded to [-.75, -.5, -.25, 0, .25, .5, .75, 1, 1.25, 1.5, 1.75]
                    })
        });

Creates a closed, curvature-continuous, symmetric curve between the four given points.

ParameterTypeAdditional Info
definition map
  • degree
number

The degree of the spline.

  • isPeriodic
boolean

Whether the spline is periodic.

  • controlPoints
array

An array of control points. See BSplineCurve for specific detail. For periodic splines, you may provide the necessary overlap, or provide control points without any overlap. If no overlap is provided, degree overlapping control points (corresponding to the first degree control points) will be added to the end of the control points list (unless you provide a set of knots that show no overlap is necessary).

EXAMPLE

[vector(-1, 1, 0) * inch, vector(1, 1, 0) * inch, vector(1, -1, 0) * inch, vector(-1, -1, 0) * inch]
  • weights
array

Optional

An array of weights. See BSplineCurve for specific detail.

  • knots
KnotArray

Optional

An array of knots. See BSplineCurve for specific detail. If knots are not provided a uniform parameterization wil be created such that the curve exists on the parameter range [0, 1]. For non-periodic curves with n control points, you may provide the full set of n + degree + 1 knots, or you may provide n - degree + 1 knots, and multiplicity will by padded onto the ends (which has the effect of clamping the spline to its two endpoints). For periodic curves with n unique control points (and optionally an additional degree overlapping control points), you may provide the full set of n + 2 * degree + 1 knots, or you may provide n + 1 knots, and the periodic knots will be padded onto the ends.

bSplineCurve (degree is number, isPeriodic is boolean, controlPoints is array, knots is KnotArray) returns BSplineCurve

Deprecated: Use bSplineCurve(map)

bSplineCurve (degree is number, isPeriodic is boolean, controlPoints is array, weights is array, knots is KnotArray) returns BSplineCurve

Deprecated: Use bSplineCurve(map)

math

A module containing many elementary math functions.

Some math functions (such as sin and cos) accept a ValueWithUnits, rather than a number, and are defined in the units module. There is no pow function: exponentiation is done using the ^ operator.

When writing a FeatureScript module which uses only basic math functionality, importing mathUtils (which imports this module along with matrix, transform, and vector) is recommended.

PI const

The mathematical constant pi, to floating-point precision.

EXAMPLE

myAngle = (PI / 4) * radian

In most cases, conversions using PI can be avoided if using ValueWithUnits appropriately. Thus, you should never find yourself writing a statement like sin(myAngle * PI / 180), since myAngle should already have correct units attached.

tolerantEquals (value1 is number, value2 is number) predicate

Returns true if numbers are equal up to a computational tolerance. The tolerance used is a specific number defined by TOLERANCE.computational (set to 1e-13) that is meant to adequately handle tolerances introduced by numerical operations. However, this tolerance may be too restrictive or generous for different situations, in which case tolerantEquals(number, number, number) should be used with the appropriate tolerance specified.

EXAMPLE

tolerantEquals(1, 1) returns true

EXAMPLE

tolerantEquals(1, 1 + 1e-14) returns true

EXAMPLE

tolerantEquals(1, 1 / 900 * 9e100 / 1e98) returns true

EXAMPLE

tolerantEquals(1, 1 / 9 / 9 / 9 / 9 * 9 * 9 * 9 * 9) returns true

See also

tolerantEquals(number, number, number)

tolerantEquals (value1 is number, value2 is number, tolerance is number) predicate

Returns true if numbers are equal up to a specified tolerance.

EXAMPLE

tolerantEquals(1, 1, 0) returns true

EXAMPLE

tolerantEquals(1, 1.01, 0.03) returns true

EXAMPLE

tolerantEquals(1, 0.99, 0.03) returns true

EXAMPLE

tolerantEquals(1, 1.01, 0.01) returns true

EXAMPLE

tolerantEquals(1, 1.03, 0.01) returns false

See also

tolerantEquals(number, number)

abs (value)

Absolute value.

EXAMPLE

abs(-1) returns 1

EXAMPLE

abs(-1.5 * inch) equals 1.5 * inch

sqrt (value is number)

Square root of a number.

EXAMPLE

sqrt(4) returns 2

EXAMPLE

sqrt(-4) throws an error

log (value is number)

Natural logarithm of a number.

EXAMPLE

log(exp(3)) returns 3

EXAMPLE

log(0) returns -inf

EXAMPLE

log(-1) throws an error

log10 (value is number)

Base 10 logarithm of a number.

EXAMPLE

log10(1000) returns 3

EXAMPLE

log10(0) returns -inf

EXAMPLE

log10(-1) throws an error

sinh (value is number)

Hyperbolic sine.

cosh (value is number)

Hyperbolic cosine.

tanh (value is number)

Hyperbolic tangent.

asinh (value is number)

Inverse hyperbolic sine.

acosh (value is number)

Inverse hyperbolic cosine.

atanh (value is number)

Inverse hyperbolic tangent.

exp (value is number)

e to the power of value.

EXAMPLE

exp(1) returns 2.71828...

EXAMPLE

exp(log(3)) returns 3

exp2 (value is number)

2 to the power of value.

EXAMPLE

exp2(10) returns 1024

hypot (a is number, b is number)

Hypotenuse function, as sqrt(a^2 + b^2), but without any surprising results due to finite numeric precision.

EXAMPLE

hypot(3, 4) returns 5

floor (value is number)

Round a number down to the nearest integer.

For values with units, first divide by a value with the same units.

EXAMPLE

floor(1.9) returns 1

EXAMPLE

floor(2.0) returns 2

EXAMPLE

floor(-3.3) returns -4

EXAMPLE

var numberOfBricks is number = floor(wallLength / brickLength);

ceil (value is number)

Round a number up to the nearest integer.

For values with units, first divide by a value with the same units.

EXAMPLE

ceil(1.1) returns 2

EXAMPLE

ceil(1.0) returns 1

EXAMPLE

ceil(-3.3) returns -3

EXAMPLE

var numberOfBricks is number = ceil(wallLength / brickLength)

round (value is number)

Round a number to the nearest integer.

EXAMPLE

round(1.4) returns 1

EXAMPLE

round(1.5) returns 2

EXAMPLE

round(-1.5) returns -1

roundToPrecision (value is number, precision is number)

Round a number to a given number of decimal places.

EXAMPLE

roundToPrecision(0.12345, 3) returns 0.123

EXAMPLE

roundToPrecision(9.9995, 3) returns 10

EXAMPLE

roundToPrecision(123.45, -1) returns 120

For positive values of precision, this method is more accurate than round(value, multiple). For instance, print(roundToPrecision(0.45682, 4)) prints 0.4568, but round(0.45682, 0.0001) prints 0.45680000000000004. This is because the floating point representation of 0.0001 is slightly imprecise, and that imprecision is compounded inside the call to round. The floating point value of 4, on the other hand, is precise, so the result of roundToPrecision will be the closest possible floating-point representation of 0.4568. Thus, print and other functions using string conversion (~) will not print extraneous digits.

min (value1, value2)

Return the lesser of two values, which must be comparable with <.

EXAMPLE

min(0, 1) returns 0

EXAMPLE

min(1 * meter, 1 * inch) equals 1 * inch

max (value1, value2)

Return the greater of two values, which must be comparable with <.

EXAMPLE

max(0, 1) returns 1

EXAMPLE

max(1 * meter, 1 * inch) equals 1 * meter

min (arr is array)

Return the least of an array of values, as determined by operator <, or undefined if the array is empty.

EXAMPLE

min([1, 2, 3]) returns 1

EXAMPLE

min([1 * inch, 2 * inch, 3 * inch]) equals 1 * inch

max (arr is array)

Return the greatest of an array of values, as determined by operator <, or undefined if the array is empty.

EXAMPLE

max([1, 2, 3]) returns 3

EXAMPLE

max([1 * inch, 2 * inch, 3 * inch]) equals 3 * inch

argMin (arr is array)

Return the index of the smallest element of an array, as determined by operator <, or undefined if the array is empty.

EXAMPLE

argMin([1 * inch, 2 * inch, 3 * inch]) returns 0

argMax (arr is array)

Return the index of the largest element of an array, as determined by the > operator, or undefined if the array is empty.

EXAMPLE

argMax([1 * inch, 2 * inch, 3 * inch]) returns 2

range (from is number, to is number)

Return an array of numbers in a range. Only integers are allowed.

EXAMPLE

range(0, 3) returns [0, 1, 2, 3]

range (from, to, count)

Return an array of numbers, (of type number or ValueWithUnits), in a range. Note: before FeatureScript 372 this function received as input the step size instead of the number of steps

EXAMPLE

range(0, 10, 6) returns [0, 2, 4, 6, 8, 10]

EXAMPLE

range(0, 4.5, 4) returns [0, 1.5, 3, 4.5]

EXAMPLE

range(1 * inch, 1.4 * inch, 3) returns [1 * inch, 1.2 * inch, 1.4 * inch]

clamp (value, lowerBound, higherBound)

Force a value into a range,

EXAMPLE

clamp(-1, 0, 20) returns 0,

EXAMPLE

clamp(10, 0, 20) returns 10

EXAMPLE

clamp(30, 0, 20) returns 20

EXAMPLE

clamp(30 * inch, 0 * inch, 20 * inch) equals 20 * inch

isInteger (value) predicate

True if value is a finite integer.

Note that all numbers in FeatureScript represented as floating point numbers, so an expression like isInteger(hugeInteger + 0.1) may still return true.

Used in feature preconditions to define an integer input.

isNonNegativeInteger (value) predicate

True if value is a finite integer greater than or equal to zero.

isPositiveInteger (value) predicate

True if value is a finite integer greater than zero.

mathUtils

This module imports the math, matrix, transform, and vector modules. It is designed to be imported instead of the geometry module in Feature Studios where only math (not higher-level modeling functionality) is needed.

matrix

Matrix type

A Matrix is an array of rows, all the same size, each of which is an array of numbers

canBeMatrix (val) predicate

Typecheck for Matrix

matrixSize (matrix is Matrix) returns array

Return a 2 element array containing the numbers of rows and columns of a matrix.

isSquare (matrix is Matrix) predicate

Check whether a matrix is square.

matrix (value is array) returns Matrix

Cast a two-dimensional array to a matrix.

identityMatrix (size is number) returns Matrix

Construct an identity matrix of a given dimension.

zeroMatrix (rows is number, cols is number) returns Matrix

Construct an all-zero matrix of a given dimension.

diagonalMatrix (diagonalValues is array) returns Matrix

Given an array of diagonalValues of size n, construct an nxn matrix which has those values along its main diagonal (starting in the top-left), and 0 everywhere else.

cwiseProduct (m1 is Matrix, m2 is Matrix) returns Matrix

Construct a matrix by multiplying corresponding elements of two matrices (which must be the same size).

transpose (m is Matrix) returns Matrix

Return the transpose of a matrix.

inverse (m is Matrix) returns Matrix

Compute the inverse of a matrix. Throws an exception if the matrix is not square. If the matrix is singular the resulting matrix will contain infinities.

squaredNorm (m is Matrix) returns number

Return the sum of the squares of matrix elements.

norm (m is Matrix) returns number

Return the square root of the sum of the squares of matrix elements.

svd (m is Matrix) returns map

Compute the singular value decomposition of a matrix, i.e. s, u, and v, where m == u * s * transpose(v) and s is a diagonal matrix of singular values.

ParameterTypeAdditional Info
m Matrix

an n-by-p matrix.

ReturnTypeDescription
map
  • u
Matrix

An n-by-n unitary matrix

  • s
Matrix

An n-by-p diagonal matrix

  • v
Matrix

A p-by-p unitary matrix

determinant (m is Matrix) returns number

Return the determinant of the matrix.

toString (value is Matrix) returns string

matrixWithUnits

MatrixWithUnits type

A MatrixWithUnits is analogous to ValueWithUnits, but wrapping a matrix.

canBeMatrixWithUnits (value) predicate

Typecheck for MatrixWithUnits

get (matrix is MatrixWithUnits, i is number, j is number) returns ValueWithUnits

Gets an element of a MatrixWithUnits, returning a ValueWithUnits.

matrixSize (matrix is MatrixWithUnits) returns array

Return a 2-element array containing the numbers of rows and columns of a matrix.

toString (value is MatrixWithUnits) returns string

nurbsUtils

removeKnots (points is array, knots is array, curveDegree is number) returns map

Remove as many knots as possible from a NURBS defined by points, knots and curveDegree.

separatePointsAndWeights (points is array) returns map

Separates a 4d array containing weighted points into a 3d unweighted points array and a 1d weights array.

combinePointsAndWeights (points is array, weights is array) returns array

Combines a 3d unweighted points array and a 1d weights array into a 4d weighted points array

persistentCoordSystem

PersistentCoordSystem type

A coordinate system that can persist as part of an attribute associated with an entity. This coordinate system will be transformed along with its parent entity as that entity undergoes transformations.

As with other attributes, the coordinate system will be propagated to copied entities, such as instances in a pattern. These copied persistent coordinate systems will take on the transforms of their new parents.

When getAttribute is used to retrieve a previously-set persistent coordinate system, the value of coordSystem will be in its transformed state for the current point in the feature execution. If a transform is applied such that the coordinate system is know longer right-handed, then the coordSystem value will be undefined. For instance, this would happen in the case of a mirrored coordinate system.

ValueTypeDescription
PersistentCoordSystem map
  • coordSystem
CoordSystem

The coordinate system to persist

  • coordSystemId
string

An id to associate with the coordinate system. This id must be unique within the context of the parent entity.

persistentCoordSystem (coordSystem is CoordSystem, coordSystemId is string) returns PersistentCoordSystem

Creates a persistent coordinate system.

See also

PersistentCoordSystem

ParameterTypeAdditional Info
coordSystem CoordSystem

The coordinate system

coordSystemId string

An id with which to associate the coordinate system. This id must be unique within the context of the parent entity that an becomes associated with this persistent coordinate system through setAttribute.

splineUtils

ApproximationTarget type

A set of points and optionally derivatives to approximate by a spline.

See also

approximateSpline(Context, map)

ValueTypeDescription
ApproximationTarget map
  • positions
array

An ordered array of points for the spline to pass closely to.

  • startDerivative
Vector

Required if start2ndDerivative is provided

The desired start derivative of the spline.

  • start2ndDerivative
Vector

Optional

The desired start second derivative of the spline.

  • endDerivative
Vector

Required if end2ndDerivative is provided

The desired end derivative of the spline.

  • end2ndDerivative
Vector

Optional

The desired end second derivative of the spline.

canBeApproximationTarget (value) predicate

Typecheck for ApproximationTarget

approximationTarget (value is map) returns ApproximationTarget

Construct an ApproximationTarget

approximateSpline (context is Context, definition is map) returns array

Compute a family of splines that approximates a family of ApproximationTargets to within a given tolerance. The resulting splines are consistently parameterized, so that, for example, lofting between them will match corresponding target positions. Note: If parameters are not specified, the magnitude of start and end derivatives in targets is ignored as well as the second component parallel with the first derivative.

ParameterTypeAdditional Info
definition map
  • degree
number

The desired degree of the curve. The output may have a different degree, if for example there aren't enough points.

  • tolerance
ValueWithUnits

How far the output is allowed to deviate from the input. Must be at least 1e-8 meters.

  • isPeriodic
boolean

Whether the output spline is periodic.

  • targets
array

An array of ApproximationTargets. All targets must have the same number of positions and specify corresponding derivative information.

  • parameters
array

Optional

An array of numbers representing the parameters corresponding to the target points. Must be strictly increasing. If specified, the output spline at those parameters will match the target points. If specified, derivatives in approximation targets will not be rescaled.

  • maxControlPoints
number

Optional

The maximum number of control points that will be returned by this function's output. Tolerance will not be satisfied if this limit is reached. Default is 10000.

  • interpolateIndices
array

Optional

An array of indices into target positions that specifies which ones are to be interpolated exactly. This is currently supported only for non-periodic splines.

  • suppressInterpolationNotice
boolean

Optional

Don't report an info if the result is fully interpolated. Default is false.

Return typeDescription
array

An array of BSplineCurves, one for each target.

evaluateSpline (definition is map) returns array

Evaluate a 3D spline at several parameters, possibly with derivatives.

ParameterTypeAdditional Info
definition map
  • spline
BSplineCurve

The 3D spline to evaluate.

  • parameters
array

An array of numbers in the range of the spline's knot vector.

  • nDerivatives
number

Optional

The number of derivatives to compute, in addition to the positions. Default is 0.

Return typeDescription
array

An array of arrays of points. If result is returned, result[i][j] is the ith derivative at jth parameter.

elevateBezierDegree (pointsIn is array, newDegree is number) returns array

Elevate the degree of a bezier curve defined by an array of control points

ParameterTypeAdditional Info
pointsIn array

The control points of the curve to be elevated. Must be non-empty.

newDegree number

The desired degree. If it is less than the number of control points, the control points will be returned unchanged.

Return typeDescription
array

The control points of the degree-elevated curve

surfaceGeometry

This module contains methods for creating and working with primitive surfaces: planes, cylinders, cones, spheres, and tori.

XY_PLANE const

The world XY plane, equivalent to plane(vector(0, 0, 0) * meter, vector(0, 0, 1), vector(1, 0, 0))

YZ_PLANE const

The world YZ plane, equivalent to plane(vector(0, 0, 0) * meter, vector(1, 0, 0), vector(0, 1, 0))

XZ_PLANE const

The world XZ plane, equivalent to plane(vector(0, 0, 0) * meter, vector(0, 1, 0), vector(0, 0, 1))

Plane type

A Plane is a data type representing an origin, a normal vector, and an X direction, perpendicular to the normal direction.

ValueTypeDescription
Plane map
  • origin
Vector

A 3D point, in world space.

  • normal
Vector

A 3D unit vector in world space.

  • x
Vector

A 3D unit vector in world space. Must be perpendicular to normal.

canBePlane (value) predicate

Typecheck for Plane

plane (cSys is CoordSystem) returns Plane

Create a Plane on the XY plane of a specified coordinate system.

plane (origin is Vector, normal is Vector, x is Vector) returns Plane

Create a Plane which fully specifies its orientation.

ParameterTypeAdditional Info
origin Vector

A 3D point in world space.

normal Vector

A 3D vector in world space. Need not be normalized.

x Vector

A 3D vector in world space. Need not be normalized.

plane (origin is Vector, normal is Vector) returns Plane

Create a Plane from a point and a normal.

The x-axis of this Plane's coordinate system will be an arbitrary vector perpendicular to the normal.

ParameterTypeAdditional Info
origin Vector

A 3D point in world space.

normal Vector

A 3D vector in world space. Need not be normalized.

alignCanonically (context is Context, plane is Plane) returns Plane

Returns the plane that would represent the coordinate system of a face coplanar with the input plane. Used in plane transformation for computing sketch patterns.

yAxis (plane is Plane) returns Vector

Returns the y-axis of the specified plane as a 3D Vector in world space.

tolerantEquals (plane1 is Plane, plane2 is Plane) predicate

Check that two Planes are the same up to tolerance, including checking that they have the same the origin and local coordinate system.

To check if two Planes are equivalent (rather than equal), use coplanarPlanes.

coplanarPlanes (plane1 is Plane, plane2 is Plane) returns boolean

Returns true if the two planes are coplanar.

planeToCSys (plane is Plane) returns CoordSystem

Create a coordinate system whose XY-plane is a specified plane, with its origin at the plane's origin.

coordSystem (plane is Plane) returns CoordSystem

Create a coordinate system whose XY-plane is a specified plane, with its origin at the plane's origin.

Alias for planeToCSys.

toString (value is Plane) returns string

project (plane is Plane, point is Vector) returns Vector

Projects a 3D point onto a Plane, returning a 3D point on the plane.

project (plane is Plane, line is Line) returns Line

Projects a Line onto a Plane, returning a Line whose origin is on the Plane and whose direction is a normalized Vector on the Plane

Throws an error if the Line is in the same direction as the normal of the Plane

planeToWorld (plane is Plane, planePoint is Vector) returns Vector

Transforms a 2D point in a Plane's coordinates to its corresponding 3D point in world coordinates.

planeToWorld3D (plane is Plane) returns Transform

Returns a Transform which takes 3D points measured with respect to a Plane (such that points which lie on the plane will have a z-coordinate of approximately 0) and transforms them into world coordinates.

worldToPlane3D (plane is Plane, worldPoint is Vector) returns Vector

Transforms a 3D point in world coordinates into a 3D point measured in a Plane's coordinates. If the point lies on the Plane, the result will have a z-coordinate of approximately 0.

worldToPlane (plane is Plane, worldPoint is Vector) returns Vector

Transforms a 3D worldPoint in world coordinates into a 2D point measured in a Plane's (x,y) coordinates.

This is modified as of FeatureScript version 363.0. Older versions of FeatureScript use worldToPlane to return 3D vectors composed of the plane coordinate system baseis. This functionality is still available in the worldToPlane function above.

worldToPlane3D (plane is Plane) returns Transform

Returns a Transform which takes 3D points measured in world coordinates and transforms them into 3D points measured in plane coordinates (such that points which lie on the plane will have a z-coordinate of approximately 0).

transform (from is Plane, to is Plane) returns Transform

Returns a Transform which maps the plane from to the plane to.

mirrorAcross (plane is Plane) returns Transform

Returns a Transform which takes points on one side of a plane and transforms them to the other side. The resulting transform is non-rigid, and using this transform in an opTransform or similar operations will invert the transformed bodies.

intersection (plane1 is Plane, plane2 is Plane)

Returns a Line at the intersection between the two Planes. If the planes are parallel or coincident, returns undefined.

LinePlaneIntersection type

Represents an intersection between a line and a plane. Depending on the line and plane, this intersection may be a point, a line, or nothing.

ValueTypeDescription
LinePlaneIntersection map
  • dim
number

Integer representing the dimension of the intersection.

EXAMPLE

0 indicates that intersection is a 3D length Vector.

EXAMPLE

1 indicates that intersection is a Line.

EXAMPLE

-1 indicates that the intersection does not exist (i.e. the line and the plane are parallel).
  • intersection

undefined or Vector or Line (depending on dim) that represents the intersection.

canBeLinePlaneIntersection (value) predicate

Typecheck for LinePlaneIntersection

intersection (plane is Plane, line is Line) returns LinePlaneIntersection

Returns a LinePlaneIntersection representing the intersection between line and plane.

isPointOnPlane (point is Vector, plane is Plane) returns boolean

Returns true if the point lies on the plane.

flip (plane is Plane) returns Plane

Returns a Plane with the reversed normal vector.

Cone type

Type representing a cone which extends infinitely down the positive z-axis of its coordSystem.

ValueTypeDescription
Cone map
  • coordSystem
CoordSystem

The position and orientation of the cone.

  • halfAngle
ValueWithUnits

The angle from z-axis of coordSystem to the surface of the cone.

canBeCone (value) predicate

Typecheck for Cone

cone (cSys is CoordSystem, halfAngle is ValueWithUnits) returns Cone

Constructs a Cone from a coordinate system and a half angle.

tolerantEquals (cone1 is Cone, cone2 is Cone) predicate

Check that two Cones are the same up to tolerance, including the local coordinate system.

toString (value is Cone) returns string

Cylinder type

Type representing a Cylinder which extends infinitely along the z-axis of its coordSystem.

ValueTypeDescription
Cylinder map
  • coordSystem
CoordSystem

The position and orientation of the cylinder.

  • radius
ValueWithUnits

The cylinder's radius.

canBeCylinder (value) predicate

Typecheck for Cylinder

cylinder (cSys is CoordSystem, radius is ValueWithUnits) returns Cylinder

Constructs a cylinder from a coordinate system and a radius.

tolerantEquals (cylinder1 is Cylinder, cylinder2 is Cylinder) predicate

Check that two Cylinders are the same up to tolerance, including the local coordinate system.

toString (value is Cylinder) returns string

Torus type

Type representing a torus, the shape of a circle revolved around a coplanar axis.

The torus represented is revolved about the z-axis of the coordSystem and centered in its xy-plane.

ValueTypeDescription
Torus map
  • coordSystem
CoordSystem

The position and orientation of the torus.

  • radius
ValueWithUnits

The major radius, i.e. the distance from the center of the torus to the center of the revolved circle.

  • minorRadius
ValueWithUnits

The minor radius, i.e. the radius of the revolved circle.

canBeTorus (value) predicate

Typecheck for Torus

torus (cSys is CoordSystem, minorRadius is ValueWithUnits, radius is ValueWithUnits) returns Torus

Constructs a torus from a coordinate system, the minor radius, and the major radius.

tolerantEquals (torus1 is Torus, torus2 is Torus) predicate

Check that two tori are the same up to tolerance, including the local coordinate system.

toString (value is Torus) returns string

Sphere type

Type representing a sphere of a given radius centered around a 3D point.

ValueTypeDescription
Sphere map
  • coordSystem
CoordSystem

The position and orientation of the sphere.

  • radius
ValueWithUnits

The sphere's radius.

canBeSphere (value) predicate

Typecheck for Sphere

sphere (cSys is CoordSystem, radius is ValueWithUnits) returns Sphere

tolerantEquals (sphere1 is Sphere, sphere2 is Sphere) predicate

Check that two Spheres are the same up to tolerance, including the local coordinate system.

toString (value is Sphere) returns string

ControlPointMatrix type

A two-dimensional array of 3D position vectors. Reading across a row represents a change in v, and reading down a column represents a change in u.

canBeControlPointMatrix (value) predicate

Typecheck for ControlPointMatrix

controlPointMatrix (value is array) returns ControlPointMatrix

Cast a two-dimensional array of 3D position vectors to a ControlPointMatrix.

BSplineSurface type

The definition of a spline in 3D space. For all matrices of the spline definition, reading across a row represents a change in v, and reading down a column represents a change in u.

See also

bSplineSurface

ValueTypeDescription
BSplineSurface map
  • uDegree
number

The degree of the spline in u.

  • vDegree
number

The degree of the spline in v.

  • isRational
boolean

Whether the spline is rational.

  • isUPeriodic
boolean

Whether the spline periodic in u.

  • isVPeriodic
boolean

Whether the spline periodic in v.

  • controlPoints
ControlPointMatrix

A grid of 3d control points. Must have at least uDegree + 1 rows and vDegree + 1 columns.

  • weights
Matrix

Required if rational is true

A matrix of unitless values with the same shape as the control points grid.

  • uKnots
KnotArray

An array of non-decreasing knots of size equal to 1 + uDegree + number of rows in controlPoints

  • vKnots
KnotArray

An array of non-decreasing knots of size equal to 1 + vDegree + number of columns in controlPoints

canBeBSplineSurface (value) predicate

Typecheck for BSplineSurface

bSplineSurface (definition is map)

Returns a new BSplineSurface, adding knot padding and control point overlap as necessary.

EXAMPLE

opCreateBSplineSurface(context, id + "bSplineSurface1", {
            "bSplineSurface" : bSplineSurface({
                        "uDegree" : 2,
                        "vDegree" : 2,
                        "isUPeriodic" : false,
                        "isVPeriodic" : false,
                        "controlPoints" : controlPointMatrix([
                                    [vector(-2,  2, 0) * inch, vector(-1,  2, 0) * inch, vector(0,  2, 0) * inch, vector(1,  2, 0) * inch, vector(2,  2, 0) * inch],
                                    [vector(-2,  1, 0) * inch, vector(-1,  1, 0) * inch, vector(0,  1, 0) * inch, vector(1,  1, 0) * inch, vector(2,  1, 0) * inch],
                                    [vector(-2,  0, 0) * inch, vector(-1,  0, 0) * inch, vector(0,  0, 1) * inch, vector(1,  0, 0) * inch, vector(2,  0, 0) * inch],
                                    [vector(-2, -2, 0) * inch, vector(-1, -2, 0) * inch, vector(0, -2, 0) * inch, vector(1, -2, 0) * inch, vector(2, -2, 0) * inch]
                                ]),
                        "uKnots" : knotArray([0, .1, 1]), // Will be padded to [0, 0, 0, .1, 1, 1, 1]
                        "vKnots" : knotArray([0, 1/3, 2/3, 1]) // Same as default when no knots provided.  Will be padded to [0, 0, 0, 1/3, 2/3, 1, 1, 1]
                    })
        });

Creates a new spline surface on the XY plane with a protrusion at the origin, falling back to the XY plane more quickly in the +Y direction.

EXAMPLE

opCreateBSplineSurface(context, id + "bSplineSurface1", {
            "bSplineSurface" : bSplineSurface({
                        "uDegree" : 2,
                        "vDegree" : 1,
                        "isUPeriodic" : true,
                        "isVPeriodic" : false,
                        "controlPoints" : controlPointMatrix([
                                    [vector(0,  0, 1) * inch, vector(-1,  0, 0) * inch, vector(-2,  0, -1) * inch],
                                    [vector(1,  1, 1) * inch, vector( 0,  1, 0) * inch, vector(-1,  1, -1) * inch],
                                    [vector(2,  0, 1) * inch, vector( 1,  0, 0) * inch, vector( 0,  0, -1) * inch],
                                    [vector(1, -1, 1) * inch, vector( 0, -1, 0) * inch, vector(-1, -1, -1) * inch]
                                    // Will be overlapped by repeating the first two rows
                                ]),
                        "uKnots" : knotArray([0, .25, .5, .75, 1]), // Same as default when no knots provided. Will be padded to [-.5, -.25, 0, .25, .5, .75, 1, 1.25, 1.5]
                        "vKnots" : knotArray([0, .5, 1]) // Same as default when no knots provided.  Will be padded to [0, 0, .5, 1, 1]
                    })
        });

Creates a new spline surface which is a tube surrounding the origin, sheared in the X direction.

ParameterTypeAdditional Info
definition map
  • uDegree
number

The degree of the spline in u.

  • vDegree
number

The degree of the spline in v.

  • isUPeriodic
boolean

Whether the spline periodic in u.

  • isVPeriodic
boolean

Whether the spline periodic in v.

  • controlPoints
ControlPointMatrix

A matrix of control points. See BSplineSurface for specific detail. If u or v is periodic, you may provide the necessary overlap, or provide control points without any overlap. If no overlap is provided, degree overlapping control point rows or columns (corresponding to the first degree control point rows or columns) will be added. (unless you provide a set of knots that show no overlap is necessary).

EXAMPLE

controlPointMatrix([
    [vector(-1, -1, -1) * inch, vector(-1, 0, 0) * inch, vector(-1, -2, 1) * inch],
    [vector( 0,  1, -1) * inch, vector( 0, 2, 0) * inch, vector( 0,  0, 1) * inch],
    [vector( 1, -1, -1) * inch, vector( 1, 0, 0) * inch, vector( 1, -2, 1) * inch]
])
  • weights
array

Optional

A matrix of weights. See BSplineSurface for specific detail.

  • uKnots
KnotArray

Optional

An array of knots. See BSplineSurface for specific detail. If knots are not provided a uniform parameterization will be created such that the u parameterization exists on the range [0, 1]. For non-periodic u with n control point rows, you may provide the full set of n + degree + 1 knots, or you may provide n - degree + 1 knots, and multiplicity will by padded onto the ends (which has the effect of clamping the surface to the control points in the first and last rows). For periodic u with n unique control points (and optionally an additional degree overlapping control points), you may provide the full set of n + 2 * degree + 1 knots, or you may provide n + 1 knots, and the periodic knots will be padded onto the ends.

  • vKnots
KnotArray

Optional

See uKnots.

MeshFaceParameter type

A MeshFaceParameter is a 2D array unitless array. It is functionnally indentical to a 2D vector but because there is no guarantee of continuity for mesh parameters, it does not make sense to expose vector math for it.

canBeMeshFaceParameter (value) predicate

Typecheck for MeshFaceParameter

meshFaceParameter (value is array) returns MeshFaceParameter

Make a MeshFaceParameter from an array.

transform

Transform type

A Transform typically represents a change of position and orientation in 3D space (other affine transformations, such as scaling and shearing, can also be represented).

rotationAround, scaleUniformly, transform(Vector), toWorld(CoordSystem) and fromWorld(CoordSystem) return useful transforms. Transforms are commonly used with opTransform, whose documentation has examples of calling these functions.

Transforms are also commonly used with their * operator overloads to easily work with geometry in multiple coordinate systems.

EXAMPLE

transform * (vector(1, 1, 1) * inch) yields a point which is the given point, transformed by the transform.

EXAMPLE

transform2 * transform1 yields a new transform which is equivalent to applying transform1 followed by transform2.

A Transform contains a linear portion (rotation, scaling, or shearing), which is applied first, and a translation vector, which is applied second. Generally, these individual fields on this type don't need to be directly used, and everything you need can be accomplished through the operator overloads above, or other functions in this module and the coordSystem module.

ValueTypeDescription
Transform map
  • linear
Matrix

A linear motion, which is generally a rotation, but can also be a scaling, inversion, or shearing.

  • translation
Vector

A 3D translation vector.

canBeTransform (value) predicate

Typecheck for Transform

transform (linear is Matrix, translation is Vector) returns Transform

Construct a Transform using the matrix argument for rotation and scaling and the vector argument for translation.

transform (translation is Vector) returns Transform

Construct a Transform that translates without rotation or scaling.

transform (value is map) returns Transform

identityTransform () returns Transform

Construct a transform that does nothing (no rotation, scaling, or translation).

tolerantEquals (transform1 is Transform, transform2 is Transform) predicate

Check that two Transforms are the same up to tolerance.

inverse (t is Transform) returns Transform

Compute the inverse of a Transform, such that inverse(t) * t == identityTransform().

scaleUniformly (scale is number) returns Transform

Returns a Transform that represents a uniform scaling around the origin.

scaleUniformly (scale is number, pointToScaleAbout is Vector) returns Transform

Returns a Transform that represents a uniform scaling around pointToScaleAbout.

scaleNonuniformly (xScale is number, yScale is number, zScale is number) returns Transform

Returns a Transform that represents 3 independent scalings along the X, Y, and Z axes, centered around the origin.

scaleNonuniformly (xScale is number, yScale is number, zScale is number, pointToScaleAbout is Vector) returns Transform

Returns a Transform that represents 3 independent scalings along the X, Y, and Z axes, centered around pointToScaleAbout.

transformUV

TransformUV type

A TransformUV represents a change of position and orientation in unitless 2D space.

A TransformUV contains a linear portion (rotation, scaling, or shearing), which is applied first, and a translation vector, which is applied second.

ValueTypeDescription
TransformUV map
  • linear
Matrix

A linear motion, which is generally a rotation, but can also be a scaling, inversion, or shearing.

  • translation
Vector

A 2D translation vector.

isUvVector (value) predicate

True for a single 2D unitless Vector

EXAMPLE

vector(0.5, 1)

canBeTransformUV (value) predicate

Typecheck for Transform

transformUV (linear is Matrix, translation is Vector) returns TransformUV

Construct a TransformUV using the matrix argument for rotation and scaling and the vector argument for translation.

transformUV (translation is Vector) returns TransformUV

Construct a TransformUV that translates without rotation or scaling.

transformUV (value is map) returns TransformUV

identityTransformUV () returns TransformUV

Construct a transform that does nothing (no rotation, scaling, or translation).

tolerantEquals (transform1 is TransformUV, transform2 is TransformUV) predicate

Check that two TransformUVs are the same up to tolerance.

inverse (t is TransformUV) returns TransformUV

Compute the inverse of a TransformUV, such that inverse(t) * t == identityTransform().

scaleUniformlyUV (scale is number) returns TransformUV

Returns a TransformUV that represents a uniform scaling around the origin.

scaleNonuniformly (xScale is number, yScale is number) returns TransformUV

Returns a TransformUV that represents two independent scalings along the X and Y axes, centered around the origin.

rotate (angle is ValueWithUnits) returns TransformUV

Returns a TransformUV that represents a rotation around the origin with the given angle.

units

ValueWithUnits type

A ValueWithUnits is a number with dimensions, such as 1.5 inches, 90 degrees, or 9.81 meters per second per second.

const width is ValueWithUnits = 1.5 * inch;
const angle is ValueWithUnits = 90 * degree;
const g     is ValueWithUnits = 9.81 * meter / second / second;

Values with the same dimensions can be added and subtracted, even if they were created in different unit systems.

const length       = 3 * meter + 1 * inch;
const longerLength = length + 0.01 * inch;
const nonsense     = 3 * meter + 3 * degree;     // Throws an error from dimension mismatch

Multiplication (*) will multiply both the values and the units. An expression where the units all cancel evaluates to plain number.

var doubleLength   = 2 * length;                 // ValueWithUnits with length units
var area           = (20 * foot) * (30 * foot);  // ValueWithUnits with area units
var numberOfBricks = (64 * foot) / (9 * inch);   // number with no units

Values with units can be raised to numerical powers with the ^ operator. Base units like inch or second can be exponentiated in the same way.

var squareArea   = (3 * meter)^2;
var g            = 9.81 * meter / second^2;

Functions in the standard library require a ValueWithUnits for arguments where units are needed. Thus, the depth in opExtrude requires a value with length units (rather than assuming meters). The argument of sin is a value with angle units (rather than assuming radians). The argument of sqrt can be any value whose units are even powers.

var ladderHeight   = ladderLength * sin(75 * degree); // Has length units
var pendulumPeriod = 2 * PI * sqrt(armLength / g);    // Has time units

Equality of ValueWithUnits considers the underlying value, so 25.4 * millimeter is equal to 1 * inch. However, PI * radian / 5 does not equal 36 * degree because of finite precision arithmetic. To check equality of ValueWithUnits, you should use tolerantEquals.

if (tolerantEquals(myLength, 0 * inch))
{
    ...

Keeping correct units on variables is always best practice, in order to benefit from easy unit conversions and runtime unit checks. However, when printing, you may wish to divide out the units in order to display a value in a different system of units.

const length = 42 * centimeter;
println(length);                                 // prints "0.42 meter"
println("length: " ~ toString(length));          // prints "length: 0.42 meter"
println(length / inch ~ " inches");              // prints "16.535433070866137 inches"
println(roundToPrecision(length / inch, 3) ~ " inches"); // prints "16.535 inches"

unitless const

The constant 1, with no units.

meter const

A constant equal to 1 meter.

centimeter const

A constant equal to 1 centimeter.

millimeter const

A constant equal to 1 millimeter.

inch const

A constant equal to 1 inch.

A constant equal to 1 foot.

yard const

A constant equal to 1 yard.

squareMeter const

A constant equal to one square meter.

squareCentimeter const

A constant equal to one square centimeter.

squareMillimeter const

A constant equal to one square millimeter.

squareInch const

A constant equal to one square inch.

squareFoot const

A constant equal to one square foot.

squareYard const

A constant equal to one square yard.

cubicMeter const

A constant equal to one cubic meter.

cubicCentimeter const

A constant equal to one cubic centimeter.

cubicMillimeter const

A constant equal to one cubic millimeter.

cubicInch const

A constant equal to one cubic inch.

cubicFoot const

A constant equal to one cubic foot.

cubicYard const

A constant equal to one cubic yard.

radian const

A constant equal to 1 radian.

Formally, radians are unitless, so in certain situations you may need to multiply or divide by radian

EXAMPLE

var myAngle = PI / 6 * radian

EXAMPLE

var arcLength = radius * arcAngle / radian

degree const

A constant equal to 1 degree.

kilogram const

A constant equal to 1 kilogram.

gram const

A constant equal to 1 gram.

ounce const

A constant equal to 1 ounce.

pound const

A constant equal to 1 pound.

second const

A constant equal to 1 second

newton const

A constant equal to 1 newton.

kilonewton const

A constant equal to 1 kilonewton.

poundForce const

A constant equal to 1 pound-force.

pascal const

A constant equal to 1 pascal.

kilopascal const

A constant equal to 1 kilopascal.

megapascal const

A constant equal to 1 megapascal.

gigapascal const

A constant equal to 1 gigapascal.

poundPerSquareInch const

A constant equal to 1 pound per square inch.

kilopoundPerSquareInch const

A constant equal to 1 ksi.

newtonMeter const

A constant equal to 1 newton-meter.

newtonMillimeter const

A constant equal to 1 newton-millimeter.

inchPound const

A constant equal to 1 inch-pound.

footPound const

A constant equal to 1 foot-pound.

meterPerSecondSquared const

A constant equal to 1 meter per second squared.

millimeterPerSecondSquared const

A constant equal to 1 millimeter per second squared.

inchPerSecondSquared const

A constant equal to 1 inch per second squared.

footPerSecondSquared const

A constant equal to 1 foot per second squared.

radianPerSecond const

A constant equal to 1 radian per second.

degreePerSecond const

A constant equal to 1 degree per second.

joule const

A constant equal to 1 Joule.

footPoundForce const

A constant equal to 1 foot-pound force.

isLength (val) predicate

True for any value with length units.

isArea (val) predicate

True for any value with area units.

isVolume (val) predicate

True for any value with volume units.

isAngle (val) predicate

True for any value with angle units.

isForce (val) predicate

True for any value with force units.

isPressure (val) predicate

True for any value with pressure units.

isMoment (val) predicate

True for any value with moment units.

isAcceleration (val) predicate

True for any value with acceleration units.

isAngularVelocity (val) predicate

True for any value with angular velocity units.

isEnergy (val) predicate

True for any value with energy units.

reciprocal (val is ValueWithUnits) returns ValueWithUnits

Inverts a value, including units.

tolerantEquals (value1 is ValueWithUnits, value2 is ValueWithUnits) predicate

Returns true if angles are equal up to zeroAngle or anything else is equal up to zeroLength

tolerantGreaterThan (greater, lesser) predicate

Returns true if greater is greater than and not tolerantly equal to lesser.

EXAMPLE

(1 * meter)->tolerantGreaterThan(0 * meter) returns true

EXAMPLE

1->tolerantGreaterThan(0) returns true

EXAMPLE

0->tolerantGreaterThan(-1e-14) returns false

EXAMPLE

0->tolerantGreaterThan(0) returns false

tolerantGreaterThanOrEqual (greater, lesser) predicate

Returns true if greater is greater than or tolerantly equal to lesser.

EXAMPLE

(1 * meter)->tolerantGreaterThanOrEqual(0 * meter) returns true

EXAMPLE

1->tolerantGreaterThanOrEqual(0) returns true

EXAMPLE

0->tolerantGreaterThanOrEqual(0) returns true

EXAMPLE

0->tolerantGreaterThanOrEqual(1e-14) returns true

tolerantLessThan (lesser, greater) predicate

Returns true if lesser is less than and not tolerantly equal to greater.

EXAMPLE

(0 * meter)->tolerantLessThan(1 * meter) returns true

EXAMPLE

0->tolerantLessThan(1) returns true

EXAMPLE

0->tolerantLessThan(1e-14) returns false

EXAMPLE

0->tolerantLessThan(0) returns false

tolerantLessThanOrEqual (lesser, greater) predicate

Returns true if lesser is less than or tolerantly equal to greater.

EXAMPLE

(0 * meter)->tolerantLessThanOrEqual(1 * meter) returns true

EXAMPLE

0->tolerantLessThanOrEqual(1) returns true

EXAMPLE

0->tolerantLessThanOrEqual(0) returns true

EXAMPLE

1e-14->tolerantLessThanOrEqual(0) returns true

tolerantWithinExclusive (value, lesser, greater) predicate

Returns true if value is tolerantly within the interval (lesser, greater).

EXAMPLE

(0.5 * meter)->tolerantWithinExclusive(0 * meter, 1 * meter) returns true

EXAMPLE

0.5->tolerantWithinExclusive(0, 1) returns true

EXAMPLE

1->tolerantWithinExclusive(0, 1) returns false

EXAMPLE

0->tolerantWithinExclusive(0, 1) returns false

EXAMPLE

0->tolerantWithinExclusive(1e-14, 1) returns false

tolerantWithinInclusive (value, lesser, greater) predicate

Returns true if value is tolerantly within the interval [lesser, greater].

EXAMPLE

(0.5 * meter)->tolerantWithinInclusive(0 * meter, 1 * meter) returns true

EXAMPLE

0.5->tolerantWithinInclusive(0, 1) returns true

EXAMPLE

1->tolerantWithinInclusive(0, 1) returns true

EXAMPLE

0->tolerantWithinInclusive(0, 1) returns true

EXAMPLE

0->tolerantWithinInclusive(1e-14, 1) returns true

tolerantEqualsZero (value) predicate

Returns true if value is tolerantly equal to the 0 value with the same units as value.

EXAMPLE

tolerantEqualsZero(0) returns true

EXAMPLE

tolerantEqualsZero(0 * meter) returns true

EXAMPLE

tolerantEqualsZero(1e-9 * meter) returns true

EXAMPLE

tolerantEqualsZero(1) returns false

EXAMPLE

tolerantEqualsZero(1 * meter) returns false

sqrt (value is ValueWithUnits) returns ValueWithUnits

Square root of a ValueWithUnits.

EXAMPLE

sqrt(4 * meter^2) equals 2 * meter.

EXAMPLE

2 * PI * sqrt(armLength / (9.8 * meter/second^2)) equals the period of a pendulum, in seconds.

EXAMPLE

sqrt(4 * meter) throws an error, since FeatureScript has no concept of the square root of a meter.

hypot (a is ValueWithUnits, b is ValueWithUnits)

Hypotenuse function, as sqrt(a^2 + b^2), but without any surprising results due to finite numeric precision.

EXAMPLE

hypot(3 * foot, 4 * foot) equals 5 * foot

sin (value is ValueWithUnits) returns number

Sine, the ratio of the opposite side over the hypotenuse in a right triangle of the specified angle.

EXAMPLE

sin(30 * degree) returns approximately 0.5

EXAMPLE

sin(PI * radian) returns approximately 0

cos (value is ValueWithUnits) returns number

Cosine, the ratio of the adjacent side over the hypotenuse in a right triangle of the specified angle.

EXAMPLE

cos(60 * degree) returns approximately 0.5

EXAMPLE

cos(PI * radian) returns approximately -1

tan (value is ValueWithUnits) returns number

Tangent, the ratio of the opposite side over the adjacent side in a right triangle of the specified angle.

EXAMPLE

tan(45 * degree) returns approximately 1

EXAMPLE

tan(PI * radian) returns approximately 0

asin (value is number) returns ValueWithUnits

Arcsine, i.e. inverse sine.

Returns a value between -90 * degree and 90 * degree.

EXAMPLE

asin(0.5) equals approximately 30 * degree

EXAMPLE

asin(1.5) throws an error, since there is no value where sin(value) is 1.5

acos (value is number) returns ValueWithUnits

Arccosine, i.e. inverse cosine.

Returns a value between 0 * degree and 180 * degree.

EXAMPLE

acos(0.5) equals approximately 60 * degree

EXAMPLE

acos(1.5) throws an error, since there is no value where cos(value) is 1.5

atan (value is number) returns ValueWithUnits

Arctangent, i.e. inverse tangent.

Returns a value between -90 * degree and 90 * degree.

EXAMPLE

atan(1) equals approximately 45 * degree

EXAMPLE

atan(inf) equals approximately 90 * degree

atan2 (y is number, x is number) returns ValueWithUnits

Returns the counterclockwise angle from the vector [0, 1] to the vector [x, y]. The angle is negative if y is negative. This is equivalent to atan(y/x) except the result respects the quadrant of the input and is well-behaved near x == 0.

EXAMPLE

atan2(0, 1) equals approximately 0 * degree

EXAMPLE

atan2(1, 0) equals approximately 90 * degree

EXAMPLE

atan2(0, -1) equals approximately 180 * degree

EXAMPLE

atan2(-1, 0) equals approximately -90 * degree

atan2 (y is ValueWithUnits, x is ValueWithUnits) returns ValueWithUnits

Returns the counterclockwise angle from the vector [0, 1] to the vector [x, y], assuming the units of y and x match.

See also

atan2(number, number)

isAngleBetween (queryAngle is ValueWithUnits, minAngle is ValueWithUnits, maxAngle is ValueWithUnits)

Returns true if the provided angle is within the given range (inclusive with tolerance), "winding" the query angle as necessary to put it within a positive full circle turn of the range. Ranges that encompass one or more full circles will return true regardless of the query angle.

Throws if range's maximum angle is less than the minimum angle.

EXAMPLE

isAngleBetween(0.5 * PI * radian, 0 * radian, PI * radian) returns true

EXAMPLE

isAngleBetween(0.5 * PI * radian, 2 * PI * radian, 3 * PI * radian) returns true

EXAMPLE

isAngleBetween(-1.5 * PI * radian, 0 * radian, PI * radian) returns true

floor (value, multiple)

Round a value down to nearest given multiple.

EXAMPLE

floor(125, 10) returns 120

EXAMPLE

floor(-15, 10) returns -20

EXAMPLE

floor(3.14 * inch, 0.1 * inch) equals 3.1 * inch

ceil (value, multiple)

Round a value up to nearest given multiple.

EXAMPLE

ceil(125, 10) returns 130

EXAMPLE

ceil(-15, 10) returns -10

EXAMPLE

ceil(3.14 * inch, 0.1 * inch) equals 3.2 * inch

round (value, multiple)

Round a value to nearest given multiple.

EXAMPLE

round(125, 10) returns 130

EXAMPLE

round(-15, 10) returns -10

EXAMPLE

round((10 / 3) * meter, centimeter) equals 3.33 * meter

EXAMPLE

round(1 * meter, .001 * inch) equals 39.37 * inch

For small values of multiple, roundToPrecision is preferred to reduce floating point errors.

toString (value is ValueWithUnits) returns string

General value to string conversion.

parseJsonWithUnits (s is string)

Parse a JSON string into either a map or array. Null values in the JSON are returned as undefined. Throws if the string is not well-formed JSON. Applicable strings are parsed into a ValueWithUnits. For instance, "3 inch" will map to a ValueWithUnits with length units that repreresents 3 inches.

Return typeDescription

A map or an array corresponding to the JSON value.

vector

Vector type

A Vector is a non-empty array. It should contain numbers or lengths.

Operators +, -, *, and / are overloaded for vectors, and other operations such as dot product are available. If a vector does not contain numbers or lengths, operations that assume number-like properties may fail.

canBeVector (value) predicate

Typecheck for Vector

vector (value is array) returns Vector

Make a Vector from an array.

vector (x, y) returns Vector

Construct a 2-dimensional vector.

vector (x, y, z) returns Vector

Construct a 3-dimensional vector.

isLengthVector (value) predicate

True for a Vector where all members are values with length units.

EXAMPLE

vector([1, 2, 3, 4, 5]) * inch

isUnitlessVector (value) predicate

True for a Vector where all members are simple numbers.

EXAMPLE

vector([1, 2, 3, 4, 5])

is2dPoint (value) predicate

True for a single 2D length Vector

EXAMPLE

vector(0.5, 1) * inch

is2dPointVector (value) predicate

True for an array where all members are 2D lengths.

EXAMPLE

[vector(0, 0) * inch, vector(0, 1) * inch, vector(1, 0) * inch]

is2dDirection (value) predicate

True for a unitless 2D Vector that is normalized (i.e. has length 1)

EXAMPLE

vector(0, 1)

is3dLengthVector (value) predicate

True for a 3D Vector where all members are values with length units.

EXAMPLE

vector(0, 1.5, 30) * inch

is3dDirection (value) predicate

True for a unitless 3D Vector that is normalized (i.e. has length 1)

EXAMPLE

vector(0, 0, 1)

zeroVector (size is number) returns Vector

Make an array filled with 0.

EXAMPLE

zeroVector(3) is equivalent to vector(0, 0, 0)

squaredNorm (vector is Vector)

Returns the squared length of a vector. This is slightly faster to calculate than the length.

norm (vector is Vector)

Returns the length (norm) of a vector.

dot (vector1 is Vector, vector2 is Vector)

Returns the dot product of two vectors.

cross (vector1 is Vector, vector2 is Vector) returns Vector

Returns the cross product of two 3-dimensional vectors.

angleBetween (vector1 is Vector, vector2 is Vector) returns ValueWithUnits

Returns the angle between two 3-dimensional vectors. Values are within the range [0, PI] * radian.

EXAMPLE

angleBetween(X_DIRECTION, Y_DIRECTION) equals PI/2 * radian

EXAMPLE

angleBetween(Y_DIRECTION, X_DIRECTION) equals PI/2 * radian

A plane is fitted to the two vectors and the shortest angle between them is measured on that plane.

angleBetween (vector1 is Vector, vector2 is Vector, ref is Vector) returns ValueWithUnits

Returns the counterclockwise angle between two 3-dimensional vectors as witnessed from the tip of a third 3-dimensional vector. Values are within the range (-PI, PI] * radian with negative values indicating clockwise angles.

EXAMPLE

angleBetween(X_DIRECTION, Y_DIRECTION, Z_DIRECTION) equals PI/2 * radian

EXAMPLE

angleBetween(Y_DIRECTION, X_DIRECTION, Z_DIRECTION) equals -PI/2 * radian

The first two vectors are projected onto a plane perpendicular to the reference vector and the angle is measured according to that projection.

normalize (vector is Vector) returns Vector

Returns the (unitless) result of normalizing vector. Throws if the input is zero-length.

ParameterTypeAdditional Info
vector Vector

A Vector with any units.

project (target is Vector, source is Vector) returns Vector

Project the source vector onto the target vector. Equivalent to target * dot(source, target) / squaredNorm(target).

perpendicularVector (vec is Vector) returns Vector

Returns a vector perpendicular to the given vector. The choice of which perpendicular vector to return is arbitrary but consistent for the same input. The returned vector is unitless and of length 1.

rotationMatrix3d (from is Vector, to is Vector) returns Matrix

Construct a 3D rotation matrix that represents the minimum rotation that takes the normalized from vector to the normalized to vector. The inputs may have any units.

rotationMatrix3d (axis is Vector, angle is ValueWithUnits) returns Matrix

Construct a 3D matrix representing a counterclockwise (looking against the axis) rotation around the given axis by the given rotation angle.

scalarTripleProduct (vector1 is Vector, vector2 is Vector, vector3 is Vector)

Returns the scalar triple product, a dot (b cross c), of three 3-dimensional vectors.

toString (value is Vector) returns string

tolerantEquals (point1 is Vector, point2 is Vector) predicate

Returns true if two vectors designate the same point (within tolerance) or the same direction (within tolerance).

parallelVectors (vector1 is Vector, vector2 is Vector) returns boolean

Returns true if two vectors are parallel (within tolerance).

perpendicularVectors (vector1 is Vector, vector2 is Vector) returns boolean

Returns true if two vectors are perpendicular (within tolerance).

clusterPoints (points is array, tolerance is ValueWithUnits) returns array

Groups points into clusters. Two points farther than tolerance apart are guaranteed to be in separate clusters. A set of points all within tolerance of each other that has no other points within tolerance is guaranteed to be a single cluster.

Return typeDescription
array

Array of arrays, where each array is a cluster of nearby points, represented as indices into points array.

Utilities

attributes

Attributes are data attached to individual entities, which can be set and retrieved by name in FeatureScript. The data can be of any type, and multiple attributes with different names can be associated with the same topological entity.

One common use case for attributes is to set attributes on an entity in one feature, and get them in another. For data not associated with entities, the same thing can be accomplished simply via setVariable and getVariable, but attributes allow that data to be set on specific bodies, faces, edges, or vertices.

setAttribute(context, {
   "entities" : somePart,
   "name" : "refPoint",
   "attribute" : vector(0, 0, 1) * inch
});
// Later, possibly in another feature:
const partRefPoint = getAttribute(context, {
   "entity" : somePart,
   "name" : "refPoint"
});
if (partRefPoint != undefined)
{
    // use partRefPoint...
}

Attributes are also a useful way to mark important groups of entities for other features or other deriving Part Studios. You can query for entities with a specific attribute, a specific attribute value, or a value matching a given pattern with the query functions qHasAttribute, qHasAttributeWithValue, or qHasAttributeWithValueMatching, respectively.

Attributes stay with the entity they are defined on, even as the Part Studio changes. An attribute on a face, edge, or body which is split in two will be set with the same name and value on both split pieces. An attribute on a patterned entity will be set on each patterned copy. If two or more entities are merged together (e.g. with a boolean union), then the attributes on both are kept on the result, though if they have attributes with the same name, the value of the primary entity (e.g. the first resolved body in the boolean tools) will be used.

Legacy unnamed attributes: A previous use of these attribute functions involved setting unnamed attributes by calling setAttribute without a "name". This workflow is still supported, but is no longer recommended. Legacy unnamed attributes can be identified and retrieved only by type, and two attributes of the same type are not allowed on the same entity. The behavior of these unnamed attributes, described in "Legacy unnamed attribute" notes like this one, can be safely ignored if all your attributes are set with a "name".

setAttribute (context is Context, definition is map)

Attach an attribute to one or several entities. Will overwrite any attribute previously set on the same entity with the same name.

ParameterTypeAdditional Info
definition map
  • entities
Query

Entities to attach attribute to. Throws an error if the query resolves to nothing.

  • name
string

The name of the attribute

  • attribute

The data to set. Can be any type. If undefined is provided, any existing attribute will be unset (and this entity will no longer resolve in qHasAttribute and similar functions)

Legacy unnamed attributes: If name is not provided, adds an unnamed attribute to the entities. If more than one unnamed attribute with the same type is set on any entity, throws an error.

getAttributes (context is Context, definition is map) returns array

Get attributes attached to entities.

ParameterTypeAdditional Info
definition map
  • entities
Query

Entities to get attributes on. If query resolves to nothing, empty array is returned

  • name
string

The name of the attribute to get.

  • attributePattern

Optional

Providing a map here will also filter out attributes which do not have entries precisely matching the keys and values of attributePattern, similar to qHasAttributeWithValueMatching.

EXAMPLE

{ "odd" : true } matches all attributes values are maps with a field "odd" whose value is true.

Legacy unnamed attributes: If attributePattern is provided and name is not, getAttributes will only return unnamed attributes with the same type as attributePattern, using the same behavior documented in the legacy function qAttributeFilter.

Return typeDescription
array

An array of all unique attributes on the given entities matching the pattern.

getAttribute (context is Context, definition is map)

Get the value of a single named attribute attached to a single entity, or undefined if no attribute of that name has been set.

EXAMPLE

setAttribute(context, { "entities" : someEntities, "name" : "importantData", "attribute" : 42});
for (const entity in evaluateQuery(entities)) {
    const value = getAttribute(context, {
        "entity" : entity,
        "name" : "importantData"
    });
    println(value); // prints 42
}
ParameterTypeAdditional Info
definition map
  • entity
Query

Query resolving to a single entity to get the attribute from. If multiple entities are resolved, the first resolved entity is considered.

  • name
string

Name of the attribute

getAllAttributes (context is Context, definition is map) returns map

Get the named attributes attached to a single entity, or an empty map if the entity has no attributes.

ParameterTypeAdditional Info
definition map
  • entity
Query

Query resolving to a single entity to get the attributes from.

Return typeDescription
map

A map from attribute names to attribute values for all of the attributes on the given entity.

removeAttributes (context is Context, definition is map)

Has no effect on named attributes, instead use setAttribute with "attribute" : undefined.

Legacy unnamed attributes: Remove matching unnamed attributes attached to entities.

ParameterTypeAdditional Info
definition map
  • entities
Query

Optional

Entities to remove unnamed attributes from. Default is everything.

  • attributePattern

Optional

If provided, will only remove attributes with the same type, using the same behavior documented in the legacy function qAttributeFilter.

computedPartProperty

defineComputedPartProperty (propertyFunction is function) returns function

This function takes a computed part property function and wraps it to define a computed part property. It is analogous to defineFeature, except that it is used to define computed part properties. A typical usage is something like:

annotation { "Property Function Name" : "MyProperty" }  // annotation required for Onshape to recognize computed property function
export const myProperty = defineComputedPartProperty(function(context is Context, part is Query, definition is map)
    returns ValueWithUnits // may also return string or boolean or number
    // definition is an empty map and reserved for future use
    {
        ... // Compute and return the property value, using the context and the parameters
    });

For more information on writing computed part properties, see Computed part properties in the FeatureScript guide.

ParameterTypeAdditional Info
propertyFunction function

A function that takes a context, a part Query that returns a single Part, and a definition, and that returns a value such as a number or a string or a ValueWithUnits.

containers

This module contains functions for working with FeatureScript arrays (e.g. [1, 2, 3]) and maps (e.g. { "x" : 1, "y" : true })

makeArray (size is number, fillValue) returns array

Create a new array with given size, filled with fillValue. Note: this is equivalent to assigning each individual array element to fillValue; boxes and builtins will not be deep-copied.

EXAMPLE

makeArray(3, 0) returns [0, 0, 0]

makeArray (size is number) returns array

Create a new array with given size, filled with undefined.

EXAMPLE

makeArray(3) returns [undefined, undefined, undefined]

size (container is array) returns number

Returns the size of an array. This counts only direct children; it does not recursively examine containers inside.

EXAMPLE

size([1, 2, 3]) returns 3

EXAMPLE

size([1, [2, 3]]) returns 2

size (container is map) returns number

Returns the size of an map. This counts only direct children; it does not recursively examine containers inside.

EXAMPLE

size({ "x" : 1, "y" : 2 }) returns 2

isIn (value, container is array) returns boolean

Returns true if value appears in an array, using == for comparison.

EXAMPLE

isIn(1 * inch, [0 * inch, 1 * inch, 2 * inch]) returns true

indexOf (container is array, value) returns number

Return the index of the value in container, or -1 if the value is not found.

indexOf (container is array, value, startIndex is number) returns number

Return the index of the value in container starting the search at a specified start index, or -1 if the value is not found.

isValueIn (value, container is map) returns boolean

Returns true if value appears as the value of a map entry, using == for comparison.

EXAMPLE

isValueIn(true, { "a" : true, "b" : 0 }) returns true

EXAMPLE

isValueIn("b", { "a" : true, "b" : 0 }) returns false

mapArray (arr is array, mapFunction is function) returns array

Returns a new array, with the same size as arr, created by mapping each element of arr through a mapFunction.

EXAMPLE

mapArray([0, 1], function(x) { return -x; }) returns [0, -1]
ParameterTypeAdditional Info
mapFunction function

A function which takes in one argument (a member of the input array) and returns a value.

resize (arr is array, newSize is number, newValue) returns array

Returns a copy of an array with size changed to newSize. If the new size is larger than the original size, the extra values are set to newValue.

EXAMPLE

resize([1, 2, 3], 2, 0) returns [1, 2]

EXAMPLE

resize([1, 2, 3], 5, 0) returns [1, 2, 3, 0, 0]

resize (arr is array, newSize is number) returns array

Returns a copy of an array with size changed to newSize. If the new size is larger than the original size, the extra values are set to undefined.

append (arr is array, newValue) returns array

Returns a copy of an array with a single value added to the end.

EXAMPLE

append([1, 2], 3) returns [1, 2, 3]

concatenateArrays (arr is array) returns array

Given an array of arrays, concatenate the contents of the inner arrays.

EXAMPLE

concatenateArrays([[1, 2], [3, 4]]) returns [1, 2, 3, 4]

EXAMPLE

concatenateArrays([[1], [], [2, undefined], [[3]]]) returns [1, 2, undefined, [3]]

mergeMaps (defaults is map, m is map) returns map

Add each key-value pair in the second map to a copy of first and return the result. Since later-added entries take precedence, nothing from the second map will be lost.

In other words, any keys from defaults which are missing from m will be filled in with their values from defaults.

EXAMPLE

mergeMaps({a:0}, {a:1}) returns {a:1}

EXAMPLE

mergeMaps({a:0}, {b:1}) returns {a:0, b:1}

intersectMaps (maps is array) returns map

Compute the intersection of the keysets of the input maps. In other words, returns a map whose keys are present in all input maps and whose values are taken from the last map.

EXAMPLE

intersectMaps([{a:0}, {a:1}]) returns {a:1}

EXAMPLE

intersectMaps([{a:0}, {b:1}]) returns {}

EXAMPLE

intersectMaps([{a:0, b:1}, {a:0, b:2}]) returns {a:0, b:2}

reverse (arr is array) returns array

Return a copy of an array with elements in reverse order.

EXAMPLE

reverse([1, 2, 3]) returns [3, 2, 1]

sort (entities is array, compareFunction is function)

Return a sorted copy of an array. Current implementation uses merge sort.

EXAMPLE

sort([3, 1, 2], function(a, b) { return a - b; }) returns [1, 2, 3]
ParameterTypeAdditional Info
compareFunction function

A function that takes two values, returns a negative value if the first is before the second, 0 if the two are equal, and positive value if the second is before the first.

tolerantSort (values is array, tolerance) returns array

Returns a sorted copy of values, where any sequence of values within tolerance of each other is sorted in the order of the original array.

This is useful when sorting by a geometric measurement (like length, area, or volume) because it makes it much less likely that a tiny change in that computed value will change the resulting sort order.

EXAMPLE

tolerantSort([5, 1.000001, 1, 8], 0.001) returns [1.000001, 1, 5, 8]

EXAMPLE

tolerantSort( [1 * inch, 1.00009 * inch, 0.99991 * inch], 0.0001 * inch) returns [1 * inch, 1.00009 * inch, 0.99991 * inch]. The order is entirely unchanged since two pairs of values are within the tolerance (even though the third pair isn't).
ParameterTypeAdditional Info
values array

An array of number or ValueWithUnits.

tolerance

Tolerance for comparing elements of values.

tolerantSort (entities is array, tolerance, mapFunction) returns array

Performs a tolerantSort of entities, ordering by the value returned by mapFunction. Like tolerantSort, the original order will be preserved for values within tolerance for stability.

ParameterTypeAdditional Info
tolerance

EXAMPLE

1e-7 * meter
mapFunction

A function taking in a single entity and returning a sortable number or ValueWithUnits.

EXAMPLE

function(entity is Query) { return evLength(context, {"entities" : entity}); } to sort entities by increasing length.

filter (arr is array, filterFunction is function)

Return the members of an array matching a predicate function, preserving element order.

Throws exception if filterFunction throws, or if the filterFunction does not return boolean.

EXAMPLE

filter([1, 2, 3, 4, 5, 6], function(x) { return x % 2 == 0; }) returns [2, 4, 6]
ParameterTypeAdditional Info
filterFunction function

A function which takes one argument (a member of the input array) and returns a boolean.

first (m is map)

Return the first item in a map

keys (container is map) returns array

Returns the keys in the supplied map in map iteration order.

EXAMPLE

keys({ "a" : 1, "c" : 2, "b" : 3 }) returns ["a", "b", "c"]

values (container is map) returns array

Returns the values in the supplied map ordered by the map iteration ordering of their associated keys.

EXAMPLE

values({ "a" : 1, "c" : 2, "b" : 3 }) returns [1, 3, 2]

subArray (input is array, startIndex is number) returns array

Returns the subarray beginning at startIndex

subArray (input is array, startIndex is number, endIndex is number) returns array

Returns the subarray [startIndex, endIndex)

insertIntoMapOfArrays (mapToInsertInto is map, key, value) returns map

Inserts value into the array keyed by key, returns the updated map

last (elements is array)

Returns last element of array.

rotateArray (elements is array, step is number) returns array

Returns a rotated array of the same elements. step less than zero moves elements towards the front. step greater than zero moves elements towards the back.

EXAMPLE

rotateArray([0, 1, 2], -1) returns [1, 2, 0]

insertElementAt (arr is array, index is number, value) returns array

Returns an array with value inserted at index.

removeElementAt (arr is array, index is number) returns array

Returns an array with the element at index removed.

all (arr is array, checkFunction is function) returns boolean

Returns true if and only if all elements of an array, when passed into the checkFunction, return true.

EXAMPLE

all([0, 2, 4], function(e){ return e % 2 == 0; }) returns true

EXAMPLE

all([], function(e){ return false; }) returns true

See also

all(array)

ParameterTypeAdditional Info
arr array

An array of elements to be checked.

checkFunction function

A unary function that returns a boolean.

Return typeDescription
boolean

true if and only if all checkFunction(element) calls return true.

all (arr is array) returns boolean

Returns true if all elements in the passed array are true.

EXAMPLE

all([]) returns true

EXAMPLE

all([false, false, true]) returns false

EXAMPLE

all([true, true, true]) returns true

See also

all(array, function)

ParameterTypeAdditional Info
arr array

An array of booleans.

Return typeDescription
boolean

true if and only if all elements are true.

allCombinations (arr is array) returns array

Creates all possible combinations from arrays of values for each element.

EXAMPLE

allCombinations([[1,2], [3,4]]) returns [[1,3], [1,4], [2,3], [2,4]]

EXAMPLE

allCombinations([[0, 1, 2, 3]]) returns [[0], [1], [2], [3]]

EXAMPLE

allCombinations([[], [0, 1, 2]]) returns []
ParameterTypeAdditional Info
arr array

An array of arrays, where each array represents all possible values for the given array's index in the returned arrays.

Return typeDescription
array

An array of all possible combinations that have exactly one element from each of the input arrays.

any (arr is array, check is function) returns boolean

Returns true if any element of an array, when passed into the check function, returns true.

EXAMPLE

any([1, 3, 4], function(e){ return e % 2 == 0; }) returns true

EXAMPLE

any([], function(e){ return true; }) returns false

See also

any(array)

ParameterTypeAdditional Info
arr array

An array of elements.

Return typeDescription
boolean

true if and only if at least one check(element) call returns true.

any (arr is array) returns boolean

Returns true if any element in the passed array is true.

EXAMPLE

any([]) returns false

EXAMPLE

any([false, false, true]) returns true

See also

any(array, function)

ParameterTypeAdditional Info
arr array

An array of booleans.

Return typeDescription
boolean

true if and only if at least one element is true.

average (arr is array)

Returns the average of an array. All array elements must be mutually addable and divisible by a number.

EXAMPLE

average([1, 2, 3, 4]) returns 2.5

EXAMPLE

average([vector([1, 0, 0])*meter, vector([0, 0, 0])*meter, vector([0, 1, 0])*meter]) returns vector(1/3, 1/3, 0) * meter
ParameterTypeAdditional Info
arr array

An array of mutually addable and divisible elements.

Return typeDescription

The average of values in the passed in array.

deduplicate (arr is array) returns array

Deduplicate an array. Maintains original array order, eliminating all but the first occurrence of a given duplicate.

EXAMPLE

deduplicate([1, 2, 1, 3, 2, 0, 0]) returns [1, 2, 3, 0]

EXAMPLE

deduplicate([]) returns []
ParameterTypeAdditional Info
arr array

An array of values to be deduplicated.

Return typeDescription
array

An array of deduplicated values.

foldArray (arr is array, seed, foldFunction is function)

Folds an array from left to right with a foldFunction.

EXAMPLE

foldArray([1, 2, 3], 0, function(accumulator, element) { return accumulator + element; }) returns 6
ParameterTypeAdditional Info
arr array

An array to fold.

seed

The initial value of the accumulator to be passed into the foldFunction.

foldFunction function

A binary function which takes in an accumulator (the seed for the first iteration, and the result of the previous call for subsequent iterations) and an element of the passed in array.

Return typeDescription

The accumulator after all elements of arr have been folded.

foldArray (arr is array, foldFunction is function)

Calls foldArray with the seed set to the first element of arr.

See also

foldArray

mapArrayIndices (arr is array, mapIndexFunction is function) returns array

Returns a new array, with the same size as arr, created by mapping each index of arr through a mapIndexFunction.

EXAMPLE

const myArray = [1, 3, 5]; mapArrayIndices(myArray, function(i) { return myArray[i] + myArray[ (i+1) % size(myArray)]; }) returns [4, 8, 6]
ParameterTypeAdditional Info
mapIndexFunction function

A function which takes in one argument (an index of the input array) and returns a value.

Return typeDescription
array

The results of calling mapIndexFunction on the indices of all elements in the passed in arr.

mapValue (value, mapFunction is function)

Map a value using a mapFunction and return the result. Particularly useful when using a lambda function inline to dynamically change some value.

EXAMPLE

mapValue(4, function(n){ return n+1; }) returns 5

EXAMPLE

couldBeUndefined->mapValue(function(v){ return v == undefined ? 'a great default' : v; })
ParameterTypeAdditional Info
value

Anything that the passed in mapFunction will accept as a parameter.

mapFunction function

A function that will be called on the passed in value.

Return typeDescription

The result of calling mapFunction with value.

memoizeFunction (f is function) returns function

Memoize a unary (one-parameter) function. Once memoized, if the returned function is called with the same parameter twice, the second return value will be fetched from an internal cache. This can dramatically speed up calculations - particularly when f is called with the same parameter many times. The overhead of memoizing a function is negligible. Note that memoization will not properly work with functions that have side effects, such as modifying a box.

EXAMPLE

const square = memoizeFunction(function(n){ return n^2; });
println(square(5)); // calls f internally and prints 25
println(square(5)); // retrieves cached value of 25 and returns it
ParameterTypeAdditional Info
f function

A unary function to be memoized.

Return typeDescription
function

A memoized function that will return the same thing as f.

mergeMaps (defaults, keyList is array, newNode)

Merge maps at a particular location as specified by the keyList. If either the destination node specified by the keyList or the newNode is not a map, the newNode will replace the destination node.

EXAMPLE

mergeMaps({ a: [ { b: 2 } ] }, ['a', 0, 'b'], 4) returns { a : [ { b : 4 } ] }

EXAMPLE

mergeMaps(5, [], 4) returns 4

EXAMPLE

mergeMaps({ a : 5 }, ['a'], 4) returns {a: 4 }

See also

mergeMaps(map, map)

ParameterTypeAdditional Info
defaults

A container (array or map) that will be merged at the location specified by the keyList. If defaults is not an array or map and keyList is empty, the result is newNode since a merge isn't possible.

keyList array

An array of map keys or array indices that collectively specify a location within defaults to perform the merge.

newNode

A value that will be merged into defaults at the location specified by keyList. If the newNode specified is a map and the node identified by keyList is a map, then this will perform a mergeMaps operation.

Return typeDescription

The merged or replaced value.

sum (arr is array)

Sum an array of elements that are all mutually addable. An empty array returns 0.

EXAMPLE

sum(range(0,5)) returns 15

EXAMPLE

sum([vector(1, 2, 3) * meter, vector(4, 5, 6) * meter]) returns vector(5, 7, 9) * meter

EXAMPLE

sum([]) returns 0
ParameterTypeAdditional Info
arr array

An array of mutually addable elements to be summed.

Return typeDescription

The sum of values in the passed in array.

zip (arr is array) returns array

Makes an array that aggregates elements from each of the arrays. Returns an array of arrays, where the i-th array contains the i-th element from each of the argument arrays. The array stops when the shortest input array is exhausted. With a single array argument, it returns an array of single element arrays. With no arguments, it returns an empty array.

EXAMPLE

zip([range(0,3), range(10,13), range(20,26)]) returns [[0, 10, 20], [1, 11, 21], [2, 12, 22], [3, 13, 23]]

EXAMPLE

zip([]) returns []

EXAMPLE

zip([range(0, 3)]) returns [[0],[1],[2],[3]]

See also

zip(array, array)

ParameterTypeAdditional Info
arr array

An array of arrays to aggregate.

Return typeDescription
array

An array where the i'th element contains the i'th element from each of the passed in arrays.

zip (a is array, b is array) returns array

An alternative way to call zip(array) that facilitates chaining arguments.

EXAMPLE

zip(range(0,3), range(1, 4)) returns [[0, 1], [1, 2], [2, 3], [3, 4]]

EXAMPLE

zip(range(0,3), []) returns []

See also

zip(array)

ParameterTypeAdditional Info
a array

The first array to zip.

b array

The second array to zip.

Return typeDescription
array

An array of length-2 arrays. For the i'th array, the first element is the i'th element of a and the second is the i'th element of b.

debug

debug (context is Context, value, color is DebugColor)

Print and, if applicable, display value in a Part Studio, highlighting or creating entities in a chosen color, red by default.

The displayed data will ONLY be visible when the feature calling the debug function is being edited. Entities displayed during debug are for display only, and will not appear in any queries.

Values which can be debugged are:

Query: Highlights entities matching the Query (bodies, faces, edges, and vertices) in red.

3D length Vector: Displays a single point in world space.

Unitless, normalized 3D Vector: Displays an arrow starting at the world origin, pointing in the given direction.

Line: Displays an arrow starting at the line's origin, pointing in the line's direction.

CoordSystem: Displays three perpendicular arrows from the coordinate system's origin, along its three axes. The arrowhead for the x-axis is largest, and the z-axis is smallest.

Plane: Displays a large square in the positive quadrant of the plane, along with three arrows along the plane's x-axis, y-axis, and normal.

Box3d: Displays the edges of the bounding box (in the given coordinate system, if provided)

The overloads in this module define these behaviors.

ParameterTypeAdditional Info
color DebugColor

Optional

The color of the debug highlight

debug (context is Context, value)

debug (context is Context, value is ValueWithUnits, color is DebugColor)

debug (context is Context, value is Vector, color is DebugColor)

debug (context is Context, value is Query, color is DebugColor)

debug (context is Context, value is Line, color is DebugColor)

debug (context is Context, value is CoordSystem)

debug (context is Context, value is CoordSystem, color is DebugColor)

debug (context is Context, value is CoordSystem, xColor is DebugColor, yColor is DebugColor, zColor is DebugColor)

debug (context is Context, value is Plane, color is DebugColor)

debug (context is Context, point1 is Vector, point2 is Vector, color is DebugColor)

Draws a line between point1 and point2 and prints the points with the distance between them.

debug (context is Context, point1 is Vector, point2 is Vector)

debug (context is Context, boundingBox is Box3d, color is DebugColor)

Displays the edges of a Box3d in the world coordinate system with a chosen DebugColor.

debug (context is Context, boundingBox is Box3d, cSys, color is DebugColor)

Displays the edges of a Box3d in the given coordinate system with a chosen DebugColor.

EXAMPLE

const myBox = evBox3d(context, { "topology" : entities, "cSys" : myCSys });
debug(context, myBox, myCSys, DebugColor.RED);

debug (context is Context, boundingBox is Box3d, cSys)

addDebugEntities (context is Context, entities is Query, color is DebugColor)

Highlights entities in a given DebugColor, without printing anything.

As with debug, highlighted entities are only visible while the debugged feature's edit dialog is open.

addDebugEntities (context is Context, entities is Query)

addDebugPoint (context is Context, point is Vector, color is DebugColor)

Highlights a 3D point in a given DebugColor, without printing anything.

As with debug, highlighted entities are only visible while the debugged feature's edit dialog is open.

addDebugPoint (context is Context, point is Vector)

addDebugLine (context is Context, point1 is Vector, point2 is Vector, color is DebugColor)

Draws a line in 3D space from point1 to point2 with a chosen DebugColor.

As with debug, highlighted entities are only visible while the debugged feature's edit dialog is open.

ParameterTypeAdditional Info
point1 Vector

one endpoint of the line.

point2 Vector

the other endpoint of the line.

addDebugLine (context is Context, point1 is Vector, point2 is Vector)

addDebugArrow (context is Context, from is Vector, to is Vector, radius is ValueWithUnits, color is DebugColor)

Draws an arrow in 3D space from from to to with a chosen DebugColor.

As with debug, highlighted entities are only visible while the debugged feature's edit dialog is open.

ParameterTypeAdditional Info
radius ValueWithUnits

Width of the four arrowhead lines

EXAMPLE

.25 * centimeter

addDebugArrow (context is Context, from is Vector, to is Vector, radius is ValueWithUnits)

startTimer (timer is string)

Starts the timer associated with the string timer or resets it. Use with printTimer(string).

startTimer ()

Starts the global timer associated with the empty string or resets it. Use with printTimer().

printTimer (timer is string)

Prints the elapsed milliseconds for the timer associated with the string timer. Use with startTimer(string).

Note that if the timer was set in a prior feature, the elapsed time may be very large because features can be regenerated at different times.

Throws an error if no such timer has been started.

printTimer ()

Prints the elapsed milliseconds for the global timer associated with the empty string. Use with startTimer().

Note that if the timer was set in a prior feature, the elapsed time may be very large because features can be regenerated at different times.

Throws an error if no such timer has been started.

decalUtils

DecalData type

Data representing a decal that is mapped onto a face.

ValueTypeDescription
DecalData map
  • decalId
Id

A unique id to represent the decal in the context of the face on which it is placed. The id should correspond to the id of the creating feature, or be a sub-id of the creating feature.

  • imageMappingType
ImageMappingType

The type of projection mapping to use for this decal

  • image
ImageData

The image that is being mapped.

  • uvTransform
TransformUV

A post-projection transformation that is applied in UV space. This can be used to further translate, rotate, and scale a projected image.

  • planeSystem
PersistentCoordSystem

Optional

A coordinate system representing the plane for the ImageMappingType.PLANAR type. This field must be defined if the imageMappingType field is of type ImageMappingType.PLANAR. The center of the image will project to the plane's origin. The right edge of the image is along the positive X direction of the coordinate system. The top edge of the image is along the positive Y direction of the coordinate system. See planeToCSys for deriving a coordinate system from a Plane object.

  • cylinder
Cylinder

Optional

The cylinder onto which the decal is mapped. This field must be defined if the imageMappingType field is of type ImageMappingType.CYLINDRICAL.

  • cylinderSystem
PersistentCoordSystem

Optional

A coordinate system used in projecting the image onto the given cylinder. This field must be defined if the imageMappingType field is of type ImageMappingType.CYLINDRICAL. The coordinate system's origin must lie on the cylinder's axis with the system's Z axis aligned with the cylinder's own axis. The center of the horizontal extents of the image coincide with the intersection of the coordinate system's x axis and the cylinder. The center of the vertical extents of the image coincide with the projection of the coordinate system's origin on the cylinder. The top edge of the image is along the positive Z direction of the coordinate system projected on the cylinder.

createPlanarDecal (decalId is Id, image is ImageData, planeSystem is CoordSystem, uvTransform is TransformUV) returns DecalData

Creates data for a planar decal. This can be applied to a face using associateDecalAttribute.

See also

DecalData

ParameterTypeAdditional Info
decalId Id

The id to for the decal

image ImageData

The image to use for the data

planeSystem CoordSystem

The coordinate system to use for the planar projection

uvTransform TransformUV

A post-projection transform to apply to the decal

createCylindricalDecal (decalId is Id, image is ImageData, cylinder is Cylinder, uvTransform is TransformUV) returns DecalData

Creates data for a cylindrical decal. This can be applied to a face using associateDecalAttribute.

See also

DecalData

ParameterTypeAdditional Info
decalId Id

The id to for the decal

image ImageData

The image to use for the data

cylinder Cylinder

The cylinder definition to use for projection

uvTransform TransformUV

A post-projection transform to apply to the decal

associateDecalAttribute (context is Context, entities is Query, decalData is DecalData)

Associate the given decal data as an attribute on the entities provided. This will append the decal to any existing decals associated with the given entities.

Associating a decal in this way will cause the data to be transmitted to Onshape clients where they will be rendered.

createUvTransform (decalWidth is ValueWithUnits, mirrorHorizontal is boolean, decalHeight is ValueWithUnits, mirrorVertical is boolean, decalRotation is ValueWithUnits) returns TransformUV

Creates a UV transform suitable for scaling, mirroring, and rotating a decal after it's been projected.

ParameterTypeAdditional Info
decalWidth ValueWithUnits

The width of the decal, post-transformation

mirrorHorizontal boolean

If true, the image will be mirrored about its center horizontally

decalHeight ValueWithUnits

The height of the decal, post-transformation

mirrorVertical boolean

If true, the image will be mirrored about its center vertically

decalRotation ValueWithUnits

An amount of rotation to apply to decal about the image center.

getWorldSpacePosition (decalData is DecalData, uv is Vector)

Unprojects the given point in UV space to its corresponding world position for the given decal data. The UV is equivalent to the texture coordinate for the UV that is ultimately used to render the decal.

See also

getDecalUvSpacePosition

getDecalUvSpacePosition (decalData is DecalData, worldPosition is Vector)

Projects the given world position into UV space for the given decal data. The UV computed is equivalent to the texture coordinate for the UV that is ultimately used to render the decal.

See also

getWorldSpacePosition

defaultFeatures

newContextWithDefaults () returns Context

Creates a Context with default planes and an origin.

qDefaultBodies () returns Query

A query for all default created bodies in a context, that is, the top, right, front planes and the origin point.

qFrontPlane (entityType is EntityType) returns Query

A query for the front plane.

ParameterTypeAdditional Info
entityType EntityType

Specify type FACE or BODY.

qRightPlane (entityType is EntityType) returns Query

A query for the right plane.

ParameterTypeAdditional Info
entityType EntityType

Specify type FACE or BODY.

qTopPlane (entityType is EntityType) returns Query

A query for the top plane.

ParameterTypeAdditional Info
entityType EntityType

Specify type FACE or BODY.

qOrigin (entityType is EntityType) returns Query

A query for the origin point.

ParameterTypeAdditional Info
entityType EntityType

Specify type VERTEX or BODY.

derive

derive (context is Context, id is Id, buildFunction is function, options is map) returns map

Merges context returned by buildFunction(options.configuration) into context.

ParameterTypeAdditional Info
options map
  • parts
Query

Queries resolving to bodies in base context to be preserved.

  • configuration
map

The configuration of the part studio.

  • clearSMDataFromAll
boolean

Optional

Default is true. If set to false, for every part in options.parts belonging to an active sheet metal model all 3d parts and flats of that sheet metal model survive and remain active.

  • filterOutNonModifiable
boolean

Optional

Default is true.

  • propagateMergeStatus
boolean

Optional

Default is true.

  • noPartsError
ErrorStringEnum

Optional

Error to be reported if options.parts resolves to empty array. If field is not specified ErrorStringEnum.IMPORT_DERIVED_NO_PARTS is used.

  • noPartsErrorParams
array

Optional

  • queriesToTrack
map

Optional

Map whose keys are Querys which resolve in the original derived context (that is, the context resulting from buildFunction). If set, the output field trackingResults will contain values which resolve to each query's equivalent entities in the current context.

  • mateConnectors
array

Optional

Array of queries for mate connectors, to evaluate in the new context. If set, the output field mateConnectors will be a map from each query to its resulting transform.

  • mateConnectorIds
array

Optional

Array of creating feature ids for mate connectors.

  • mateConnectorFeatureIndices
array

Optional

Array of indices into mate connectors created by feature.

  • loadedContext
Context

Optional

Preloaded context, if available, of the reference.

ReturnTypeDescription
map
  • mateConnectors
map

Map from mate connector query to Transform to that mate connector

  • trackingResults
map

Map from Query keys of queriesToTrack to each query's value in the new context (given as an array of transient queries)

edgeBlendCommon

addFilletControlManipulator (context is Context, id is Id, definition is map, manipulatorEntity is Query)

Create a linear manipulator for radius or width parameter

onFilletControlManipulatorChange (context is Context, definition is map, newManipulators is map, manipulatorEntity is Query, widthFieldName is string) returns map

fillet manipulator change function

error

regenError (customMessage is string) returns map

regenError functions are used to construct maps for throwing to signal feature regeneration errors. Can either take a string for a custom message or an ErrorStringEnum for a built-in message. Custom messages are limited to ASCII characters. Messages longer than 200 characters will not be displayed fully.

EXAMPLE

throw regenError("Failed to attach widget: Boolean union failed")

EXAMPLE

throw regenError("Wall is too thin for this feature", ["wallWidth"]);

EXAMPLE

throw regenError(ErrorStringEnum.POINTS_COINCIDENT, ["points"]);

regenError (customMessage is string, faultyParameters is array) returns map

ParameterTypeAdditional Info
faultyParameters array

An array of strings that correspond to keys in the feature definition map. Throwing a regenError with faultyParameters will highlight them in red inside the feature dialog.

regenError (customMessage is string, entities is Query) returns map

ParameterTypeAdditional Info
entities Query

A query for entities to highlight in the Part Studio. Multiple queries can be combined and highlighted using the qUnion function. The entities are only highlighted when the feature dialog is open.

regenError (customMessage is string, faultyParameters is array, entities is Query) returns map

ParameterTypeAdditional Info
faultyParameters array

An array of strings that correspond to keys in the feature definition map. Throwing a regenError with faultyParameters will highlight them in red inside the feature dialog.

entities Query

A query for entities to highlight in the Part Studio. Multiple queries can be combined and highlighted using the qUnion function. The entities are only highlighted when the feature dialog is open.

regenError (message is ErrorStringEnum) returns map

The following overloads take an ErrorStringEnum rather than a custom message, and are using for all errors withing the Onshape Standard Library. The enum values correspond to messages which can be translated into multiple languages.

regenError (message is ErrorStringEnum, faultyParameters is array) returns map

ParameterTypeAdditional Info
faultyParameters array

An array of strings that correspond to keys in the feature definition map. Throwing a regenError with faultyParameters will highlight them in red inside the feature dialog.

regenError (message is ErrorStringEnum, entities is Query) returns map

ParameterTypeAdditional Info
entities Query

A query for entities to highlight in the Part Studio. Multiple queries can be combined and highlighted using the qUnion function. The entities are only highlighted when the feature dialog is open.

regenError (message is ErrorStringEnum, faultyParameters is array, entities is Query) returns map

ParameterTypeAdditional Info
faultyParameters array

An array of strings that correspond to keys in the feature definition map. Throwing a regenError with faultyParameters will highlight them in red inside the feature dialog.

entities Query

A query for entities to highlight in the Part Studio. Multiple queries can be combined and highlighted using the qUnion function. The entities are only highlighted when the feature dialog is open.

regenError (message is ErrorStringEnum, regenErrorOptions is map) returns map

ParameterTypeAdditional Info
regenErrorOptions map
  • faultyParameters

An array of strings that correspond to keys in the feature definition map. Throwing a regenError with faultyParameters will highlight them in red inside the feature dialog.

  • entities

A query for entities to highlight in the Part Studio. Multiple queries can be combined and highlighted using the qUnion function. The entities are only highlighted when the feature dialog is open.

regenError (message is string, regenErrorOptions is map) returns map

ParameterTypeAdditional Info
regenErrorOptions map
  • faultyParameters

An array of strings that correspond to keys in the feature definition map. Throwing a regenError with faultyParameters will highlight them in red inside the feature dialog.

  • entities

A query for entities to highlight in the Part Studio. Multiple queries can be combined and highlighted using the qUnion function. The entities are only highlighted when the feature dialog is open.

reportFeatureWarning (context is Context, id is Id, message is ErrorStringEnum) returns boolean

Attaches a warning-level status to the given feature id.

reportFeatureWarning (context is Context, id is Id, customMessage is string) returns boolean

Attaches a custom warning-level status to the given feature id. Will display a notification to the user containing the specified message.

reportFeatureWarning (context is Context, id is Id, message is ErrorStringEnum, associatedParameters is array) returns boolean

Attaches custom warning-level status to the given feature id. Will display a notification to the user containing the specified message.

reportFeatureInfo (context is Context, id is Id, message is ErrorStringEnum) returns boolean

Attaches an info-level status to the given feature id. Will display a notification to the user containing the specified message.

reportFeatureInfo (context is Context, id is Id, message is ErrorStringEnum, associatedParameters is array) returns boolean

Attaches an info-level status to the given feature id. Will display a notification to the user containing the specified message.

reportFeatureInfo (context is Context, id is Id, customMessage is string) returns boolean

Attaches a custom info-level status to the given feature id.

processSubfeatureStatus (context is Context, id is Id, options is map) returns boolean

Propagate the status of a subfeature to a feature.

ParameterTypeAdditional Info
options map
  • subfeatureId
Id

The Id of the subfeature.

  • overrideStatus
ErrorStringEnum

Optional

A status enum to use instead of the subfeature status enum if the subfeature has an info, warning, or error status.

  • featureParameterMap
map

Optional

A mapping of the field names from subfeature to feature.

  • featureParameterMappingFunction
function

Optional

A function to map field names from subfeature to feature.

  • propagateErrorDisplay
boolean

Optional

Use subfeature error display when present. Default is false.

  • additionalErrorEntities
Query

Optional

Additional error entities to display if the subfeature has an info, warning, or error status.

getFeatureStatus (context is Context, id is Id) returns FeatureStatus

Return the status of a feature as a FeatureStatus

reportFeatureStatus (context is Context, id is Id, status is FeatureStatus) returns boolean

Report the status of a feature

clearFeatureStatus (context is Context, id is Id, definition is map) returns boolean

Clear the status of a feature to StatusType.OK *

ParameterTypeAdditional Info
definition map
  • withDisplayData
boolean

Optional

Clear status display data attached to feature. Default true.

getFeatureError (context is Context, id is Id)

Returns the error (as a string or an ErrorStringEnum) associated with the given feature id or undefined if none.

getFeatureWarning (context is Context, id is Id)

Returns the warning (as a string or an ErrorStringEnum) associated with the given feature id or undefined if none.

getFeatureInfo (context is Context, id is Id)

Returns the info status (as a string or an ErrorStringEnum) associated with the given feature id or undefined if none.

setErrorEntities (context is Context, id is Id, definition is map)

Causes the given entities to be shown in red. This display is not rolled back even if the feature fails and the entities themselves are rolled back.

ParameterTypeAdditional Info
definition map
  • entities
Query

The entities to display.

featureHasError (context is Context, id is Id) returns boolean

Return typeDescription
boolean

true if the feature with the given id has an associated regeneration error.

featureHasNonTrivialStatus (context is Context, id is Id) returns boolean

Return typeDescription
boolean

true if the feature with the given id has an associated status different from OK.

faultyArrayParameterId (arrayParameter is string, itemIndex is number, innerParameter is string) returns string

Return typeDescription
string

A string identifier for marking an error on an array parameter when using the faultyParameters argument in any of the error reporting functions in error.fs.

FeatureStatus type

The status of a feature

ValueTypeDescription
FeatureStatus map
  • statusType
StatusType
  • faultyParameters
array
  • statusEnum
ErrorStringEnum
  • statusMsg
string

canBeFeatureStatus (value) predicate

The faultyParameters cannot exist when the statusType is StatusType.OK. The statusEnum must be ErrorStringEnum.CUSTOM_ERROR if the statusMsg exists.

verify (condition is boolean, error)

If the condition check fails, this function throws the error.

ParameterTypeAdditional Info
condition boolean

The condition to test.

error

The error to throw if condition is false, where error is of type ErrorStringEnum or string.

verify (condition is boolean, error, regenErrorOptions is map)

If the condition check fails, this function throws the error.

ParameterTypeAdditional Info
condition boolean

The condition to test.

error

The error to throw if condition is false, where error is of type ErrorStringEnum or string.

regenErrorOptions map

The key-value pairs to pass to the thrown regenError, e.g. entities or faultyParameters.

extrudeCommon

SMExtrudeBoundingType enum

Bounding type used with SMProcessType.EXTRUDE

ValueDescription
BLIND
UP_TO_NEXT
UP_TO_SURFACE
UP_TO_BODY
UP_TO_VERTEX

feature

defineFeature (feature is function, defaults is map) returns function

This function takes a regeneration function and wraps it to create a feature. It is exactly like the one-argument version of defineFeature but the additional argument enables setting default values for feature parameters when they are not passed in.

ParameterTypeAdditional Info
defaults map

A map of default parameter values for when this feature is called in FeatureScript.

This does NOT control the user-visible default value when creating this feature. To change the user-visible default for booleans, enums, and strings, use the "Default" annotation. To change the user-visible default for a length, angle, or number, see the valueBounds module.

EXAMPLE

{} will not modify the definition.

EXAMPLE

{ "shouldFillet" : false } will set the parameter "shouldFillet" to false if the feature is called from FeatureScript without the "shouldFillet" parameter.

defineFeature (feature is function) returns function

This function takes a regeneration function and wraps it to create a feature. The wrapper handles certain argument recording for the UI and error handling. A typical usage is something like:

annotation { "Feature Type Name" : "Widget" } // This annotation is required for Onshape to recognize widget as a feature.
export const widget = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        ... // Specify the parameters that this feature takes
    }
    {
        ... // Specify what the feature does when regenerating
    });

For more information on writing features, see Specifying feature UI in the language guide.

ParameterTypeAdditional Info
feature function

A function that takes a context, an id, and a definition and regenerates the feature.

startFeature (context is Context, id is Id)

callSubfeatureAndProcessStatus (topLevelId is Id, fn is function, context is Context, subfeatureId is Id, definition is map)

This function can be used to call a subfeature or sub-operation (such as extrude or opExtrude, respectively). It will properly handle any statuses as if they came from the top level feature. That is, reported INFO will display as a blue message bubble, WARNING will turn the feature orange with a warning tooltip on hover, and ERROR will throw an error after status handling (aborting feature execution if it is not caught). Any error entities that the subfeature emits will also be displayed.

EXAMPLE

callSubfeatureAndProcessStatus(id, booleanBodies, context, id + "boolean", booleanDefinition); (where id is the top-level feature id passed into the feature) will call booleanBodies(context, id + "boolean", booleanDefinition), propagate its status onto the current feature, and show any error entities coming from the boolean.

Internally, calls the supplied function, and attaches any status it produces to the topLevelId using processSubfeatureStatus. If calling the function produces an error, the error is re-thrown. If the function produces a return value, that value is returned.

callSubfeatureAndProcessStatus (topLevelId is Id, fn is function, context is Context, subfeatureId is Id, definition is map, processSubfeatureStatusOptions is map)

See callSubfeatureAndProcessStatus.

ParameterTypeAdditional Info
processSubfeatureStatusOptions map

Passed as the definition argument to processSubfeatureStatus. Setting subfeatureId in this map is not required, and will be ignored in favor of the subfeatureId passed into this function.

forEachEntity (context is Context, id is Id, query is Query, operationToPerform is function)

Iterate through all entities provided by a query, calling the provided function once for each geometric entity resolved by the provided query.

forEachEntity behaves much like the code:

const evaluated = evaluateQuery(context, query);
for (var i = 0; i < size(evaluated); i += 1)
{
    operationToPerform(id + i, evaluated[i]);
}

However, forEachEntity has one additional benefit: The entId this function provides to operationToPerform is tied to the entity itself, not its index i. This means that downstream features made in the Part Studio will hold up better across upstream changes.

For example, imagine the following scenario: A user inserts a custom feature which places a slot on every selected line. That feature calls forEachEntity(context, lineQuery ...). The user then makes a sketch downstream which uses geometry from e.g. the third slot. Finally, the user decides some slots are unnecessary and deletes some of the lines. Since the feature used forEachEntity, the user's downstream sketch will still reference the same slots. If the feature instead used the code above, the user's sketch would break or jump around, since a different slot would suddenly become "slot 3".

Aside from that difference, the two are interchangable.

Like any expression function, be warned that the provided operationToPerform can read but can NOT modify the values of variables outside the function. It can, however, modify values inside a box.

EXAMPLE

const allParts = qAllModifiableSolidBodies();
const threshold = 0.01 * inch^3;
var deletedSizes is box = new box([]); // box containing an empty array
forEachEntity(context, id + "deleteSmallParts", allParts, function(entity is Query, id is Id)
{
    const size = evVolume(context, {
            "entities" : entity
    });
    if (size < threshold)
    {
        opDeleteBodies(context, id + "deleteBodies1", {
                "entities" : entity
        });
        deletedSizes[] = append(deletedSizes[], size);
    }
});
println(deletedSizes[]);
ParameterTypeAdditional Info
operationToPerform function

EXAMPLE

function(entity is Query, id is Id)
{
    // perform operations with the entity
}

The first argument to this function is a query resolving to one single entity of the input query.

The second argument to this function is a unique id tied to the entity. By default it is named "id", which will shadow (i.e. take precedence over) the outer variable named "id". If you need access to that outer id, simply rename this argument to e.g. innerId.

setFeatureComputedParameter (context is Context, id is Id, definition is map)

Associates a FeatureScript value with a given string. This value can then be referenced in a feature name using the string. The provided value can be used in a feature name by including e.g. "#myValue" in the Feature Name Template.

ParameterTypeAdditional Info
definition map
  • name
string

EXAMPLE

myValue
  • value

getFullPatternTransform (context is Context) returns Transform

When in feature pattern scope returns composition of all pattern transforms pushed by setFeaturePatternInstanceData returns identity transform when out of scope

getRemainderPatternTransform (context is Context, definition is map) returns Transform

Making a feature work correctly with feature patterns is usually done with two functions: this one and transformResultIfNecessary.

Feature patterns work by first computing a sequence of transforms, one for each instance. For each transform, the pattern pushes it onto the pattern stack (using setFeaturePatternInstanceData), executes the patterned features, and then pops the transform off the stack (using unsetFeaturePatternInstanceData) before pushing the next one. The stack depth corresponds to the level of nesting of feature patterns. Feature authors are responsible for reading the pattern stack and transforming themselves accordingly.

The basic principle is that inside one feature pattern (as opposed to nested feature patterns), if any entities that the feature references come from a feature that is also being patterned, then the feature ignores the pattern transform. Otherwise, the feature uses the pattern transform in a "natural" way, applying it to an input, the output, or somewhere in between.

For example, suppose the patterned feature creates a 3D line between two arbitrary vertices. If the first vertex is also patterned, but not the second, then the result should be a bunch of lines from different instances of the first vertex to the unpatterned second vertex (this is accomplished by not applying any transform to the line). If neither vertex is patterned, the line should be transformed by the pattern transform and the result will be as expected, as if a body pattern of these lines was performed. Other features may need to apply the transform differently: for example, a sweep can transform the result of opSweep prior to the boolean, but an extrude needs to transform the profile prior to opExtrude to accommodate up-to-next correctly.

The general case is more complicated because feature patterns may be nested, and this function is designed to handle them. This function takes references, a query for everything the feature geometrically depends on (typically a qUnion of the queries in the feature definition), and computes the portion of the pattern transform that is not applied to any of the references and hence should be applied to the feature. For example, if one of the references is patterned by the current feature pattern or if there is no feature pattern, it will return the identity transform. If references evaluates to nothing, it will return the current feature pattern transform.

More precisely: Among references find topology created by pattern instance deepest in the pattern transform stack. If the transformation on the stack for that instance is S and the full transformation is F, the remainder R is such that R * S = F

A simple feature may use this function and transformResultIfNecessary as follows:

... // Feature definition boilerplate and precondition
    { // Feature body
        // Call getRemainderPatternTransform before performing any operations
        var remainingTransform = getRemainderPatternTransform(context, { "references" : definition.vertexToBuildOn });
        ... // Create a cube using definition.vertexToBuildOn as the reference location
        // Inside a feature pattern, the following will transform the cube if definition.vertexToBuildOn is not getting patterned:
        transformResultIfNecessary(context, id, remainingTransform);
        ... // Perhaps boolean the results to something in the context
    });
ParameterTypeAdditional Info
definition map
  • references
Query

transformResultIfNecessary (context is Context, id is Id, transform is Transform)

Applies transformation to bodies created by operation with id if transform argument is non-trivial

isAnything (value) predicate

A predicate which always returns true. Used to create a generic feature parameter that can be any featurescript expression.

Note that to change the user-visible default value, the "Default" annotation must be a string containing a valid parameter expression. For example, to make the default value the string "My string", pass in an escaped string: annotation{ "Default": "\"My string\"" }.

lastModifyingOperationId (context is Context, query is Query) returns Id

Returns id of operation that created or last modified the first entity to which query resolves.

Throws if query resolves to nothing.

startTracking (context is Context, arg is map) returns Query

Generates a tracking query, which will evaluate to entities derived from subquery in features between startTracking and when query is evaluated. If secondarySubquery is specified, the query would evaluate to entities derived from both objects. If trackPartialDependency is set to true, query would also include entities that are not exclusively derived from subquery1. Optional field lastOperationId can be used to specify the starting operation of tracking. Use example:

// "sketch1" constructs a polygon of "line0", "line1", etc.
var extrudedFromLine0 = startTracking(context, id + "sketch1", "line0");
extrudeOp(context, id + "extrude1", {"entities" : qSketchRegion(id + "sketch1",....});
var fromLine0 = evaluateQuery(context, extrudedFromLine0);
// fromLine0 contains a face and two edges (top and bottom) corresponding to line0 in the extrude.

startTracking (context is Context, subquery is Query) returns Query

startTracking (context is Context, sketchId is Id, sketchEntityId is string) returns Query

startTrackingIdentity (context is Context, subquery is Query) returns Query

Generates a tracking query, which will evaluate to the new entities inheriting the identity of subquery evaluation result.

makeRobustQuery (context is Context, subquery is Query) returns Query

Generates query robust to identity-preserving changes

makeRobustQueriesBatched (context is Context, subquery is Query) returns array

Generates array of robust queries for each entity of the subquery

setExternalDisambiguation (context is Context, id is Id, query is Query)

Used to set external disambiguation for operations with unstable component in id. The disambiguation will be applied to results of sub-operations which otherwise don't track dependency e.g. Sketch , opPlane, opPoint

ParameterTypeAdditional Info
id Id

ends in unstable component

verifyNonemptyQuery (context is Context, definition is map, parameterName is string, errorToReport is string) returns array

Throws a regenError and marks the specified Query parameter as faulty if the specified Query parameter is not a Query which resolves to at least one entity. This happens when the user has not made any selection into the Query parameter, or when upstream geometry has changed such that the Querys of the Query parameter no longer resolve to anything. Should be used to check all non-optional Query parameters in a feature. By convention, errorToReport should take the form "Select parameter display name." For example, a parameter declared as follows:

annotation { "Name" : "Entities to use", "Filter" : EntityType.FACE }
definition.entitiesToUse is Query;

should verify that the input is nonempty in the following way:

EXAMPLE

verifyNonemptyQuery(context, definition, "entitiesToUse", "Select entities to use.")
Return typeDescription
array

An array representing the result of evaluating the Query parameter with evaluateQuery

verifyNonemptyArray (context is Context, definition is map, parameterName is string, errorToReport is string)

Throws a regenError and marks the specified array parameter as faulty if the specified array parameter does not have any entries. A parameter declared as follows:

annotation { "Name" : "Array items", "Item name" : "Array item" }
definition.arrayItems is array;
for (var arrayItem in definition.arrayItems)
{
   ...
}

could verify that the input is nonempty in the following way:

EXAMPLE

verifyNonemptyArray(context, definition, "arrayItems", "Add an array item.")

verifyNoMesh (context is Context, definition is map, parameterName is string)

Verifies that the definition[parameterName] Query does not contain mesh or mixed entities. Throws a regenError if definition[parameterName] references mesh topologies.

verifyNoMeshInBody (context is Context, definition is map, parameterName is string)

Verifies no body containing the specified query contains any mesh.

ParameterTypeAdditional Info
context Context

The application context.

definition map

The feature definition.

parameterName string

The key of definition that will be accessed to find the query.

adjustAngle (context is Context, angle is ValueWithUnits) returns ValueWithUnits

Adjust angle out of bounds angles to lie in [0 to 2pi] if the feature is new, do a range check otherwise.

isButton (value) predicate

True if the value is undefined and creates a button parameter.

featureList

Support functions for feature lists (as used for featurePattern)

FeatureList type

Parameter type for inputting a list of features, stored as a map from feature Id to feature function. For an example, see the circularPattern module.

canBeFeatureList (value) predicate

Typecheck for FeatureList

featureList (features is map) returns FeatureList

Takes a map from id to lambda to return it as type FeatureList

valuesSortedById (context is Context, idToValue is map) returns array

Takes a context and a map whose keys are subfeature ids from that context. Returns the values from that map sorted in the order that the subfeatures were started.

flatOperationType

FlatOperationType enum

Types of flat operations supported by SMFlatOp

ValueDescription
ADD
REMOVE

formedUtils

setFormAttribute (context is Context, bodies is Query, attribute is string)

Attach the given FormAttribute to the bodies.

qBodiesWithFormAttribute (attribute is string)

Query for all bodies marked with a FormAttribute and value exactly equal to attribute

See also

setFormAttribute

qBodiesWithFormAttribute (queryToFilter is Query, attribute is string) returns Query

Query for all bodies in queryToFilter marked with a FormAttribute and value exactly equal to attribute

See also

setFormAttribute

qBodiesWithFormAttributes (queryToFilter is Query, attributes is array) returns Query

Query for all bodies in queryToFilter marked with a FormAttribute and value exactly equal to one of the attributes

See also

setFormAttribute

frameAttributes

FrameTopologyType enum

The possible types of a FrameTopologyAttribute.

ValueDescription
SWEPT_FACE

The side faces of a frame, swept from the edges of the profile

SWEPT_EDGE

The side edges of a frame, swept from the vertices of the profile

CAP_FACE

The start and end cap faces of a frame

FrameProfileAttribute type

An attribute attached to the frame profile and the constructed frame body which defines the default cutlist associated with the frame.

frameProfileAttribute (value is map) returns FrameProfileAttribute

Construct a FrameProfileAttribute.

getFrameProfileAttributes (context is Context, frames is Query)

Get all FrameProfileAttributes attached to the frames.

getFrameProfileAttribute (context is Context, frame is Query)

Get the FrameProfileAttribute attached to the frame. Throw if a single attribute is not found.

setFrameProfileAttribute (context is Context, frame is Query, attribute is FrameProfileAttribute)

Attach the given FrameProfileAttribute to the frame.

FrameTopologyAttribute type

An attribute assigned to certain faces and edges of the frames to aid in tracking the frame as it changes over the series of frame-altering features.

frameTopologyAttributeForSwept (topologyType is FrameTopologyType) returns FrameTopologyAttribute

Construct a FrameTopologyAttribute for SWEPT_* types.

See also

frameTopologyAttributeForCapFace

frameTopologyAttributeForCapFace (isStartFace is boolean, isFrameTerminus is boolean, isCompositeTerminus is boolean) returns FrameTopologyAttribute

Construct a FrameTopologyAttribute for CAP_FACE.

See also

frameTopologyAttributeForSwept

getFrameTopologyAttributes (context is Context, faces is Query)

Get all FrameTopologyAttributes attached to the faces.

getFrameTopologyAttribute (context is Context, face is Query)

Get the FrameTopologyAttribute attached to the face. Throw if a single attribute is not found.

setFrameTopologyAttribute (context is Context, entities is Query, attribute is FrameTopologyAttribute)

Attach the given FrameTopologyAttribute to each of the entities.

CutlistAttribute type

An attribute attached to the composite created by the Cutlist feature which contains the cutlist table for that composite.

cutlistAttribute (featureId is Id, table is Table) returns CutlistAttribute

Construct a CutlistAttribute.

getCutlistAttributes (context is Context, composites is Query)

Get all CutlistAttributes attached to the composites.

getCutlistAttribute (context is Context, composite is Query)

Get the getCutlistAttribute attached to the composite. Throw if a single attribute is not found.

setCutlistAttribute (context is Context, composite is Query, attribute is CutlistAttribute)

Attach the given CutlistAttribute to the composite.

setCustomFrameAlignmentPointAttribute (context is Context, pointsQuery is Query)

Sets an attribute on the sketch entity point queries for later discovery and use during frame creation.

getCustomFrameAlignmentPoints (context is Context, profileId is Id) returns Query

Finds the sketch points in the profileId sketch with the custom alignment point attribute.

holeUtils

HoleStyle enum

Defines whether each hole should have a countersink, a counterbore, or neither.

ValueDescription
SIMPLE
C_BORE
C_SINK

HoleProfile type

Describes a single profile for a HoleDefinition.

See also

holeProfile for standard circular profiles.

holeProfileBeforeReference for a circular profile meant to be used as the first profile of the hole.

matchedHoleProfile for a profile that geometrically matches the HolePositionReference.

ValueTypeDescription
HoleProfile map
  • positionReference
HolePositionReference

The reference along the hole axis to which this profile is relative.

  • beforeReference
boolean

Optional

Whether the position of the profile should reference the start or end of the given positionReference. See holeProfileBeforeReference for more detail. Default is false if not provided. Only considered when profileType is POSITIONED, ignored otherwise.

  • profileType
HoleProfileType

How the profile should be constructed in relation to the given positionReference

  • position
ValueWithUnits

Required if profileType is POSITIONED

The position of the profile along the hole axis, relative to the given positionReference.

  • radius
ValueWithUnits

The radius of the profile. Can be 0 to specify that the profile forms a point.

  • targetMustDifferFromPrevious
boolean

Optional

If true, instructs opHole to skip the construction of any holes in which the target referenced by this profile's positionReference is not different than the target reference by the previous profile's positionReference. Cannot be set to true on the first profile or any profile that does not have a different positionReference than the previous profile. Default is false.

  • notApplicableForFirstTarget
boolean

Optional

If true, instructs opHole to skip the profiles in which the target referenced by this profile's positionReference is not different than the target reference by the GBTHolePositionReference::TARGET_START. Cannot be set to true on the first profile Default is false.

  • name
string

Optional

A name for to assign to the edge created by opHole which corresponds to this profile. Supplying a name allows for the querying of profile edges by name when using qOpHoleProfile.

canBeHoleProfile (value) predicate

Typecheck for HoleProfile

holeProfile (positionReference is HolePositionReference, position is ValueWithUnits, radius is ValueWithUnits, optionalParameters is map) returns HoleProfile

Returns a new circular HoleProfile at a given position in relation to the end of the range of the positionReference. See HolePositionReference for further detail about the range of the positionReference.

ParameterTypeAdditional Info
optionalParameters map
  • targetMustDifferFromPrevious
boolean

Optional

See HoleProfile.

  • notApplicableForFirstTarget
boolean

Optional

See HoleProfile.

  • name
string

Optional

See HoleProfile.

holeProfile (positionReference is HolePositionReference, position is ValueWithUnits, radius is ValueWithUnits) returns HoleProfile

holeProfileBeforeReference (positionReference is HolePositionReference, position is ValueWithUnits, radius is ValueWithUnits, optionalParameters is map) returns HoleProfile

Returns a new circular HoleProfile at a given position in relation to the beginning of the range of the positionReference. See HolePositionReference for further detail about the range of the positionReference. This type of profile is useful as the first profile of a hole, such that if the hole cylinder intersects the first target at a slanted or otherwise irregular face, the first profile is backed up enough such that when the hole tool is subtracted from the target, there is no undesirable overhang left behind.

ParameterTypeAdditional Info
optionalParameters map
  • targetMustDifferFromPrevious
boolean

Optional

See HoleProfile.

  • notApplicableForFirstTarget
boolean

Optional

See HoleProfile.

  • name
string

Optional

See HoleProfile.

holeProfileBeforeReference (positionReference is HolePositionReference, position is ValueWithUnits, radius is ValueWithUnits) returns HoleProfile

matchedHoleProfile (positionReference is HolePositionReference, radius is ValueWithUnits, optionalParameters is map) returns HoleProfile

Returns a new HoleProfile that is geometrically matched to the positionReference. This is useful for configurations like blind-in-last, where a transition from one radius to another must be made that matches the shape of the position reference, to avoid the hole tool intersecting incorrectly with the part(s) in question. To form a valid HoleDefinition, MATCHED profiles must come in pairs of different radii.

ParameterTypeAdditional Info
optionalParameters map
  • targetMustDifferFromPrevious
boolean

Optional

See HoleProfile.

  • notApplicableForFirstTarget
boolean

Optional

See HoleProfile.

  • name
string

Optional

See HoleProfile.

matchedHoleProfile (positionReference is HolePositionReference, radius is ValueWithUnits) returns HoleProfile

HoleDefinition type

Describes the shape of a hole using a series of HoleProfiles.

See also

opHole

ValueTypeDescription
HoleDefinition map
  • profiles
array

An array of HoleProfiles which define the shape of the hole. The profiles are interpreted in order, from the top to the bottom of the hole. The final profile must have a radius of 0. Each profile must specify a unique name, or all of the profiles must leave their name field undefined. If two or more adjacent profiles in the list end up being identical (in the same position with the same radius) when their final placement is determined in opHole, the identical profiles will be collapsed into a single profile, which uses the name of the first of the identical profiles.

  • faceNames
array

Optional

A list of names to assign to the faces created by opHole. Should be the same length as the profiles array, where faceNames[i] is the name of the face created between profiles i - 1 and i, and faceNames[0] is the name of the top cap face (the face before profile 0). If any profiles are collapsed, the names of the faces between the collapsed profiles are skipped. Supplying faceNames allows for the querying of faces by name when using qOpHoleFace.

canBeHoleDefinition (value) predicate

Typecheck for HoleDefinition

holeDefinition (profiles is array, optionalParameters is map) returns HoleDefinition

Returns a new HoleDefinition.

ParameterTypeAdditional Info
optionalParameters map
  • faceNames
string

Optional

See HoleDefinition.

holeDefinition (profiles is array) returns HoleDefinition

instantiator

The instantiator makes it easy to efficiently bring in (possibly configured) bodies from other Part Studios and place them at specific positions and orientations. The usage pattern is generally as follows:

firstPartStudio::import(...);
secondPartStudio::import(...);
// later, in a feature
const instantiator = newInstantiator(id + "myId");
var firstQuery = addInstance(instantiator, firstPartStudio::build, {
                                 "configuration" : { "configurationInput" : configurationValue },
                                 "transform"     : transform(vector(1, 2, 3) * inch)
                             });
var secondQuery = addInstance(instantiator, secondPartStudio::build, {
                                  "configuration" : secondConfiguration,
                                  "transform"     : someOtherTransform,
                                  "mateConnector" : queryForMateConnectorInSecondPartStudio // Specifies the origin
                              });
// repeat the above as necessary
instantiate(context, instantiator); // This call actually brings in the bodies
// Now firstQuery and secondQuery will resolve to the instantiated geometry

Internally, the instantiator groups all added instances by Part Studio and configuration. The final call to instantiate() is optimized so that any duplicates of the same Part Studio and the same configuration are patterned instead of re-derived, resulting in better performance and scalability for features instantiating the same bodies multiple times.

Instantiator type

Stores the data associated with using instantiator functionality.

canBeInstantiator (value) predicate

Typecheck for Instantiator

newInstantiator (id is Id) returns Instantiator

Creates a new instantiator with the specified id and default options.

newInstantiator (id is Id, options is map) returns Instantiator

Creates a new instantiator.

ParameterTypeAdditional Info
id Id

The root id for all instances that will be created by this instantiator. Multiple instantiators can be used simultaneously, as long as they have different ids.

options map

Optional

  • partQuery
Query

Optional

The query for all bodies to be brought in from the part studios. Default is all bodies except sketches.

  • tolerances
map

Optional

The tolerances for variable configuration inputs. Default is 1e-8 meters for lengths, 1e-11 radians for angles, and 0 for numbers. The default tolerances for lengths, angles, and numbers can be specified using the (LENGTH_UNITS), (ANGLE_UNITS), and (unitless) keys, respectively. The tolerance for a specific configuration input can be specified using that input name as the key.

EXAMPLE

{ (LENGTH_UNITS) : 1e-4 * meter, (unitless) : 1e-8, "count" : 0 } causes length configuration variables that differ by less than 1e-4 meters to be considered identical, as well as numberical configuration variables that differ by less than 1e-8, except that configuration variables named "count" are compared exactly.

addInstance (instantiator is Instantiator, build is function, definition is map) returns Query

Adds an instance to the instantiator (does not actually create it in a context) with the given build function. The definition can specify the configuration, the transform, and how the result is identified.

ParameterTypeAdditional Info
definition map
  • configuration
map

Optional

The configuration of the part studio.

  • partQuery
query

Optional

A query which evaluates to bodies in new context, to be instantiated for this instance. If absent partQuery of instantiator is used. When present, overrides partQuery of the instantiator.

  • transform
Transform

Optional

The transform to be applied to the geometry.

  • mateConnector
Query

Optional

A query for all mate connectors from the part studio being instantiated, specifying its coordinate system.

  • mateConnectorId
Id

Optional

Creating feature Id of the mate connector used for transformation.

  • mateConnectorIndex
number

Optional

Index into the creating feature of the mate connector used for transformation.

  • name
string

Optional

The id component for this instance. Must be unique per instantiator. If it is not specified, one is automatically generated based on order. If it is specified, the query returned is qCreatedBy(id + name, EntityType.BODY), where id is the id that was passed into newInstantiator

  • identity
Query

Optional

If provided, specifies an entity whose identity controls the identity of the instance, so that queries for the instance can be robust. For example, if creating instances based on a layout sketch, one instance per line segment, the identity should be a query for the corresponding line segment.

  • loadedContext
Context

If a preloaded context is provided, use this context

Return typeDescription
Query

a query that will resolve to the bodies instantiated once instantiate is run.

addInstance (instantiator is Instantiator, partStudio is PartStudioData, definition is map) returns Query

Add an instance with the buildFunction, partQuery, and configuration of a PartStudioData value.

ParameterTypeAdditional Info
definition map
  • transform
Transform

Optional

The transform to be applied to the geometry.

  • mateConnector
Query

Optional

A query for a mate connector in the part studio being instantiated, specifying its coordinate system.

  • mateConnectorId
Id

Optional

Creating feature Id of the mate connector used for transformation.

  • mateConnectorIndex
number

Optional

Index into the creating feature of the mate connector used for transformation.

  • configurationOverride
map

Optional

If set, the values will be merged with the configuration set in partStudio, overriding any configuration inputs with matching keys.

  • name
string

Optional

The id component for this instance. Must be unique per instantiator. If it is not specified, one is automatically generated based on order. If it is specified, the query returned is qCreatedBy(id + name, EntityType.BODY), where id is the id that was passed into newInstantiator

  • identity
Query

Optional

If provided, specifies an entity whose identity controls the identity of the instance, so that queries for the instance can be robust. For example, if creating instances based on a layout sketch, one instance per line segment, the identity should be a query for the corresponding line segment.

  • loadedContext
Context

If a preloaded context is provided use this context

Return typeDescription
Query

a query that will resolve to the bodies instantiated once instantiate is run.

addInstance (instantiator is Instantiator, partStudio is PartStudioData) returns Query

Add an instance with the buildFunction, partQuery, and configuration of a PartStudioData value.

Return typeDescription
Query

a query that will resolve to the bodies instantiated once instantiate is run.

instantiate (context is Context, instantiator is Instantiator)

Create the instances (in the provided context) that were added to the instantiator

libraryValidation

LibraryValidationProblems type

A container for a list of distinct problems found when validating a part studio for use in a library

manipulator

A manipulator is an alternative, graphical UI for controlling a feature's definition. For example, in Onshape's extrude feature, the arrow which appears at the end of a blind extrusion is a manipulator controlling the depth parameter. A manipulator can be one of a few ManipulatorTypes, which are generally draggable arrows designed to control different degrees of freedom.

The manipulator is added inside the feature function, and will be rendered whenever that feature is being edited. Changes to a manipulator will be processed by a "Manipulator Change Function" associated with the feature.

A small example using a manipulator to control the depth and direction of an opExtrude is below:

annotation { "Feature Type Name" : "Fake extrude",
        "Manipulator Change Function" : "fakeExtrudeManipulatorChange" }
export const fakeExtrude = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Faces to extrude", "Filter" : EntityType.FACE }
        definition.faces is Query;
        annotation { "Name" : "My Length" }
        isLength(definition.depth, LENGTH_BOUNDS);
        annotation { "Name" : "Opposite direction", "UIHint" : UIHint.OPPOSITE_DIRECTION }
        definition.shouldFlip is boolean;
    }
    {
        var extrudePlane is Plane = evFaceTangentPlane(context, {
                "face" : definition.faces,
                "parameter" : vector(0.5, 0.5)
        });
        var extrudeManipulator is Manipulator = linearManipulator({
                "base" : extrudePlane.origin,
                "direction" : extrudePlane.normal,
                "offset" : definition.shouldFlip ? definition.depth : -definition.depth,
                "primaryParameterId" : "depth"
        });
        addManipulators(context, id, {
                "myManipulator" : extrudeManipulator
        });
        opExtrude(context, id + "extrude1", {
                "entities" : definition.faces,
                "direction" : definition.shouldFlip ? extrudePlane.normal : -extrudePlane.normal,
                "endBound" : BoundingType.BLIND,
                "endDepth" : definition.depth
        });
    }, {});
export function fakeExtrudeManipulatorChange(context is Context, definition is map, newManipulators is map) returns map
{
    var newDepth is ValueWithUnits = newManipulators["myManipulator"].offset;
    definition.depth = abs(newDepth);
    definition.shouldFlip = newDepth > 0;
    return definition;
}

The manipulator change function is responsible for changing the definition such that the feature will regenerate correctly. It may change the definition in any way, and need not be restricted to the pattern of one manipulator changing one parameter.

The feature function is only aware of the definition passed in; it makes no distinction about whether the definition was produced from a manipulator change, or by a change in the feature dialog, or by another custom feature.

Manipulator type

A Manipulator is a type which can be passed into addManipulators, containing the necessary information to position the manipulator in the context. Altered copies of these manipulators are passed into a manipulator change function as newManipulators.

Can be constructed with triadManipulator, linearManipulator, and other functions below.

canBeManipulator (value) predicate

Typecheck for Manipulator

triadManipulator (definition is map) returns Manipulator

Create a manipulator represented by a triad of perpendicular arrows, aligned with the world axes, which specify a 3D position. See transformCopy for an example.

ParameterTypeAdditional Info
definition map
  • base

The position of the manipulator when the offset is 0.

  • offset

The 3D position of the triad, relative to the base.

  • sources

Optional

For Onshape internal use.

fullTriadManipulator (definition is map) returns Manipulator

Create a manipulator represented by a triad of perpendicular arrows, planes, angular position handles, which specify 3D transform.

ParameterTypeAdditional Info
definition map
  • base

The coordinate system the manipulator is aligned with when transform is the identity transform. Default is WORLD_COORD_SYSTEM.

  • transform

The 3D transform of the triad, relative to the base coordinate system.

triadManipulator (base is Vector, offset is Vector, sources) returns Manipulator

Deprecated: Use triadManipulator(map)

linearManipulator (definition is map) returns Manipulator

Create a manipulator represented by a single arrow which can move along a single axis. See extrude for an example.

ParameterTypeAdditional Info
definition map
  • base

The position of the manipulator when the offset is 0.

  • direction

A 3D unit vector pointing on the axis on which the manipulator can be dragged.

  • offset

The positive or negative distance along direction from the base to the manipulator.

  • sources

Optional

For Onshape internal use.

  • minValue
ValueWithUnits

Optional

The minimum offset allowed.

  • maxValue
ValueWithUnits

Optional

The maximum offset allowed.

  • style
ManipulatorStyleEnum

Optional

  • primaryParameterId
string

Optional

The id of the definition field which is being manipulated. When set, the feature dialog focus will be shifted to the parameter in question when the manipulator is manipulated.

linearManipulator (base is Vector, direction is Vector, offset is ValueWithUnits, sources, style is ManipulatorStyleEnum) returns Manipulator

Deprecated: Use linearManipulator(map)

linearManipulator (base is Vector, direction is Vector, offset is ValueWithUnits, sources) returns Manipulator

Deprecated: Use linearManipulator(map)

linearManipulator (base is Vector, direction is Vector, offset is ValueWithUnits) returns Manipulator

Deprecated: Use linearManipulator(map)

angularManipulator (definition is map) returns Manipulator

Create a manipulator represented by a curved arrow which can move along a circumference to specify an angle, with the start and end of the rotation angle delimited by radial lines. See revolve for an example.

ParameterTypeAdditional Info
definition map
  • axisOrigin
Vector

The origin of the axis to rotate around.

EXAMPLE

project(axis, rotationOrigin)
  • axisDirection
Vector

The direction of the axis to rotate around.

EXAMPLE

axis.direction
  • rotationOrigin
Vector

Point at the tip of the revolve manipulator.

  • angle
ValueWithUnits

Current angle value of the manipulator.

  • sources

Optional

For Onshape internal use.

  • minValue
ValueWithUnits

Optional

The minimum angle allowed.

  • maxValue
ValueWithUnits

Optional

The maximum angle allowed.

  • style
ManipulatorStyleEnum

Optional

  • primaryParameterId
string

Optional

The id of the definition field which is being manipulated. When set, the feature dialog focus will be shifted to the parameter in question when the manipulator is manipulated.

  • disableMinimumOffset
boolean

Optional

Removes the minimum offset between the arrow and axisOrigin.

pointsManipulator (definition is map) returns Manipulator

A set of points which can be selected one at a time.

ParameterTypeAdditional Info
definition map
  • points
array

Array of 3d locations for points

  • index
number

The index of the currently selected point

togglePointsManipulator (definition is map) returns Manipulator

A series of points which can each be selected individually.

ParameterTypeAdditional Info
definition map
  • points
array

Array of 3d locations for points

  • selectedIndices
array

The indices of the currently selected points

  • suppressedIndices
array

The indices of any non-selectable points

flipManipulator (definition is map) returns Manipulator

Create a manipulator represented by a single arrow which flips direction when clicked.

ParameterTypeAdditional Info
definition map
  • base
Vector

A 3d point at the manipulator's origin

EXAMPLE

vector(0, 0, 0) * meter
  • direction
Vector

A 3d vector pointing in the unflipped direction

EXAMPLE

vector(0, 0, 1) points manipulator along the z axis
  • flipped
boolean

EXAMPLE

false points the manipulator along +direction

EXAMPLE

true points the manipulator along -direction, or otherDirection if defined
  • sources

Optional

For Onshape internal use.

  • style
ManipulatorStyleEnum

Optional

  • otherDirection
Vector

Optional

A 3d vector for the flipped direction

flipManipulator (base is Vector, direction is Vector, flipped is boolean, sources, style is ManipulatorStyleEnum) returns Manipulator

Deprecated: Use flipManipulator(map)

flipManipulator (base is Vector, direction is Vector, flipped is boolean, sources) returns Manipulator

Deprecated: Use flipManipulator(map)

flipManipulator (base is Vector, direction is Vector, flipped is boolean) returns Manipulator

Deprecated: Use flipManipulator(map)

addManipulators (context is Context, id is Id, manipulators is map)

Add a manipulator to this feature, which will be visible and interactable when a user edits the feature.

addManipulators should be called within the feature function, with the offset on the added manipulator set to match the state of the definition.

ParameterTypeAdditional Info
manipulators map

A map whose keys will match the keys of newManipulators (passed into the Manipulator Change Function), and whose values are the Manipulators to be added.

path

Path type

Represents a series of connected edges which form a continuous path.

ValueTypeDescription
Path map
  • edges
array

The edges that form this Path, in the order of the Path.

  • flipped
array

An array of booleans corresponding to each edge in the path, set to true to traverse the edge backwards.

  • closed
boolean

Whether the Path is a closed path.

  • adjacentFaces
Query

Optional

All adjacent faces on one side of the Path.

canBePath (value) predicate

Typecheck for Path

PathDistanceInformation type

Distance information returned by constructPath and evPathTangentLines when either function is provided with referenceGeometry

ValueTypeDescription
PathDistanceInformation map
  • distance
ValueWithUnits

The distance between the the start of the Path and the center of the bounding box of referenceGeometry, or infinity if referenceGeometry is empty

  • withinBoundingBox
boolean

Whether the start of the Path is within the bounding box of referenceGeometry, or false if referenceGeometry is empty

canBePathDistanceInformation (value) predicate

defaultPathDistanceInformation () returns PathDistanceInformation

Returns a PathDistanceInformation with distance set to infinity and withinBoundingBox set to false

reverse (path is Path) returns Path

Reverse the direction of a Path

ParameterTypeAdditional Info
path Path

the Path to reverse.

constructPath (context is Context, edgesQuery is Query) returns Path

Construct a Path from a Query of edges, picking the starting point of the path based on query evaluation order for edgesQuery

ParameterTypeAdditional Info
edgesQuery Query

A Query of edges to form into a Path. The edges are ordered with query evaluation order, so a qUnion should be used to ensure a stable ordering.

constructPath (context is Context, edgesQuery is Query, options is map) returns map

Construct a Path from a Query of edges, optionally picking the starting point as the closest viable starting point to the supplied referenceGeometry

ParameterTypeAdditional Info
edgesQuery Query

A Query of edges to form into a Path.

options map
  • referenceGeometry

Optional

A geometry Query to determine the start of the Path. If unspecified, (or the query is empty) the starting point of the path will be based on query evaluation order for edgesQuery.

  • tolerance
ValueWithUnits

Optional

Tolerance with length units indicating how close endpoints need to be to be considered part of the same path. Default is 1e-8 * meter

EXAMPLE

1e-5 * meter
ReturnTypeDescription
map
  • path
Path

The resulting constructed Path

  • pathDistanceInformation
PathDistanceInformation

A map containing the distance from the Path start point to the center of the bounding box of referenceGeometry and whether the Path start point falls inside that bounding box.

evPathLength (context is Context, path is Path) returns ValueWithUnits

Return typeDescription
ValueWithUnits

The total length of the Path.

evPathTangentLines (context is Context, path is Path, parameters is array) returns map

Return tangent lines to a Path using arc length parameterization.

ParameterTypeAdditional Info
path Path

The Path to use.

parameters array

An array of numbers in the range 0..1 indicating where along the Path to evaluate tangents.

ReturnTypeDescription
map
  • tangentLines
array

The tangent Lines corresponding to each parameter

  • edgeIndices
array

The indices of the edges in the Path corresponding to each parameter

evPathTangentLines (context is Context, path is Path, parameters is array, referenceGeometry) returns map

Return tangent lines to a Path using arc length parameterization. By default, the 0 parameter of the Path will be the start of the Path. If evaluating a closed path, providing reference geometry will alter the 0 parameter to be the closest point on the Path to the reference geometry. Providing reference geometry for a non-closed Path will not change the parameterization of the Path

ParameterTypeAdditional Info
path Path

The Path to use.

parameters array

An array of numbers in the range 0..1 indicating where along the Path to evaluate tangents.

referenceGeometry

A geometry Query to determine the 0 parameter of the Path, or undefined. If an empty Query or undefined is specified, the tangents will be evaluated starting at the beginning of the path.

ReturnTypeDescription
map
  • tangentLines
array

The tangent Lines corresponding to each parameter

  • edgeIndices
array

The indices of the edges in the Path corresponding to each parameter

  • pathDistanceInformation
PathDistanceInformation

A map containing the distance from the remapped 0 parameter to the center of the bounding box of referenceGeometry and whether the remapped 0 parameter falls inside that bounding box. Only valid if the path is closed.

getPathEndVertices (context is Context, path is Path) returns Query

Return query to end vertices of path if open or qNothing if closed.

ParameterTypeAdditional Info
path Path

The Path to use.

patternCommon

PatternType enum

The type of pattern.

ValueDescription
PART

Creates copies of bodies.

FEATURE

Calls a feature function multiple times, first informing the context of the transform to be applied.

FACE

Creates copies of faces and attempts to merge them with existing bodies.

MirrorType enum

The type of mirror.

See also

PatternType

ValueDescription
PART
FEATURE
FACE

patternUtils

applyPattern (context is Context, id is Id, definition is map, remainingTransform is Transform)

Applies the body, face, or feature pattern, given just transforms and instance names

ParameterTypeAdditional Info
definition map
  • patternType
PatternType
  • entities
Query

Required if patternType is not FEATURE

The faces or parts to pattern.

  • instanceFunction
FeatureList

Required if patternType is FEATURE

The features to pattern.

  • transforms
array

An array of Transforms in which to place new instances.

  • instanceNames
array

An array of the same size as transforms with a string for each transform, used in later features to identify the entities created.

properties

Properties include name, appearance, material, and part number (see PropertyType). They can be set in FeatureScript, but not read.

setProperty (context is Context, definition is map)

Sets a property on a set of bodies and/or faces. The allowed properties are listed in PropertyType. Only APPEARANCE and NAME properties are supported for faces.

Note: Any properties set in this way will be overridden if they are set directly in the Part Studio (via "Rename", "Set appearance", or the properties dialog). In that case the property value provided in FeatureScript will become shadowed. For example, if a part number is set in a custom feature based on the configuration, manually editing the part number from the properties dialog will override the custom feature's part number for all configurations.

ParameterTypeAdditional Info
definition map
  • entities
Query

The bodies and/or faces to apply the property to.

  • propertyType
PropertyType

The property to set.

EXAMPLE

PropertyType.APPEARANCE to change the part appearance.
  • customPropertyId
string

Required if propertyType is CUSTOM

The id of the custom property. The property id is available from your company's custom properties page. Note that this call performs no checks as to whether the custom property value is valid, so invalid property values may be recorded.

  • value

A Color if the propertyType is APPEARANCE, a Material if it is MATERIAL, a boolean if it is EXCLUDE_FROM_BOM, a value with mass units if it is MASS_OVERRIDE, and a string otherwise. The value should be a string for a CUSTOM property even if the property is of a non-string type.

EXAMPLE

color(1, 0, 0) to make the part red.

getProperty (context is Context, definition is map)

NOTE: This function cannot be called inside custom features. It can only be called from table functions, editing logic, and manipulator change functions. Getting properties in custom features is not possible, since features are regenerated before any user-set properties are applied.

Returns the value of a property of a single body, which can be either an Onshape property (allowed properties listed on PropertyType) or a custom property defined in company settings.

The returned value's type will correspond to the property type: A Color if the propertyType is APPEARANCE, a Material if it is MATERIAL, a boolean if it is EXCLUDE_FROM_BOM, and a string otherwise. CUSTOM property's returned value will always be a string, even if the custom property is of a non-string type.

ParameterTypeAdditional Info
definition map
  • entity
Query

A single body the property applies to.

  • propertyType
PropertyType

The property to get.

EXAMPLE

PropertyType.NAME to get the body's name
  • customPropertyId
string

Required if propertyType is CUSTOM

The id of the custom property. The property id is available from your company's custom properties page.

Color type

Represents a color as red, green, blue, and alpha transparency components, each between 0 and 1 (inclusive).

canBeColor (value) predicate

Typecheck for Color

color (red is number, green is number, blue is number, alpha is number) returns Color

Create a Color from RGBA values, each between 0 and 1 (inclusive)

color (red is number, green is number, blue is number) returns Color

Create an opaque Color from RGB values, each between 0 and 1 (inclusive)

Material type

Represents a material.

canBeMaterial (value) predicate

Typecheck for Material

material (name is string, density is ValueWithUnits)

Constructs a material with a name and a density.

ParameterTypeAdditional Info
name string

The displayed name of the material.

density ValueWithUnits

EXAMPLE

19.3 * gram / centimeter ^ 3

string

Pretty printing and toString methods

toString (value) returns string

Return a string representation of any value.

Overloads of this method are found for many standard and custom types in this and other modules. When overloaded, the toString method will be called inside print and println, allowing users to change how custom types are printed.

toString (value is string) returns string

toString (value is array) returns string

toString (value is map) returns string

Print a message to the FeatureScript notices pane.

This has no effect on model state or rendering.

println (value)

Print a message to the FeatureScript notices pane, followed by a newline.

This has no effect on model state or rendering.

printl