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 :)

Cheers!
- Imants



Tagged:

Comments

  • eric_pestyeric_pesty Member Posts: 1,885 PRO
    You could take a look at the "3d points" feature, it looks like it uses a string approach:
    https://cad.onshape.com/documents/576d1e60c6cb90985345ac37/v/6bdd1ac65b1e423b1a692568/e/0ea78f371cbafb95ea304449

    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);
    
            }

  • MichaelPascoeMichaelPascoe Member Posts: 1,988 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)
        precondition
        {
            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]" }
                isAnything(vector.vect);
            }
        }
        {
            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);
            }
        });
    https://cad.onshape.com/documents/fd25eb49ed0b337b8b6ce216/w/cc40be845773e9603fd45fe7/e/c567751317dbecfad1d202a1?renderMode=0&uiState=633b333d1e9631446ce0b25f



    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • EvanReeseEvanReese Member, Mentor Posts: 2,135 ✭✭✭✭✭
    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
  • steve_shubinsteve_shubin Member Posts: 1,096 ✭✭✭✭
    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

    https://cad.onshape.com/documents/f044ddc8d35e56ddf664cf5b/w/38d7f9552f87669c5214103a/e/5657845114584e71500268cb

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


Sign In or Register to comment.