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.

Dual counterbore featurescript help throwing error but idk whats wrong

michael_mccartymichael_mccarty Member Posts: 2

Hi All,

Starting with FS trying to stay positive but it seems like an uphill journey. Basically I want the same as the hole feature but I need a counterbore on both sides. I want to select the vertex/point and it will create a hole with the counterbore and then flip and do the same on the other side but as of now I cant even get a hole, and the error it throws does not really tell me anything? Help? Thanks !

For context I'm making parts that fit lego technic stuff trying to recreate "Catalog: Parts: Technic, Liftarm: 64179" (google and you will see)

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

annotation {
    "Feature Type Name" : "Double Counterbore Hole",
    "Feature Type Description" : "Creates a hole with counterbores on both ends at a selected point"
}
export const doubleCounterboreHole = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Point", "Filter" : EntityType.VERTEX }
        definition.point is Query;

        annotation { "Name" : "Hole Diameter", "Min" : 1, "Max" : 100, "Default" : 4.9}
        isLength(definition.holeDiameter, { (millimeter) : [1, 5.0, 100] } as LengthBoundSpec);

        annotation { "Name" : "Hole Depth", "Min" : 1, "Max" : 100, "Default" : 8.0 }
        isLength(definition.holeDepth, { (millimeter) : [1, 10.0, 100] } as LengthBoundSpec);

        annotation { "Name" : "Counterbore Diameter", "Min" : 1, "Max" : 100, "Default" : 6.2 }
        isLength(definition.counterboreDiameter, { (millimeter) : [1, 8.0, 100] } as LengthBoundSpec);

        annotation { "Name" : "Counterbore Depth", "Min" : 0.1, "Max" : 100, "Default" : 0.8 }
        isLength(definition.counterboreDepth, { (millimeter) : [0.1, 2.0, 100] } as LengthBoundSpec);
    }
    {
         //const pointPosition = evVertexPoint(context, { "vertex" : definition.point });
        
                // Define the hole parameters
        var holeDefinition = {
            "position" : definition.point,
            "diameter" : definition.holeDiameter,
            "depth" : definition.holeDepth,
            "counterboreDiameter" : definition.counterboreDiameter,
            "counterboreDepth" : definition.counterboreDepth,
            "flip" : false
        };

        // Create the hole
        hole(context, id + "hole", holeDefinition);

        // Create the flipped hole for the counterbore on the other end
        //holeDefinition.flip = true;
        //hole(context, id + "flippedHole", holeDefinition);

    });

and this is the error I get

throw Execution error
78:21
onshape/std/feature.fs (defineFeature)
40:9
HoleTwoCounterbore (const doubleCounterboreHole)
57:17
onshape/std/feature.fs (defineFeature)

Part Studio 2 (Double Counterbore Hole 1)

Part Studio 2
Precondition failed (definition.locations is Query)
369:9
onshape/std/hole.fs (const hole)
57:17
onshape/std/feature.fs (defineFeature)
40:9
HoleTwoCounterbore (const doubleCounterboreHole)
57:17
onshape/std/feature.fs (defineFeature)

Part Studio 2 (Double Counterbore Hole 1)

Part Studio 2

Comments

  • Caden_ArmstrongCaden_Armstrong Member Posts: 214 PRO

    If you look at the hole feature it requires a field called "locations" as a query.
    You are using "position" which is not a field in the hole feature.

    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • GregBrownGregBrown Member, Onshape Employees, csevp Posts: 233

    It may be easier to call opHole in your feature, something like this…

                opHole(context, id + "hole1", {
                            "holeDefinition" : holeDefinition([
                                    holeProfile(HolePositionReference.AXIS_POINT, 0 * millimeter, definition.counterboreDiameter / 2),
                                    holeProfile(HolePositionReference.AXIS_POINT, definition.counterboreDepth, definition.counterboreDiameter / 2),
                                    holeProfile(HolePositionReference.AXIS_POINT, definition.counterboreDepth, definition.holeDiameter / 2),
                                    holeProfile(HolePositionReference.AXIS_POINT, calcDepth - definition.counterboreDepth, definition.holeDiameter / 2),
                                    holeProfile(HolePositionReference.AXIS_POINT, calcDepth - definition.counterboreDepth, definition.counterboreDiameter / 2),
                                    holeProfile(HolePositionReference.AXIS_POINT, calcDepth, definition.counterboreDiameter / 2),
                                    holeProfile(HolePositionReference.AXIS_POINT, calcDepth, 0 * millimeter),
                                ], { "faceNames" : ["1", "WALL1", "SPOT1", "4", "SPOT2", "WALL2", "7"] }),
                            "axes" : [line(holeLocation, holeDirection), ],
                            "targets" : targets,
                            "keepTools" : false
                        });
    

    In your feature do you intend to always have the same counterbore depth/diam for start and end of hole. That's what I assumed above ^^^

    The hole feature is a tricky one to wrap one's head around, but it can be very powerful once you do! I hacked this together quickly.

Sign In or Register to comment.