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.

Call user created scripts in another script

Lee_HeskethLee_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
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!

Best Answer

Answers

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565
    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(...
    or
    export function myFunction(...
    See also: import documentation.
  • robert_carpenter114robert_carpenter114 Member Posts: 8 ✭✭
    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 type
           annotation { "Name" : "My Length" }
            isLength(definition.myLength, LENGTH_BOUNDS);
            
        }
        {
            // Define the function's action
             
            
            
            fCuboid(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 ?

  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    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 Team
  • robert_carpenter114robert_carpenter114 Member Posts: 8 ✭✭
    Works great !  Fantastic ! Thanks Jake, Onshape rules !
Sign In or Register to comment.