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.
Tenon Joint FeatureScript help
Lee_Hesketh
Member, Developers Posts: 148 ✭✭✭
Hello, I have been trying to create a feature that creates a tenon joint. What I want it to do is first the user selects a face, then a new sketch is created at the centre of that face. I have defined four variables, thickness, height, depth and face. The thickness and height variables will be used to draw a rectangle on the new sketch. Then, an extrude feature is used to remove everything apart from the rectangle at the depth of the depth variable.
I cannot get this to work because I have been using FeatureScript for and hour and a half so I am a complete novice. How should I go about this?
I cannot get this to work because I have been using FeatureScript for and hour and a half so I am a complete novice. How should I go about this?
There are 10 types of people in the world. Those who know binary, those who don't and those who didn't expect base 3!
0
Comments
Also have you done the Featurescript slot tutorial? It covers a lot of what you'll need for your script.
Cheers, Owen S
HWM-Water Ltd
Here is the code:
The problem I am having is I can't seem to get the 'extrudeCut' to work in both directions....
Just looking, your opExtrude is probably failing because depth has the wrong units. definition.depth already has length units (and the user will type something like "3 in" in that field), so when you multiply by centimeter, you're giving it area units, which opExtrude doesn't know how to deal with.
The fix is probably to just delete " * centimeter" from the depth parameter in your script.
Also, in the future, posting a link to a public document or a screenshot of the error flyout in the Part Studio will let people identify your issues faster. Some of the errors reported by FeatureScript can at first be hard to identify, but for people who are used to looking at them, its often trivial for kind souls on the forums to point out the issue.
link: https://cad.onshape.com/documents/51a4ed191be8c3b458ce259f/w/847ee03f2e14af8f13ce60dc/e/d25738af38b0c07077d16456
Feature studio 2 is the one with the simple extrude. The other is the whole script which also doesn't work.
Replacing that with evPlane() makes the feature work, as evPlane takes any flat face as input.
At a glance you have the same problem in the full feature, as well as the doubled units problem @kevin_o_toole_1 mentioned above. As an aside, line 48 of FS1 is probably more idiomatic with a call to skRectangle rather than polyline.
PhD, Mechanical Engineering, Stanford University
"face" : queryForFaceWhosePlaneYouWant
So the cause of one of two things: either you don't have a "face" entry at all or you have one but the thing to the right of "face" is not a query (it could be an array or some geometry or something else -- we'd need to see the rest of the code to tell).
https://cad.onshape.com/documents/51a4ed191be8c3b458ce259f/w/847ee03f2e14af8f13ce60dc/e/d25738af38b0c07077d16456
<div>opExtrude(context, id + "extrude1", { <span><pre class="CodeBlock"><code> "entities" : face, <span> "direction" : pointFace.normal, </span><span> "endBound" : BoundingType.BLIND, </span><span> "endDepth" : depth </span><span> });</span>
PhD, Mechanical Engineering, Stanford University
With regard to the new part for the tenon the "extrude" as oposed to the opExtrude" has the following parameter:-
<span>operationType as </span>
NewBodyOperationType enumDefines how a new body from a body-creating feature (extrude, revolve, etc.) should be merged with other bodies in the context.
To include this enum with the same styling as the extrude dialog (and others), use
booleanStepTypePredicate(definition)
.NEW
Creates a new body in the context with the geometry resulting from the operation.
ADD
Performs a boolean union between the new body and all bodies in the merge scope.
REMOVE
Performs a boolean subtraction of the new body from all bodies in the merge scope.
INTERSECT
Performs a boolean intersection between each new body and each body in the merge scope.
HWM-Water Ltd
e.g. where definition.width and .height already have units.
PhD, Mechanical Engineering, Stanford University
Thank you both for the information, everything now works as it should! It's taken a while but I finally got it.
I ended up sticking with the opExtrude() and simply included an opBoolean() afterwards, which suffices.