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.


Extrusion Direction based on Collision Evaluation


I am trying to create a routine that changes the direction of the extrusion based on a collision evaluation.
The script performs this task right after sweeping a cylindrical structure.
My goal is to extrude another cylinder (different to the original), in the opposite direction.
My initial though was to use the "evCollision()" to determine if the extrusion generated an INTERFERE clash and then change the direction by multiplying normal * -1, as shown here:

var extrude_params = {
            "entities" : qSketchRegion(id + "sketch1"),
            "direction" : evOwnerSketchPlane(context, {"entity" : qSketchRegion(id + "sketch1")}).normal * -1,
            "endBound" : BoundingType.BLIND,
            "endDepth" : 1 * millimeter,
            "operationType" : NewBodyOperationType.ADD
        opExtrude(context, id + "extrude1" + unstableIdComponent("1"), extrude_params);                                                                        // execute extrusion with default parameters

var clashes = evCollision(context, { // execute collision test
"tools" : qCreatedBy(id + "extrude1", EntityType.BODY),
"targets" : qCreatedBy(id + "bitBodySweep", EntityType.BODY)

var interfere = ClashType.INTERFERE;
if( clashes[0]['type'] == interfere ) { // if the number of clashes detected is greater than "4"
extrude_params.direction = evOwnerSketchPlane(context, {"entity" : qSketchRegion(id + "sketch1")}).normal;
opExtrude(context, id + "extrude1" + unstableIdComponent("2"), extrude_params);
println( clashes[0]['type'] );
My challenges are the following;
- Since I am not using a "try-catch" (because the collision does not raise an error), how can I avoid generating the first extrusion ("extrude 1")?
- Could I create my own "error" for "try-catch"? If so, could someone give some advice?
- I am also having issues with adding the .ADD vs .NEW parameter on the extrusion. Hence, the current script only generates new parts.

I always find myself overthinking the solution, so I am very open to suggestions!!! 

The original script is here


  • Options
    kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    If you want to create geometry but be certain its changes don't affect the Part Studio, the best pattern is to begin it with a startFeature() call and end it with an abortFeature() call. Try-catch is not needed for this pattern to work (though it's common to surround the whole thing in a try {} anyway, to prevent the entire feature from failing if your heuristic fails).

    For some good examples, see the use of abortFeature() in booleanHeuristics.fs and hole.fs.
Sign In or Register to comment.