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.

How to extrude sketch entity instead of whole sketch in FeatureScript?

marek_robakmarek_robak Member Posts: 2
Hi, I am new to FeatureScript and wonder how to extrude only the sketch entity instead of the whole sketch.

        var worldCoordSys is CoordSystem = coordSystem(vector(0, 0, 0) * meter, vector(1, 0, 0), vector(0, 0, 1));
        var bucketSketch = newSketchOnPlane(context, id + "sketch1", {
                "sketchPlane" : plane(worldCoordSys)
            });
        skRectangle(bucketSketch, "rectangle1", {
                    "firstCorner" : vector(0, 0) * meter,
                    "secondCorner" : vector(definition.bucket_size, definition.bucket_size)
                });
        skRectangle(bucketSketch, "rectangle2", {
                    "firstCorner" : vector(definition.wall_thickness, definition.wall_thickness),
                    "secondCorner" : vector(definition.bucket_size - definition.wall_thickness, definition.bucket_size - definition.wall_thickness)
                });
        skSolve(bucketSketch);

For example, here I would like to extrude "rectangle1" with some height eg. 2 inches, and "rectangle2" with eg. 10 inches.
I thought I could create two newSketchOnPlane() and extrude them easily but it seems inappropriate way to archive this.
I would love to know what is in this case good and bad practice.

Also, can I archive the extrude of only the shape that comes from the intersection of some sketch entities?

Comments

  • Jacob_CorderJacob_Corder Member Posts: 137 PRO
    edited September 2023
    //insert this code after your skSolve(bucketSketch)
    
    
    //if you want to extrude surfaces, then use this
        var largestRegion =  sketchEntityQuery(id + "sketch1", EntityType.EDGE, "rectangle1");
        var smallest =  sketchEntityQuery(id + "sketch1", EntityType.EDGE, "rectangle2");
    
    //if solid bodies then use this
    
        var regions =  qSketchRegion(id + "sketch1", false) ;
        var largestRegion = makeRobustQuery(context, qLargest(regions));//this will stop evaluating the areas of the regions in queries after.
        var smallest = qSubtraction(regions, largestRegion);
    
    //now you can extrude them
    opExtrude(context, id+"extrudeLargest", {
            "entities" : largestRegion,
            "direction" : evOwnerSketchPlane(context, {"entity" : largestRegion}).normal,
            "endBound" : BoundingType.BLIND,
            "endDepth" : 2 * inch
    });
    opExtrude(context, id+"extrudeSmallest", {
            "entities" : smallest,
            "direction" : evOwnerSketchPlane(context, {"entity" : smallest}).normal,
            "endBound" : BoundingType.BLIND,
            "endDepth" : 10 * inch
    });
     

    Give that a try. 
Sign In or Register to comment.