A Few More Undocumented FeatureScript Functions
- Caden Armstrong

- 10 hours ago
- 2 min read
In my previous post Hidden FeatureScript Functions, I talk about a few hidden functions within FeatureScript and show how they can be used. I'm back with a few more examples. All the example code can be seen here
Want to get the most out of Onshape? SmartBench Software can help.
Visit www.smartbenchsoftware.com to learn about our custom feature and integration development services.
Construct Paths
Construct Path is very useful, but what if it was even more useful?
constructPaths(context is Context, edgesQuery is Query, options is map) returns array
edgesQuery | query | A query of edges to form into a Path |
options | map | a map containing the options for the construct paths |
options.adjacentSeedFaces | (optional) query | If adjacent faces to the path are provided, each Path returned will include an 'adjacentFaces' property that has all faces on the same side of the path as the seed faces. If there are seed faces on both sides, constructPaths will error |
The first step to using construct paths is to import path.fs like so:
import(path : "onshape/std/path.fs", version : "2837.0");The difference between constructPath and constructPaths is that constructPath is expecting all of the edges to join into a single continuous path. The undocumented variant can handle multiple groups of edges that resolve into multiple paths. This can be helpful if you have a query of edges and need to separate them into multiple groups. Note that this function still does not allow for branching paths.
Cosmetic Threads
Cosmetic threads are something that the hole feature in Onshape can do, but you can actually add them to any cylindrical surface with the right attribute.
Start by importing the std utilities
import(path : "onshape/std/cosmeticThreadUtils.fs", version : "2837.0");Start with the function createCosmeticThreadDataFromEntitiy to generate the object.
function createCosmeticThreadDataFromEntity(threadCoordSys is CoordSystem, tappedDepth is number, threadPitch is number)Where threadCoordSys is a coordsystem starting where the thread should start, centered on the axis of the cylindrical face, with the Z direction in the direction of the threads.
Then use addCosmeticThreadAttribute to insert the data onto the face
function addCosmeticThreadAttribute(context is Context,entities is Query,cosmeticThreadData is CosmeticThreadData)Bringing it all together:
var coord = evSurfaceDefinition(context, {
"face" : definition.face
}).coordSystem;
var threadData = createCosmeticThreadDataFromEntity(coord, 10*millimeter/meter, 1*millimeter/meter);
addCosmeticThreadAttribute(context, definition.face, threadData);
Why am I doing millimeter/meter? Well, for some reason the cosmetic thread data is unitless and the value is forced to be in meters. Taking your value with units and dividing by meters will produce the correct result. And with that I can add cosmetic threads to any cylindrical surface. This can be useful for things like custom hydraulic port features or lids.



Comments