I accumulate a lot of weird and niche knowledge about Onshape and FeatureScript in the course of my work. This is no exception. Honestly, this blog article isn't even for you; its for me. I know that 2 years from now, I will run into this exact same issue and have forgotten the solution. Instead of writing internal docs, I figure, might as well share with the world on the off chance this helps someone else.
Today I figured out that newSketchOnPlane has a hidden parameter: "planeReference". Used like so:
var sketch = newSketchOnPlane(context, id + "sketch1", {
"sketchPlane" : plane(vector(0, 0, 0) * inch, vector(0, 0, 1)),
"planeReference" : referenceFace
});
Where referenceFace is a query for a face.
But why would you need this? The sketchPlane parameter already fully defines the sketch plane? What good could it do? The answer is: Sheet metal things.
See, sheet metal in Onshape is - weird, especially sheet metal with FeatureScript. A sketch made with newSketchOnPlane cannot then be used with the extrude feature to make tabs or holes in a flat pattern because its "in the 3D space". Onshape throws an error.
But when you, the user, select a flat pattern face as the plane for a sketch feature, the sketch appears in the sheet metal context! But how? I'm not entirely sure, but by providing a face that is in the flat domain, your sketch appears there. This parameter is how you can both have your sketch appear in the flat domain and set the exact origin of it. Useful for making things like tabs that need to be on bends.
Combine with qCorrespondingInFlat and you too can have some sheet metal FeatureScript fun.
Kommentare