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 PROMember, 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.

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

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


Best Answers


  • Caleb_KehoeCaleb_Kehoe PRO 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.

    definition.arrayVars[i].inputvalue = 115 * millimeter;
  • Caleb_KehoeCaleb_Kehoe PRO 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 PRO 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.