Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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_smidchens
Member Posts: 65 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
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:
0
Comments
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); }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); } });Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
The Onsherpa | Reach peak Onshape productivity
www.theonsherpa.com
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