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.

Configurations in Feature Script

Kira_LeeKira_Lee Member, Developers Posts: 17 PRO

I have been trying to add a specific configuration from a part studio in my feature script. I thought I had done it correctly - I even tried following this forum exactly (renaming my ID's in the part studio and feature script to "Orientation" and "Top", "Left", "Right"), but this still doesn't work. 
        var query;
        var transform = identityTransform();
        if (size(evaluateQuery(context, definition.mateConnector)) == 1)
        {
            transform = toWorld(evMateConnector(context, { "mateConnector" : definition.mateConnector }));
        }
        var instantiator = newInstantiator(id + "instantiator");

            query = addInstance(instantiator, API_BOX::build, {
                        "configuration" : {
                            "Orientation" : Orientation_conf.Top
                        },
                        "transform" : transform
                    });<br>
I want to mention that the code works correctly if I take out the "Configuration" part - it just doesn't put the configuration I want since it uses the default then.





The error I'm getting is "variable Orientation_conf not found". Is there a key factor I'm missing? I'm very stuck, so thank you for any help in advance!

Best Answer

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,114
    edited November 2021 Answer ✓
    I can't see your document, but you may have been on the right track before -- you may have to useAPI_BOX::Orientation_conf.Top
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc

Answers

  • Alex_KempenAlex_Kempen Member Posts: 208 EDU
    The name of the configuration table is "Orientation", and it looks like it has row names "Top", "Left", and "Right". Hence, the configuration is expecting something like:
    "configuration" : { "Orientation" : "Top" }
    Note that in the previous example, Top is a string, as denoted by the quotation marks "". If you want to set the configuration dynamically, you can use a variable:
    const myOrientation = "Top";
    "configuration" : { "Orientation" : myOrientation }
    If you try putting Top without the quotation marks, FeatureScript assumes you're trying to pass in the value of a variable named Top:
    "configuration" : { "Orientation" : Top } // ERROR: No variable named Top!
    
    const Top = "Right";
    "configuration" : { "Orientation" : Top } // generates the "Right" configuration
    Lastly, the toString() method can be used to convert certain values into strings - for example, if you have an enum with values Top, Right, and Left, you can use the enum directly by calling toString on it:
    "configuration" : { "Orientation" : toString(definition.myEnum) } // where myEnum is an enum parameter corresponding to an enum with values Top, Right, and Left
    Hopefully that makes some sense. You can also take a look at my vex component feature, which is a wrapper of my point derive feature and allows my VEXU team to quickly bring in motor mounts and configured c-channels:
    https://cad.onshape.com/documents/6a4c34c32c5e682a7255943c/w/b0d6114e5fd1de57c398df5f/e/a46b7a378c04ba3fee3d230e
    FeatureScript Developer, CADSharp
    Sophomore CS Student at UT Dallas
    Checkout my FeatureScripts here:



  • Kira_LeeKira_Lee Member, Developers Posts: 17 PRO
    edited November 2021
    I tried this and now I am getting a different error:

    Parameter Orientation must be a valid Orientation_conf

    This is the exact code:
    var orientation = "Top";
    var query = addInstance(instantiator, API_BOX::build, {
                    "configuration" : { "Orientation" : orientation },
                    "transform" : transform
                });

  • ilya_baranilya_baran Onshape Employees, Developers, HDM Posts: 1,114
    edited November 2021 Answer ✓
    I can't see your document, but you may have been on the right track before -- you may have to useAPI_BOX::Orientation_conf.Top
    Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc
  • Kira_LeeKira_Lee Member, Developers Posts: 17 PRO
    edited November 2021
    That fixed it! Thank you!
Sign In or Register to comment.