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.

Feature Script: How to set the "oppositeDirection"-Tag for extrude?

Hey!

I'm starting with feature script and work on a small script that simply needs a thoughhole. I ask the user for a point (around which I draw a circle) and a face to which the hole is going to. This part of the script looks like this:

        annotation { "Name" : "Vertex for center", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }
        definition.center is Query;

        annotation { "Name" : "Back Face", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
        definition.backface is Query;

(...)

        var location = evVertexPoint(context, { "vertex" : definition.center });
        var sketchPlane = evOwnerSketchPlane(context, { "entity" : definition.center });
        const frontSketch = newSketchOnPlane(context, id + "frontSketch", { "sketchPlane" : sketchPlane });
        const center = worldToPlane(sketchPlane, location);

        // create the outer diameter circle
        skCircle(frontSketch, "throughhole_circle", { "center" : center, "radius" : radius });
        skSolve(frontSketch);


        extrude(context, id + "extrude1", {
                    "entities" : qSketchRegion(id + "frontSketch", true),
                    "direction" : sketchPlane.normal,
                    "oppositeDirection" : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                    "operationType" : NewBodyOperationType.REMOVE,
                    "defaultScope" : true,
                    "endBound" : BoundingType.UP_TO_SURFACE,
                    "endBoundEntityFace" : definition.backface
                });


I don't understand yet how to set the oppositeDirection-flag. To test the function, I created a sketch with two rectangles on the top-plane and extruded both in different direction. (negative and positive z-space). But only one generates correctly.

So how is the normal of a plane defined? And how can I just create a hole? There should be an easy way to say "Remove into the object", but I haven't found it yet.

Answers

  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    edited February 2018
    generally when you select sketch region on the face or the face of solid body itself the normal of the sketch plane is directed from the solid to outside. if you need to change this behavior you need to add new boolean parameter to the precondition of the feature (optionally with corresponding UIHint parameter) like that:
    annotation { "Name" : "Opposite direction", "UIHint" : "OPPOSITE_DIRECTION" }
            definition.flipDir is boolean;
    and then inside the feature explicitly flip extrude direction like that (or using if operator)
    extrudeDir = evSketchOwnerPlane(query).normal;<br>extrudeDir = definition.flipDir? -extrudeDir: extrudeDir;

  • nikolas_engelhardnikolas_engelhard Member Posts: 5
    But if the normal of my sketch points to the outside, why does the extrude not always work?
  • konstantin_shiriazdanovkonstantin_shiriazdanov Member Posts: 1,221 ✭✭✭✭✭
    it hard to say something without having real feature
  • nikolas_engelhardnikolas_engelhard Member Posts: 5
    This is already the complete script (without the autogenerated part). Which part are you missing?.
  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,210
    @nikolas_engelhard The way to make it easy for people to help you is to actually post a link to the public document -- that way others can see the full source code in the feature studio and see how the feature is intended to be used in the part studio.
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
Sign In or Register to comment.