Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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_HeskethLee_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? 
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!

Comments

  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    Hi Lee, how far have you got?  Which bit are you stuck on? 
    Also have you done the Featurescript slot tutorial?  It covers a lot of what you'll need for your script.

    Cheers, Owen S
    Business Systems and Configuration Controller
    HWM-Water Ltd
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    I had a look at it and I tried to do a simple extrude but it didn't work.
    Here is the code:

    FeatureScript 392;
    import(path : "onshape/std/geometry.fs", version : "392.0");

    annotation { "Feature Type Name" : "My Feature" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Face", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
            definition.face is Query;

            annotation { "Name" : "Part", "Filter" : EntityType.BODY && BodyType.SOLID, "MaxNumberOfPicks" : 1 }
            definition.Part is Query;

            annotation { "Name" : "Depth" }
            isLength(definition.depth, LENGTH_BOUNDS);


        }
        {
            var face = definition.face;

            var depth = definition.depth;


            opExtrude(context, id + "extrude1", {
                        "entities" : face,
                        "direction" : evOwnerSketchPlane(context, { "entity" : face }).normal,
                        "endBound" : BoundingType.BLIND,
                        "endDepth" : depth * centimeter
                    });

        });
    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!
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    What is your work flow process? That will also help determine how to write your script.
    Digital Engineering
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    Well for the script I posted, I was following the slot FeatureScript tutorial and modifying it to extrude a certain distance that the user inputs. It didn't work and I don't know why.
    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!
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Okay, I am trying to work on it and I have it working with one sketch. 
    The problem I am having is I can't seem to get the 'extrudeCut' to work in both directions....


    Digital Engineering
  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    @LeeH Welcome to FeatureScript! Overall, your tenon joint feature sounds like something FeatureScript should be very capable of doing.

    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.

  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    I deleted the centimeter unit and still no luck. In the part studio, it simply says is did not regenerate properly cannot resolve plane.
    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.
    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!
  • lemon1324lemon1324 Member, Developers Posts: 225 EDU
    The "Cannot resolve plane" is because in line 27 you're calling evOwnerSketchPlane on a non-sketch object; asking for the sketch plane to which the face belongs doesn't make sense in this case.

    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.



    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    I did all you said to do but it is throwing the error 
    Precondition of evPlane failed (arg.face is Query)
    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!
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,215
    What this error is telling you is that when you call evPlane, somewhere in the second argument you need to have
    "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).
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    Hi guys, thanks for all the help but I still can't get it to work. It's very frustrating. I tried following the slot feature, but the opExtrude part in the video seems outdated, because there appears to be no "direction" section. Now this error shows up.
    @opExtrude: Expected vector (a non-empty array), value is MAP
     Sorry for all the hassle, I have been using FeatureScript for a day and I have made no progress, still confused and have no idea what I'm doing. Whole document including code:
    https://cad.onshape.com/documents/51a4ed191be8c3b458ce259f/w/847ee03f2e14af8f13ce60dc/e/d25738af38b0c07077d16456

    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!
  • lemon1324lemon1324 Member, Developers Posts: 225 EDU
    Looks like you resolved that error; the current error is "Precondition of evOwnerSketchPlane failed (arg.entity is Query)" which is telling you that the argument you're passing is not a Query (you can't pass a sketch to evOwnerSketchPlane, line 48). Since it's a sketch you created, you don't need to evaluate evOwnerSketchPlane, you can just directly use the normal of the sketch plane (pointFace in your code) to define the extrude.

    <div>opExtrude(context, id + "extrude1", { <span><pre class="CodeBlock"><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "entities" : face, <span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "direction" : pointFace.normal, </span><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endBound" : BoundingType.BLIND, </span><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "endDepth" : depth </span><span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });</span>
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    @lemon1324 Thank you so much, it works! If I may ask one more thing, when using skRectangle(), how could I use the length parameters used in the precondition as vector coordinates? Also, it appears the feature results in a tenon that is a separate part. This is not what I wanted, do you know how to fix it?
    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!
  • Dylan_StewartDylan_Stewart Member, Developers Posts: 107 PRO
    Are you wanting to a 'project geometry' from one part to the other? 
    Digital Engineering
  • owen_sparksowen_sparks Member, Developers Posts: 2,660 PRO
    @LeeH

    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 enum

    Defines 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) .

    ValueDescription
    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.

    Regards, Owen S.






    Business Systems and Configuration Controller
    HWM-Water Ltd
  • lemon1324lemon1324 Member, Developers Posts: 225 EDU
    @LeeH to get things with units into a vector for skRectangle, just don't multiply by the unit afterwards
    e.g.
    var minCorner = vector(definition.width, definition.height)
    where definition.width and .height already have units.
    Arul Suresh
    PhD, Mechanical Engineering, Stanford University
  • Lee_HeskethLee_Hesketh Member, Developers Posts: 148 ✭✭✭
    @lemon1324 and @owen_sparks
    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.
    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!
Sign In or Register to comment.