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.
Call user created scripts in another script
Lee_Hesketh
Member, Developers Posts: 148 ✭✭✭
If I have written one script called custom_axis, and am now writing a new script. How could I call custom_axis in this new script? I have tried entering custom_axis in the hopes ti appears in the drop down list, but it doesn't. How could I do this?
Thanks
Lee Hesketh
Thanks
Lee Hesketh
There are 10 types of people in the world. Those who know binary, those who don't and those who didn't expect base 3!
Tagged:
0
Best Answer
-
Import your script at the top of the script you want to use it in (use import icon near the commit button).Senior Director, Technical Services, EMEA5
Answers
-
Import your script at the top of the script you want to use it in (use import icon near the commit button).Senior Director, Technical Services, EMEA5
-
A quick addendum for future readers:
If you're you're still getting an error calling your feature or function after importing the Feature Studio, make sure the imported Feature Studio exports the relevant symbol, e.g.export const myFeature = defineFeature(...
orexport function myFunction(...
See also: import documentation.0 -
Suppose I have this tiny featurescript code snippet:FeatureScript 819;import(path : "onshape/std/geometry.fs", version : "819.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 typeannotation { "Name" : "My Length" }isLength(definition.myLength, LENGTH_BOUNDS);}{// Define the function's actionfCuboid(context, id + "cuboid1", {"corner1" : vector(0, 0, 0) * inch,"corner2" : vector(1, 1, definition.myLength / inch) * inch});});
Could you write a little code snippet demonstrating how to call this from another featurescript ?0 -
Hi @robert_carpenter114
In some other FeatureScript tab, you'll want to first click on the import button to set up the import of the other tab:
Once you have this open, you can navigate through that menu and fine the other feature studio you're interested in importing (note that if you are importing a Feature Studio from another document, that other document must be versioned. You can do this versioning from directly inside that dialog). When you have finalized the import it will generate a line of code that looks something like this:
At that point it will be simple to use your other feature. You'll be able to just write code that looks like:annotation {"Name" : "Some other feature"} export function someOtherFeature = defineFeature(function(context is Context, id is Id, definition is Map) precondition { } { // Generates a cuboid that is 10 inches high myFeature(context, id + "callToOriginal", { "myLength" : 10 * inch }); });
Jake Rosenfeld - Modeling Team0 -
Works great ! Fantastic ! Thanks Jake, Onshape rules !3




