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.
can you create a subroutine?
billy2
Member, OS Professional, Mentor, Developers, User Group Leader Posts: 2,115 PRO
Let's say I want to format the output for a vector
How do I call the function?
function printVector(v) {<br> println("vector :"~roundToPrecision(v[0], 4)*1000~", "~roundToPrecision(v[1], 4)*1000~", "~roundToPrecision(v[2], 4)*1000);
}
<br>How do I call the function?
printVector(v);
0
Comments
If your function is stored in another studio, you will need to place "export" before the function. Then you can import that studio into your current studio to use it like you normally would.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
FeatureScript 1803; import(path : "onshape/std/geometry.fs", version : "1803.0"); annotation { "Feature Type Name" : "function" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type } { function printOut(m) { print(m); } printOut("hello world"); }); <br>It's seems simple but I can't find any reference to functions or subroutines, I have seen other code where guys are passing the context into functions outside the "function action area" and was wondering if there is something printed in the manuals about this simple concept.
function printOut(m) { print(m); }chadstoltzfus@premiercb.com
FeatureScript 1803; import(path : "onshape/std/geometry.fs", version : "1803.0"); annotation { "Feature Type Name" : "My Feature" } export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type } { // Define the function's action var vectorWithUnits = vector(0, 0, 1) * inch; var vectorWithoutUnits = vector(0, 0, 1); printVector(vectorWithUnits); printVector(vectorWithoutUnits); }); export function printVector(v is Vector) { if (isLengthVector(v)) { println("vector :" ~ roundToPrecision(v[0] / inch, 4) * 1000 ~ ", " ~ roundToPrecision(v[1] / inch, 4) * 1000 ~ ", " ~ roundToPrecision(v[2] / inch, 4) * 1000); } else { println("vector :" ~ roundToPrecision(v[0], 4) * 1000 ~ ", " ~ roundToPrecision(v[1], 4) * 1000 ~ ", " ~ roundToPrecision(v[2], 4) * 1000); } }chadstoltzfus@premiercb.com