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.
Return definition.groups[g].lengthInputMethod ?
MichaelPascoe
Member Posts: 1,979 PRO
I'm having trouble returning a boolean definition. I can't get definition.groups[g].lengthInputMethod to return with true when the opposite direction button is pressed.
My goal is to have an opposite direction boolean switch the user interface between "group.lengthEntities" and "group.dx". The opposite direction code has to be below "group.lengthEntities" and "group.dx" code in order for the opposite direction gui to appear beside the input box.
When the opposite direction is pressed, I would like a hidden boolean "group.lengthInputReturned" to change from false to true.
Here is the code i have so far :
https://cad.onshape.com/documents/395304920b30c3b382fd312d/w/86481637ad1e9da01b0e5d60/e/296c17e767add081ff718e6a
My goal is to have an opposite direction boolean switch the user interface between "group.lengthEntities" and "group.dx". The opposite direction code has to be below "group.lengthEntities" and "group.dx" code in order for the opposite direction gui to appear beside the input box.
When the opposite direction is pressed, I would like a hidden boolean "group.lengthInputReturned" to change from false to true.
Here is the code i have so far :
https://cad.onshape.com/documents/395304920b30c3b382fd312d/w/86481637ad1e9da01b0e5d60/e/296c17e767add081ff718e6a
annotation { "Feature Type Name" : "Cut List", "UIHint" : "NO_PREVIEW_PROVIDED", "Icon" : icon::BLOB_DATA, "Editing Logic Function" : "measure" } export const cutList = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Cut List", "Item name" : "Item", "Item label template" : "#name" } //, "UIHint" : UIHint.COLLAPSE_ARRAY_ITEMS } definition.groups is array; for (var group in definition.groups) { annotation { "Name" : "lengthInputReturned", "UIHint" : UIHint.ALWAYS_HIDDEN } group.lengthInputReturned is boolean; if (group.lengthInputReturned == false) //group.lengthInputMethod == Method2.MEASURE) { annotation { "Name" : "Length", "Filter" : EntityType.FACE || EntityType.EDGE || EntityType.VERTEX, "MaxNumberOfPicks" : 2 } group.lengthEntities is Query; } if (group.lengthInputReturned == true) //group.lengthInputMethod == Method2.MANUAL) { annotation { "Name" : "Length" } isLength(group.dx, { (inch) : [-1e5, 0, 1e5] } as LengthBoundSpec); } annotation { "Name" : "Measure", "UIHint" : UIHint.OPPOSITE_DIRECTION } group.lengthInputMethod is boolean; } } export function measure(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean) returns map { for (var g = 0; g < size(definition.groups); g += 1) { //Reference functions. Thanks Alex! //https://cad.onshape.com/documents/eebb66e5a6139b9b86708957/w/093d288d7231f660efc44c25/e/8466437b7dc1144ccb506b50 // if partQuery changes, and partQuery is a solid body which does not evaluate to nothing (i.e. a solid part is selected): // this condition is used because we don't need to update the material unless the user changes which parts they've selected if (oldDefinition.groups[g].lengthInputMethod != definition.groups[g].lengthInputMethod) { if (definition.groups[g].lengthInputMethod == true) { definition.groups[g].lengthInputReturned == true; } if (definition.groups[g].lengthInputMethod == false) { definition.groups[g].lengthInputReturned == false; } } } return definition; }
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
Tagged:
0
Best Answers
-
kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 565Simple fix I think. You have
definition.groups[g].lengthInputReturned == true;
but you wantdefinition.groups[g].lengthInputReturned = true;
1 -
Alex_Kempen Member Posts: 248 EDUThe usage of library functions is actually pretty straightforward. Paste the following import at the top of your feature studio:
import(path : "4c21d0c3c89c0a81aadfdac6/636ff98c3710f0d81fcecbf8/3732a1478a38cc5723a9801f", version : "17c016200f841487aca7f892");
You'll then be able to call arrayParamterChanges (and arrayItemChanges) from my library directly:if (arrayParameterChanges(oldDefinition.group, definition.group)) { for (var i = 0; i < size(definition.group); i += 1) { if (oldDefinition.group[i].myParameter != definition.group[i].myParameter)<br> { definition.group[i].myParameter = computedValue;<br> } ... // Perform additional operations } }
They'll also autocomplete if you start typing them, and since they're fully documented, you'll be able to see usage explanations and examples directly inside the autocomplete menu:
CS Student at UT DallasAlex.Kempen@utdallas.eduCheck out my FeatureScripts here:1 -
Alex_Kempen Member Posts: 248 EDU1. arrayParameterChanges is designed to run only when something changes inside an array parameter. If you want to update all the values of your array parameter when something not in an array parameter updates, I would condition the outside parameter, then run through the array as needed:
if (oldDefinition.myParameter != definition.myParameter) { for (var i = 0; i < size(definition.groups); i += 1) { definition.groups[g].myParameter = myValue; } }
2. Specified parameters is an optional argument which can be added to editing logic functions:export function measureEditLogic(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map) returns map
The documentation states that "specified parameters map to true", which is a complicated way of saying that specifiedParameters is like your definition, except the values of parameters are all booleans corresponding to whether a user input something for that parameter. Thus:// A commonly used condition for updating a merge scope, to prevent overwriting a user input value if (!specifiedParameter.mergeScope && oldDefinition.myQuery != definition.myQuery)
Note, however, that this does not work for anything array parameter related.
3. And lastly, the code:if (definition.groups[g].widthInputMethod == true) { definition.groups[g].widthInputReturned = true; } if (definition.groups[g].widthInputMethod == false) { definition.groups[g].widthInputReturned = false; }
Behaves identically to the code:definition.groups[g].widthInputReturned = definition.groups[g].widthInputMethod;
CS Student at UT DallasAlex.Kempen@utdallas.eduCheck out my FeatureScripts here:1
Answers
but you want
Thanks Kevin!
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
I will try to keep this in mind. Looks a little advanced for my current knowledge.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
You'll then be able to call arrayParamterChanges (and arrayItemChanges) from my library directly:
They'll also autocomplete if you start typing them, and since they're fully documented, you'll be able to see usage explanations and examples directly inside the autocomplete menu:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
@Alex_Kempen
I'm having some trouble getting another parameter to update. When I type a number into "Initial quantity" it does not update the array "quantity" until I change something in that group. The moment I check a box or update a number within that group, quantity updates and becomes 4.
Also, is there a way to check if a user has not placed anything into an input? I would like the "initial" parameters to only be applied if the user has not entered any parameters. In some cases, "if (size(evaluateQuery(context, myQuery)) == 0) { }" would usually work, but not for this.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
2. Specified parameters is an optional argument which can be added to editing logic functions:
The documentation states that "specified parameters map to true", which is a complicated way of saying that specifiedParameters is like your definition, except the values of parameters are all booleans corresponding to whether a user input something for that parameter. Thus:
Note, however, that this does not work for anything array parameter related.
3. And lastly, the code:
Behaves identically to the code:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴