Configurations in Feature Script
Kira_Lee
Member, Developers Posts: 17 ✭
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
-
I can't see your document, but you may have been on the right track before -- you may have to use
API_BOX::Orientation_conf.TopIlya Baran \ VP, Architecture and FeatureScript \ Onshape Inc1
Answers
-
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" configurationLastly, 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 LeftHopefully 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
Software Developer at Epic Systems
FRC Design Mentor - Team 1306 BadgerBots0 -
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 });
0 -
I can't see your document, but you may have been on the right track before -- you may have to use
API_BOX::Orientation_conf.TopIlya Baran \ VP, Architecture and FeatureScript \ Onshape Inc1 -
That fixed it! Thank you!
0


