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.
Configurations in Feature Script
Kira_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!
0
Best Answer
-
ilya_baran Onshape Employees, Developers, HDM Posts: 1,212I can't see your document, but you may have been on the right track before -- you may have to use
API_BOX::Orientation_conf.Top
Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc1
Answers
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:
If you try putting Top without the quotation marks, FeatureScript assumes you're trying to pass in the value of a variable named Top:
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:
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
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 });
API_BOX::Orientation_conf.Top