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 set the "MaxNumberOfPicks" with a query?

MichaelPascoeMichaelPascoe Member Posts: 554 PRO
edited December 2020 in FeatureScript
How do i set the max number of picks with a query?

precondition
{
annotation { "Name" : "Group Size" }
isInteger(definition.quantity, POSITIVE_COUNT_BOUNDS);

annotation { "Name" : "Parts", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }
definition.parts is Query;
}<br>

Best Answer

  • mahirmahir Member, Developers Posts: 1,135 ✭✭✭✭✭
    Accepted Answer
    It's not perfect, but glad I could help.

Answers

  • caden_armstrongcaden_armstrong Member, User Group Leader Posts: 20 PRO
    Short answer: you can't
    Long answer: You could use the editing logic function to force a variable max number of picks. You'll need to decide what happens to the query when you go over the max number of picks; do you delete the last item from the query, or get rid of the first?
    Software Development Lead - CADSharp
  • caden_armstrongcaden_armstrong Member, User Group Leader Posts: 20 PRO
    edited December 2020
    Its not the best way, but it works. The user will see the item added, and then removed.

    Example:
    annotation { "Feature Type Name" : "My Feature", "Editing Logic Function" : "EditingLogicFunction" }
    export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            // Define the parameters of the feature type
            annotation { "Name" : "My Query", "Filter" : EntityType.FACE }
            definition.myQuery is Query;
    
            annotation { "Name" : "Max size" }
            isInteger(definition.querySize, POSITIVE_COUNT_BOUNDS);
    
    
        }
        {
            // Define the function's action
        });
    
    export function EditingLogicFunction(context is Context, id is Id, oldDefinition is map, definition is map, isCreating is boolean)
    {
        if (size(evaluateQuery(context, definition.myQuery)) > definition.querySize)
        {
            definition.myQuery = oldDefinition.myQuery;
        }
        return definition;
    }

    Software Development Lead - CADSharp
  • MichaelPascoeMichaelPascoe Member Posts: 554 PRO
    Thanks for the quick response! Hm, this changes the actual number of picks, but does not do what I need. 

    The reason I need to set the "MaxNumberOfPicks", is so that once you fill the query, it will automatically tab you to the next input box.
  • MichaelPascoeMichaelPascoe Member Posts: 554 PRO
    Bump.
  • mahirmahir Member, Developers Posts: 1,135 ✭✭✭✭✭
    edited December 2020
    Not long ago, OS added conditional visibility of array parameters. If your primary array parameter is NumberOfPicks, then you can set up some theoretical maximum number additional sub-parameters, each one with MaxNumberOfPicks=1. Based on NumberOfPicks, the extra sub-parameters would be hidden. For example, code 10 sub-parameters. If the user selects 3, then the extra 7 would be hidden. And each selection would auto tab to the next entry. It's been a while since I used array parameters, so I'm not sure what happens after that, though. OS may or may not auto tab to the next UI element, or it may add another array parameter. 
  • MichaelPascoeMichaelPascoe Member Posts: 554 PRO
    @mahir
    Thank you Mahir, I will give this a try.

    Would this have any relation to a selection-driven array parameter?
  • mahirmahir Member, Developers Posts: 1,135 ✭✭✭✭✭
    I did a little monkeying around, and it seems my idea isn't currently feasible. Conditional visibility, both of normal query inputs and of array parameters, is indeed possible. But the visibility/declaration of these inputs can only depend on a boolean input. You can't decide on the visibility of an input based on a numerical comparison, e.g. if (input_index < GroupSize). You'd have to have a series of boolean checkboxes, which doesn't sound very user friendly for inputting something like an integer number of selections.
  • MichaelPascoeMichaelPascoe Member Posts: 554 PRO
    Good to know!

    That could be a decent work around. So I can have a drop down menu with 5 or so different group sizes. Depending on which group size you choose, an almost identical query will be chosen that is set up with a different "MaxNumberOfPicks".

    Thanks for the help!
  • mahirmahir Member, Developers Posts: 1,135 ✭✭✭✭✭
    Accepted Answer
    It's not perfect, but glad I could help.
  • MichaelPascoeMichaelPascoe Member Posts: 554 PRO
    @mahir
    Here is the feature I used this info to make:
    https://forum.onshape.com/discussion/15155/boolean-groups-new-custom-feature#latest

    It doesn't auto tab to the next box, but it turned out nice.
  • mahirmahir Member, Developers Posts: 1,135 ✭✭✭✭✭
    Thanks for the shoutout in the FS  :)
  • MichaelPascoeMichaelPascoe Member Posts: 554 PRO
    Of course. 
Sign In or Register to comment.