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.

Options

Extruding up to face - Why wont this work?

matthew_rochematthew_roche Member Posts: 8 ✭✭
edited November 2020 in FeatureScript
Hi Guys,  Loving feature script but I am new to it.  Hope this is not too much of a Noob question. 

I am trying to extrude a rectangle in a sketch on a face of a rectangular part to extrude out to the 'opposing' face.  I have tried a multitude of ways to do this without any success.  My last try which looks like it should work is below in full but I get EXTRUDE FAILED error in the feature script notices.  Note it is part of a bigger script,  I just pulled out the problem area for clarity.  What Am I doing wrong?  Any help would be much appreciated.
</code>FeatureScript 1403;
import(path : "onshape/std/geometry.fs", version : "1403.0");

annotation { "Feature Type Name" : "Adder" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            
            /* Select a Face and an Edge to add a bump onto using a sketch */
            annotation { "Name" : "face to AddTo", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
            definition.SlotFace is Query;
            annotation { "Name" : "Edge to Bump", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
            definition.SlotEdge is Query;     
        }
        {
            
            /* Find the  the plane for my sketch */
            var endPoints is Query = qAdjacent(definition.SlotEdge, AdjacencyType.VERTEX, EntityType.VERTEX);
            var startPosition is Vector = evVertexPoint(context, {
            "vertex" : qNthElement(endPoints, 0)
            });
            var endPosition is Vector = evVertexPoint(context, {
                    "vertex" : qNthElement(endPoints, 1)
            });
            var xDirection is Vector = normalize(endPosition - startPosition);
            var zDirection is Vector = evPlane(context, {
                    "face" : qNthElement(definition.SlotFace, 0)
            }).normal;
            var cSys is CoordSystem = coordSystem(startPosition, xDirection, zDirection);
            var sketchPlane is Plane = plane(cSys);
            
            
            /* Draw a rectangle that extends 50mm beyond the edge on the face of my extrude */
            var sketch1 = newSketchOnPlane(context, id + "sketch1", {
                    "sketchPlane" : sketchPlane
            });
            var BumpHeight is ValueWithUnits = norm((endPosition - startPosition)/2);    
            skRectangle(sketch1, "rectangle1", {
                    "firstCorner" :  vector(0 * millimeter,    -50 * millimeter),
                    "secondCorner" : vector(BumpHeight, 50 * millimeter)
            });
            skSolve(sketch1);
            
            /* get the opposite face to my sketch face to extrude up to */
            var regionToExtrude = qContainsPoint(qSketchRegion(id + "sketch1"), cSys.origin);
            var FaceBody1 = qOwnerBody(qNthElement(definition.SlotFace, 0));
            var ParallelFaces =  qFacesParallelToDirection(qOwnedByBody(FaceBody1, EntityType.FACE), xDirection);
            debug(context,qNthElement(ParallelFaces, 1));
            
            /* Extrude to create my bump */
            opExtrude(context, id + "extrude1", {
                    "entities" : regionToExtrude,
                    "direction" : evOwnerSketchPlane(context, {"entity" : regionToExtrude}).normal,
                    "endBound" : BoundingType.UP_TO_FACE,
                    "endBoundEntity" : qNthElement(ParallelFaces, 1), //Hardcoded the opposite face for this example
                    "startBound" : BoundingType.UP_TO_FACE,
                    "startBoundEntity" : qNthElement(ParallelFaces, 1) //Hardcoded the opposite face for this example<br>
            });
            
            /* Add it all up to one part */
            opBoolean(context, id + "boolean1", {
                  "tools" : qCreatedBy(id + "extrude1", EntityType.BODY),
                  "targets" : FaceBody1,
                  "operationType" : BooleanOperationType.UNION,
                  "targetsAndToolsNeedGrouping" : true
            });
            
        });
</pre><h2><br><br><pre class="CodeBlock"><code>


This is the outcome of the bad extrude:




If I use a blind extrude it works but I want the extrude to go up to the face.  This means all my other code is OK.  This is the extrude I used: 
            /* Extrude to create my bump */
            opExtrude(context, id + "extrude1", {
                    "entities" : regionToExtrude,
                    "direction" : evOwnerSketchPlane(context, {"entity" : regionToExtrude}).normal,
                    "endBound" : BoundingType.BLIND,
                    "startBound" : BoundingType.BLIND,
                    "startDepth" : 12 * millimeter,
                    "endDepth" : 0 * millimeter
            });


The Extrude works but not what I want.


Comments

  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,381
    Have you tried changing the “direction”?
    Senior Director, Technical Services, EMEAI
  • Options
    matthew_rochematthew_roche Member Posts: 8 ✭✭
    NeilCooke said:
    Have you tried changing the “direction”?
    Hmm, Thanks Neil.  Currently set as normal to the sketch plane.   I detect maybe you are giving me a hint:-)  I will investigate.  
  • Options
    matthew_rochematthew_roche Member Posts: 8 ✭✭
    NeilCooke said:
    Have you tried changing the “direction”?
    Hmm, Thanks Neil.  Currently set as normal to the sketch plane.   I detect maybe you are giving me a hint:-)  I will investigate.  
    I tried * -1on the direction.  that did not make a difference.  but I suppose since I am using start and end bounds going in both direction I am not expecting the direction to matter.    Any other hints before I go to bed?
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,381
    To be fair, last time I tried to do something similar I couldn’t get it to work either. Hopefully somebody with more knowledge will chime in. 
    Senior Director, Technical Services, EMEAI
  • Options
    matthew_rochematthew_roche Member Posts: 8 ✭✭
    Thanks Neil,  I solved it for now by providing a Length parameter for the depth.  But I would prefer to have it automatic.  Anybody have any idea?

    FYI:  It has saved me a ton of trouble writing this feature script.  I will be doing a lot more of this.   How do I publish my scripts for others to use?
  • Options
    NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,381
    How do I publish my scripts for others to use?
    Create a version, make it public, post it here.
    Senior Director, Technical Services, EMEAI
  • Options
    Alex_KempenAlex_Kempen Member Posts: 244 EDU
    I'm pretty sure the issue is that since you've told it to extrude up to face in both directions, and you aren't passing in bodies in either direction, it's failing. More specifically, you've told opExtrude to extrude up a face in one direction, and up to face in the other direction. Since opExtrude can only find a face on one side (and not the other), it's failing. In order to have your opExtrude point in only one direction, simply remove the "startBound" and "startDepth" parameters of your extrude, as they are optional (and only really useful if you want to go in two different directions).

    You could get around this by having your extrude point in the right direction. There's a couple of different ways you could do it, but it depends on your specific implementation. The laziest way to do it would proably be to break your extrudes up into two seperate extrudes, with each inside their own try{} statement. Then the opExtrude facing the wrong direction will fail without breaking your FS, and the one with the right direction will work (theoretically, at least).
    CS Student at UT Dallas
    Alex.Kempen@utdallas.edu
    Check out my FeatureScripts here:



Sign In or Register to comment.