The first operation will extrude the sketch edge.
In the feature's body, type 'opExtrude
', and select the autocompletion for the opExtrude
function.
This will insert the following code:
NOTE
Functions in the standard library with the '
op
' prefix are
operations. These functions all perform some change to the context which modifies its geometry.
Often, there will also be a feature function which calls the operation (in the case of extruding, the extrude
feature calls the opExtrude
function). The feature is wrapper which provides a nice Part Studio interface on top of that operation, sometimes with additional operations (for instance, the extrude
includes additional parameters to optionally add a boolean and a draft). In FeatureScript, it's often a better idea to call the operation directly.
After insertion, you should see the parameter 'context
' highlighted. This is the Context
, a data structure which contains all geometry in the Part Studio. Almost always, your features will involve a single Context
named 'context
', passed in from the Part Studio. Here, we pass it on to the extrude
function so that extrude
can create geometry in the Part Studio.
The default autocompletion of 'context
' makes sense, so leave it.
With the tab key or the mouse, select the next parameter: id + 'extrude1'
. This is the Id
, a unique identifier for the extrude operation being performed.
The default Id
is already unique and descriptive, so leave it.
NOTE
An
Id is a hierarchical identifier for a specific operation or feature. When the Part Studio creates a slot feature, a unique
Id
, named '
id
', is passed in. Each slot feature created will have a different unique id.
The expression id + 'extrude1'
creates a sub-id of this feature's id
. We use the sub-id to label this specific invocation of the extrude
feature. Thus, each instance of a slot will contain an instance of an extrude, all labeled uniquely (idForSlot1 + 'extrude1'
, idForSlot2 + 'extrude1'
, etc.).
As we will see soon, any Id
can be used in a later operation to specify the geometry created by the feature or operation with that id. This will include any geometry created by sub-ids.
Select the text next to the 'entities'
field. This field defines what geometry should be extruded. We want to extrude the sketch edge passed in. This edge is stored on on the definition
as slotPath
, as we defined in the precondition.
Change the entities field to definition.slotPath
:
Select the text next to the 'direction'
field. This field defined what direction to extrude in. We want this feature to extrude the surface perpendicular to the sketch normal.
The default autocompletion makes a call to the evOwnerSketchPlane
get the correct direction vector. We want to do the same, but instead evaluate the owner sketch of the slotPath
.
NOTE
Functions from the standard library with the '
ev
' prefix are
evaluations. These functions all obtain data and/or measurements from the entities inside a context.
The result of an evaluation function is a value which can be used in subsequent calculations. For instance, evOwnerSketchPlane
returns a value with type Plane
. A Plane
has the information define its position and orientation in 3D space, including a 3D unit Vector
defining the plane's normal direction. Above, we use this normal
field above as the extrude direction.
Press tab to select the text next to the 'endBound'
field. This field specifies a BoundingType
: one of BLIND
, SYMMETRIC
, THROUGH_ALL
, etc.
Change the endBound to 'BoundingType.THROUGH_ALL
':
Press tab to select the text next to the 'depth'
field. Since we've chosen a THROUGH_ALL
extrude, this field isn't necessary.
Delete the entire depth parameter:
In its place, we will specify that the start bound of the extrude should also be THROUGH_ALL
.
This addition gives us some extra robustness in making sure the slot cuts properly. In the one instance we've made in a Part Studio, we defined the slot sketch on the bottom surface of the part, so the sketch normal points directly into the part. However, we want this feature to still work if a user puts a sketch on the top surface, or in the center, or even off of the part.
Add the field 'startBound' : BoundingType.THROUGH_ALL
as the last field in the extrude call:
Press the commit button. At this point, your FeatureScript notices panel should be free of errors.
If you switch back to the Part Studio, you should see a surface extruded from the edge in your slot feature in two directions:
The next operation will thicken the surface to the slot width.
After the extrude
call, type and select the autocompletion for opThicken
. This will insert the following code:
For this operation, the context
should be left as 'context
', as usual. The Id
default of 'id + 'thicken1'
' is unique and descriptive, so leave that too.
The 'entities'
should specify the surface to thicken. Specify a query for the surface we just created using qCreatedBy
, passing in the id of the first extrude:
NOTE
A
Query, like
qCreatedBy
, is a way to refer to topological entities (vertices, edges, faces, and bodies) in FeatureScript.
You can think of a query as an order form for entities, with one or more criteria that the specified entities must satisfy. The query itself does not contain the entities. Rather a query specifies a set of entities in a context (remember: the context contains all the geometry). When you pass a query into an operation function, that function uses the query and the context to perform the operation on the right entities.
Other examples of queries are the two query parameters you've defined: slotPath
and partToCut
. These queries are generated automatically when a user selects entities, and stored in the fields definition.slotPath
and definition.partToCut
. The generated queries refer to the selected entities in a robust way so that features can be resistant to upstream changes. For instance, if a user selects an edge on the cap face of an extrude, then later flips the direction of that extrude, they'll find the downstream feature now has the same edge selected on the opposite side of the extrude, as expected.
A query may evaluate to zero, one, or many entities. To see all the queries FeatureScript has available, refer to the Query module.
thickness1
and thickness2
specify how much to thicken on each side of the surface. Let's make the slot symmetric, and thicken each side by half the slot width:
Press the commit button. In your Part Studio, you should see the thickened surface: a new solid body in your Context
.