Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:
- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
FS generated sketch to be accessible in Asseblies
MakotoNinja
Member Posts: 6 EDU
Aloha All,
I am trying to write a FS that generates a sketch that is accessible from within Assemblies. What I am seeing is that a feature is generated with the sketch I have devised but this "sketch" isn't available to insert into an Assembly. Is there a way to create a sketch in FS that shows up as an actual sketch instead of a feature?
The first feature in the following image shows the sketch as generated by FS and the second feature in the list is a vanilla sketch created with the sketch button. Only the latter is available to insert into an Assembly.

I am new to FS but not new at programming. My code is as follows:
I am trying to write a FS that generates a sketch that is accessible from within Assemblies. What I am seeing is that a feature is generated with the sketch I have devised but this "sketch" isn't available to insert into an Assembly. Is there a way to create a sketch in FS that shows up as an actual sketch instead of a feature?
The first feature in the following image shows the sketch as generated by FS and the second feature in the list is a vanilla sketch created with the sketch button. Only the latter is available to insert into an Assembly.

I am new to FS but not new at programming. My code is as follows:
FeatureScript 1993;
import(path : "onshape/std/common.fs", version : "1993.0");
const BOUNDS = {(unitless) : [10, 100, 1e5]} as IntegerBoundSpec;
annotation { "Feature Type Name" : "Axes" }
export const axes = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// Define the parameters of the feature type
annotation
{
"Name" : "Sketch Plane",
"Filter" : EntityType.FACE,
"MaxNumberOfPicks" : 1
}
definition.sketchPlane is Query;
annotation
{
"Name" : "Diameter",
"UIHint" : [UIHint.SHOW_LABEL, UIHint.REMEMBER_PREVIOUS_VALUE],
"Description" : "Set the diameter of the circle"
}
// isLength(definition.radius, LENGTH_BOUNDS);
isInteger(definition.diameter, BOUNDS);
}
{
var diameter = definition.diameter;
var splane = definition.sketchPlane;
// Define the function's action
var sketch1 = newSketch(context, id + "sketch1", {
"sketchPlane" : splane
});
skCircle(sketch1, "circle1", {
"center" : vector(0, 0) * millimeter,
"radius" : (diameter / 2) * millimeter,
"construction" : true
});
skLineSegment(sketch1, "line1", {
"start" : vector(-diameter / 2, 0) * millimeter,
"end" : vector(diameter / 2, 0) * millimeter,
"construction" : true
});
skLineSegment(sketch1, "line2", {
"start" : vector(0, diameter / 2) * millimeter,
"end" : vector(0, -diameter / 2) * millimeter,
"construction" : true
});
skSolve(sketch1);
});
Tagged:
1
Comments
-
I'd like this too. Is there an improvement request?
0 -
I just checked to confirm that FS generated sketch edges can be included in composite parts. So I threw an extra few lines onto your script to wrap the sketch into a new composite part. This part can be put into an assembly.
EDIT: forgot to add the changed code:
FeatureScript 1993; import(path : "onshape/std/common.fs", version : "1993.0"); const BOUNDS = {(unitless) : [10, 100, 1e5]} as IntegerBoundSpec; annotation { "Feature Type Name" : "Axes" } export const axes = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type annotation { "Name" : "Sketch Plane", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 } definition.sketchPlane is Query; annotation { "Name" : "Diameter", "UIHint" : [UIHint.SHOW_LABEL, UIHint.REMEMBER_PREVIOUS_VALUE], "Description" : "Set the diameter of the circle" } // isLength(definition.radius, LENGTH_BOUNDS); isInteger(definition.diameter, BOUNDS); } { var diameter = definition.diameter; var splane = definition.sketchPlane; // Define the function's action var sketch1 = newSketch(context, id + "sketch1", { "sketchPlane" : splane }); skCircle(sketch1, "circle1", { "center" : vector(0, 0) * millimeter, "radius" : (diameter / 2) * millimeter, "construction" : true }); skLineSegment(sketch1, "line1", { "start" : vector(-diameter / 2, 0) * millimeter, "end" : vector(diameter / 2, 0) * millimeter, "construction" : true }); skLineSegment(sketch1, "line2", { "start" : vector(0, diameter / 2) * millimeter, "end" : vector(0, -diameter / 2) * millimeter, "construction" : true }); skSolve(sketch1); // Composite parts can't contain sketch bodies, so copy each sketch edge // into a standalone wire body first. Edges are extracted one at a time // because opExtractWires fails when edges cross or 3+ meet at a point // (the lines cross at the center and touch the circle at their ends). for (var entityId in ["circle1", "line1", "line2"]) { opExtractWires(context, id + "wires" + entityId, { "edges" : sketchEntityQuery(id + "sketch1", EntityType.EDGE, entityId) }); } opCreateCompositePart(context, id + "compositePart", { "bodies" : qCreatedBy(id + "wires", EntityType.BODY), "closed" : true }); });2


