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.

vertex coordinates

joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU

I have a featureScript where I select a point. Now, I want to print the coordinates of this point. How can I do this?

I already have the query, but I don't know how to access the selected point

Thanks for your help.

Best Answers


  • _anton_anton Member, Onshape Employees Posts: 81
    evVertexPoint is what you need.
  • MichaelPascoeMichaelPascoe Member Posts: 924 PRO
    What is your end objective? Do you simply want to print the coordinate of the point to the FeatureScript Notices tab? Or do you want to see the value in the feature itself while you are using it?
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU

    Thanks for the help.

    At the moment I am doing some debugging, but my final goal will be to translate the coordinates obtained from a CSV file by the x coordinate of this point, or even better, attach an sketch to this point.

    I already read in the CSV, selected a plane, and generated the sketch on the selected plane.  But now I want to translate the sketch using the information of the selected point.

    I tried the following according to _anton suggestion, but I am getting an error, I guess I am missing something (maybe the arguments):

    var coor = evVertexPoint(context, definition.selectVertex);
    debug(context, coor);

  • Alex_KempenAlex_Kempen Member Posts: 220 EDU
    Answer ✓
    The following code:
    const vertex = evVertexPoint(context, { "vertex" : definition.myQuery });
    Will print the coordinates to the console (accessible via the {✓} icon in the top right corner of a part studio). 
  • Alex_KempenAlex_Kempen Member Posts: 220 EDU
    You can transform a sketch to a point using the following code:
    const mySketch = newSketchOnPlane(context, id + "mySketch", { "value" : XY_PLANE });
    // add sketch points
    // get vertex
    opTransform(context, id + "toPoint", { 
        "bodies" : qCreatedBy(id + "mySketch", EntityType.BODY), 
        "transform" : transform(vertex - WORLD_ORIGIN) // can also use some other 3D point (make sure it's actually 3D)
    You can also find more code examples in my FeatureScript Examples document here:

    Let me know if you need any additional help!
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU
    edited July 2021

    Well that might do the trick.

    At the moment I am trying to sort out everything by myself, but if I need any additional help I will let you know.

    In any case, using your script I just need to add the following after  skSolve(sketch1):

        const vertex = evVertexPoint(context, { "vertex" : definition.selectVertex });
       opTransform(context, id + "toPoint", {
        "bodies" : qCreatedBy(id + "sketch1", EntityType.BODY),
        "transform" : transform(vertex - WORLD_ORIGIN)
    Is that right?


  • Alex_KempenAlex_Kempen Member Posts: 220 EDU
    Answer ✓
    Yeah, pretty much. I freehand the code, so watch out for spelling mistakes and the like, but it seems like you’re pointed in the right direction. Feel free to compare my code with the documentation to see how they match up as well.
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU

    It worked fine.

    Now that we are here, can I add the origin as default value for the query selection?

  • Alex_KempenAlex_Kempen Member Posts: 220 EDU
    Not really, but you could assume an empty selection means you should just use the origin instead. This can be done fairly easily using an if statement and the isQueryEmpty function to check if anything is selected before running the transform.
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU

    I think I hit a wall. I am having a behavior that I am not able to correct in an elegant way.

    You can find the document at this link:

    The problem is that when I choose a point that is located in a plane translated in z-direction by 1 (for example), the script will generate the sketch  in a plane located in 2 in the z-direction (twice the distance of the original plane).

    Any clue of what could be the problem?, pretty much I think it is related to the transformation you suggested. I managed to correct the issue adding another transformation, but I think it is possible to do it in a better way without adding too much clutter.

  • Alex_KempenAlex_Kempen Member Posts: 220 EDU
    I can't access your document - did you make it public? 

    The transform I popped in is designed to bring entities from the world origin to your vertex. If that isn't what you want, there's a variety of ways to adapt it which depend on what you're trying to do.

    Also, you can apply transforms one after another by simply multiplying the transforms together; for example, transform2 * transform1 is equal to running transform1 followed by transform2; for that reason, you should never really have to call opTransform on an object multiple times since you can simply multiply their transforms together into one big transform first.
  • Alex_KempenAlex_Kempen Member Posts: 220 EDU
    Okay, it looks like you just need a way to set the start point of the transform somewhat more intelligently. The easiest way is probably to create a plane object (use evPlane on definition.selectPlane), then project the world origin onto that plane and use that as the start of your transform. You can also project your selected vertex onto the plane if you wish; this will help keep your entities on the appropriate plane in the case where your selected point coplanar with your selected plane. 

    Feel free to let me know if you get stuck and want to see some actual code of this, too.
  • joel_guerrerojoel_guerrero Member, Developers Posts: 14 EDU

    I have been playing around with this, and honestly I didn't find an easy way to get it right. I think the fix will be to use a function that adds the sketch in the world origin but I didn't find anything.  Things get even worst when you try to use a plane that is inclined.

    If you know of a fix, let me know. For the moment the solution I implement works, but I would like to have something more general.

Sign In or Register to comment.