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.

How do I use Editing Logic Function to change input value in array using enum preset value?

Caleb_KehoeCaleb_Kehoe Member, HDM Posts: 28 PRO
I have two tabs in my UI:  Array Input and an Enum input type.  While the user can input the value into the array directly, I would like to enable the option of a dropdown in a different tab to override the array value if the dropdown enum is used/changed.  Almost like the array input value is a default.  I've seen examples close to this and @NeilCooke suggested the Spur Gear script to someone else as it drives a third input from two other ones concurrently (I believe).  It sounds like Editing Logic Function is the way to do this but I'm having some issues and I suspect the culprit is the data type being an array.  I'm also just getting started with FS so perhaps there are a host of other reasons.  Any input would be greatly appreciated.

I attempted to copy the FS code below but not sure if the formatting is going to come through in the cleanest way.  I can make a public version of this doc if that's easier.

  -------->      ------->   

<div><br></div><div>export enum tabTYPE</div><div>{</div><div>&nbsp; &nbsp; annotation { "Name" : "Array Input" }</div><div>&nbsp; &nbsp; Array_Input,</div><div>&nbsp; &nbsp; annotation { "Name" : "Dropdown Input" }</div><div>&nbsp; &nbsp; Dropdown_Input,</div><div>}</div><div><br></div><div>export enum optionTYPE</div><div>{</div><div>&nbsp; &nbsp; annotation { "Name" : "Set #VAR1 = 115" }</div><div>&nbsp; &nbsp; VAR115,</div><div>&nbsp; &nbsp; annotation { "Name" : "Set #VAR1 = 285" }</div><div>&nbsp; &nbsp; VAR285,</div><div>}</div><div><br></div><div>annotation { "Feature Type Name" : "Onshape troubleshooting", "Editing Logic Function" : "InputOverride", "UI Hint" : "NO_PREVIEW_PROVIDED" }</div><div>export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)</div><div><br></div><div>&nbsp; &nbsp; precondition</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Tab", "UIHint" : "HORIZONTAL_ENUM" }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; definition.tabTYPE is tabTYPE;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (definition.tabTYPE == tabTYPE.Array_Input)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; annotation { "Item name" : "", "Item label template" : "#(#inputname) = #inputvalue", "Driven query" : "query", "UIHint" : ["COLLAPSE_ARRAY_ITEMS", "NO_PREVIEW_PROVIDED"] }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; definition.arrayVars is array;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (var arrayVar in definition.arrayVars)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Var Name", "Default" : "VAR1", "UIHint" : "SHOW_LABEL" }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arrayVar.inputname is string;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Var Value" }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isLength(arrayVar.inputvalue, LENGTH_BOUNDS);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Entities", "Filter" : SketchObject.NO, "MaxNumberOfPicks" : 1, "UI Hint" : ["ALWAYS_HIDDEN", "CONTROL_VISIBILITY", "REMEMBER_PREVIOUS_VALUE"] }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arrayVar.query is Query;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (definition.tabTYPE == tabTYPE.Dropdown_Input)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; annotation { "Name" : "Select Input", "UIHint" : ["SHOW_LABEL", "REMEMBER_PREVIOUS_VALUE"] }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; definition.optionTYPE is optionTYPE;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; // Define the function's action</div><div>&nbsp; &nbsp; &nbsp; &nbsp; for (var arrayVar in definition.arrayVars)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setVariable(context, arrayVar.inputname, arrayVar.inputvalue);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; });</div><div><br></div><div>export function InputOverride(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean, specifiedParameters is map) returns map</div><div>{</div><div>&nbsp; &nbsp; for (var arrayVar in definition.arrayVars)</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (oldDefinition.optionTYPE != definition.optionTYPE) // this means if the value has been changed by the user</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (definition.optionTYPE == optionTYPE.VAR115)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setVariable(context, arrayVar.inputname, 115);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (definition.optionTYPE == optionTYPE.VAR285)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setVariable(context, arrayVar.inputname, 285);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; return definition;</div><div>}</div><div></div>


Tagged:

Best Answers

Answers

  • Caleb_KehoeCaleb_Kehoe Member, HDM Posts: 28 PRO
    Awesome!  Thanks, @Jake_Rosenfeld!  This worked great and I appreciate the explanation for the edits.  This will be a great reference to build on.  The only tweak I made to your code above to get it to work was that I am out to change the "inputValue" instead of "inputName" and specify units of the assigned value.

    i.e. 
    ...
    {
    definition.arrayVars[i].inputvalue = 115 * millimeter;
    }
    ...
  • Caleb_KehoeCaleb_Kehoe Member, HDM Posts: 28 PRO
    @Jake_Rosenfeld, a related question.  What if I wanted to pass the definition.arrayVars[i].inputvalue another user input value that's stored in the array?  How would I accomplish this?  For example, if I had inputvalue1 and inputvalue2 in the array and I wanted to change inputvalue1 to be set equal to inputvalue2 depending on the enum selection, rather than just the static numbers we have above.  Conceptually it seems straight forward but I'm not getting it to work.  The use case is that this inputvalue2 would be a value that doesn't change and behaves similar to a 'default' that the user has control over.

    Going one step further, I made an option in the enum selection to create a manual entry override that I would also like to pass to inputvalue1 when selected.  The manual entry input box is populated below the enum on the same 'tab'.  Struggling to get that to work as well.  

    Regardless of the tabs that these values live on, they are currently all part of the same context and map, correct?  So, where am I getting caught out by calling their unique id at any moment in time (regardless of oldDefinition or definition)?

    I can provide some code if needed.  Thanks in advance!
  • Caleb_KehoeCaleb_Kehoe Member, HDM Posts: 28 PRO
    Thanks again, Jake.  Both answers worked out nicely.  For those interested, my error on the first question was in trying to multiply the array values with integers and units.

    On the second question, my error was in thinking that the "ManualOverrideValue" needed to be specified as part of the Enum that enabled its entry rather than just being simply called as a definition of the main feature dialog.
Sign In or Register to comment.