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.


Coordinate/Vector input parameter

imants_smidchensimants_smidchens Member Posts: 63 EDU
Hi! Novice featurescripter here, what's the best way to have a UI that lets you input points in comma-separated coordinate form (for now cartesian is enough)?
A [bad] approach I think might work is asking for a string input, then parsing that string and converting to a vector, but that makes typechecking much harder.
Ideally would function in an array parameter or something similar so you can place as many points as you want :)

- Imants



  • Options
    eric_pestyeric_pesty Member Posts: 1,592 PRO
    You could take a look at the "3d points" feature, it looks like it uses a string approach:

    You could also use an array for inputting multiple ones, either an array of strings as above.
    Or if you don't mind the input requiring a bit more work, an array with each requiring 3inputs for x,y,z (more "tabing" between input cells would be required), this way you don't have to worry about units:

            annotation { "Name" : "Points", "Item name" : "Coordinates", "Item label template" : "coordinates" }
            definition.points is array;
            for (var coord in definition.points)
                annotation { "Name" : "X" }
                isLength(coord.X, LENGTH_BOUNDS);
                annotation { "Name" : "Y" }
                isLength(coord.Y, LENGTH_BOUNDS);
                annotation { "Name" : "Z" }
                isLength(coord.Z, LENGTH_BOUNDS);

  • Options
    MichaelPascoeMichaelPascoe Member Posts: 1,746 PRO
    edited October 2022
    isAnything would probably work. It could look something like this:
    FeatureScript 1847;
    import(path : "onshape/std/geometry.fs", version : "1847.0");
    annotation { "Feature Type Name" : "Vector arrays" }
    export const vectorArrays = defineFeature(function(context is Context, id is Id, definition is map)
            annotation { "Name" : "Vectors", "Item name" : "Vector", "Item label template" : "Vector" }
            definition.vectors is array;
            for (var vector in definition.vectors)
                annotation { "Name" : "Vector", "Default" : "[0,0,0]" }
            for (var i = 0; i < size(definition.vectors); i += 1)
                const x = definition.vectors[i].vect[0];
                const y = definition.vectors[i].vect[1];
                const z = definition.vectors[i].vect[2];
                opPoint(context, id + i + "point1", {
                        "point" : vector(x,y,z) * inch
                addDebugEntities(context, qCreatedBy(id + i + "point1", EntityType.VERTEX), DebugColor.GREEN);

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   cadsharp.com/featurescripts 💎
  • Options
    Evan_ReeseEvan_Reese Member Posts: 2,070 PRO
    edited October 2022
    I did it with three separate length inputs in my 3D Points and Freeform Spline features. If you want a single line input, then Michael's is good, or the string method as you described, but both of those are easy for users to do wrong, and it also requires some separate field to choose units. I'm also pretty sure "novice" isn't the right classification for you, Imants :D . You've made some great features!
    Evan Reese / Principal and Industrial Designer with Ovyl
    Website: ovyl.io
  • Options
    steve_shubinsteve_shubin Member Posts: 1,070 ✭✭✭✭
    edited October 2022
    Multimate Connector has long had UI that I've used and liked

    Can't seem to find the orginal document but here is one I did


    collapse, active or inactive, reorder, delete, delta x,y,z, rotate, x,y,z

Sign In or Register to comment.