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.

Array Parameter ID's/Names

MichaelPascoeMichaelPascoe Member Posts: 929 PRO
edited May 2021 in FeatureScript
How do I update the group name in this array parameter for each added group?
https://cad.onshape.com/documents/8a8e419809a7dc3de36ff04d/w/0ed9e9d7984dea4c03a88617/e/3b07658a43284e036816907f



annotation { "Feature Type Name" : "Boolean Groups", "Icon" : icon::BLOB_DATA }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)

    precondition
    {
        //Sources for precondition arrays:
        //Wood Grain by Tim Rice https://cad.onshape.com/documents/f5cd9f4b2ec8e9eea7266f1e/v/e15f879c66222ea59c108b8a/e/4626b80fb148952bd0b75c92
        //Mahir https://forum.onshape.com/discussion/comment/68636#Comment_68636
        
        annotation { "Name" : "Groups", "Item name" : "Group", "Item label template" : "Group" }
        definition.groups is array;
        for (var group in definition.groups)
        {
            annotation { "Name" : "Parts", "Filter" : EntityType.BODY, "UIHint" : UIHint.ALLOW_QUERY_ORDER }
            group.parts is Query;
        }
    }
    {
        for (var i = 0; i < size(definition.groups); i += 1)
        {
            try silent
            {
                opBoolean(context, id + i + "boolean1", {
                            "tools" : definition.groups[i].parts,//group[i],
                            "operationType" : BooleanOperationType.UNION
                        });
            }
            catch
            {
            }
        }
    });

Best Answer

  • Alex_KempenAlex_Kempen Member Posts: 221 EDU
    edited May 2021 Answer ✓
    If you use #innerParameterName as your Item label template, (i.e. #parts), you can derive the template from an inner parameter in order to get behavior similar to the Loft Feature. This is described in the documentation here. It's also possible that things may number themselves automatically in the desired way if you simply remove the "Item Label Template" tag of the group annotation entirely.

    Getting more control than that, however, is pretty difficult. One method is to use a hidden parameter as the item label template and then update the hidden parameter using Editing Logic - however, you will have to be careful to avoid this bug, although I don't think you're using those types of queries in your feature. If you do go this route, my custom function arrayItemChanges may also be of use to you.

    As a final note, it may be tempting to try and use setFeatureComputedParameter to easily set group names, which is how the variable Feature gives itself custom names - however, that only works for the feature name itself, and not array parameters. Ugh.

Answers

  • Alex_KempenAlex_Kempen Member Posts: 221 EDU
    edited May 2021 Answer ✓
    If you use #innerParameterName as your Item label template, (i.e. #parts), you can derive the template from an inner parameter in order to get behavior similar to the Loft Feature. This is described in the documentation here. It's also possible that things may number themselves automatically in the desired way if you simply remove the "Item Label Template" tag of the group annotation entirely.

    Getting more control than that, however, is pretty difficult. One method is to use a hidden parameter as the item label template and then update the hidden parameter using Editing Logic - however, you will have to be careful to avoid this bug, although I don't think you're using those types of queries in your feature. If you do go this route, my custom function arrayItemChanges may also be of use to you.

    As a final note, it may be tempting to try and use setFeatureComputedParameter to easily set group names, which is how the variable Feature gives itself custom names - however, that only works for the feature name itself, and not array parameters. Ugh.
  • MichaelPascoeMichaelPascoe Member Posts: 929 PRO
    Thanks @Alex_Kempen
Sign In or Register to comment.