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.

skConstraint / Newbie to featurescript

emory_krallemory_krall Member Posts: 15 PRO
I'm just starting to work with featurescript and I have no programming experience so there are some large gaps in my knowledge.

I've been working off of a script written by someone who actually knew what they were doing which imports solid tool-bodies from a separate context and uses them to create machining details at specified sketch points. I've successfully adapted it a few times for different types of hardware, but now I'm trying something more advanced.

The purpose of the script is to create CNC machining details for mounting hinges in a cabinet door. The exact distance of the door edge to the side of the cabinet can vary, so (thinking like a CAD user, not a programmer) I'm attempting to locate the hinges using points sketched on the back of the door, then have the script project the points onto the side of cabinet and place the machining details based on the projected points.

Searching discussion questions led me to skConstraint. The discussions in those posts made me understand skConstraint might not be the best way to solve my problem, but I couldn't find any alternative solutions. In any case, I almost have it working now - the script is successfully creating a new point in a new sketch for every point in the queried sketch, but it's constraining all of them to a single point of the queried sketch.

This is the script:

Open to any suggestions (including not using skConstraint)!


  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,466

    It looks like you have made some progress and are now trying to use the `project()` call directly.

    The code that you are using:
    var newPoints = project(doorPlane, definition.doorBackPoints);
    is likely failing.  I signature of the function you are trying to target is project(plane is Place, vector is Vector).  The first argument should be a plane (which is what you are inputting) and the second argument should be a Vector representing a single point in 3d space.  You are passing in a query for a bunch of points.  I would adapt that line of code to read as follows:

    var newPoints = [];
    for (var backDoorPoint in evaluateQuery(context, definition.doorBackPoints))
        const backDoorPointLocation = evVertexPoint(context, { "vertex" : backDoorPoint });
        const projected = project(doorPlane, backDoorPointLocation);
        // debug(context, projected); // This will highlight the location in red while you have the feature open, for debugging purposes
        newPoints = append(newPoints, projected);

    At the end of this loop, newPoints will be a list of 3d world space positions representing the locations of backDoorPoints projected onto doorPlane. If you want to actually create point bodies at those locations, you will need to call opPoint.


    Separate note here.  Importing other part studios at the top of the Feature Studio is no longer always the best practice.  You may want to check out our new(ish) reference parameter, which allows you to actually select a part studio as a parameter of the feature, if you want the user of this feature to be able to change to a different part studio on the fly.  If you are always going to be referencing this same Part Studio, and never need to change that, then I would stick with the import over the reference parameter.

    Jake Rosenfeld - Modeling Team
  • emory_krallemory_krall Member Posts: 15 PRO
    Thanks @Jake_Rosenfeld ! I think I'll be able to puzzle out the rest of the script now that you've given me this piece.

    Also, thanks for letting me know about the reference parameter. I am planning to have options in this script for two different types of hinges which will reference different part studios.
Sign In or Register to comment.