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 to I set the label for each new variable in feature script

daniel_cravensdaniel_cravens Member Posts: 29

Two related questions.

1. I would like to change the label for each new joint from #?:? how do I do that?
2. I would like to change the button title from "new variable" to "new joint", how would I do that?

Full code below.



****
annotation { "Feature Type Name" : "uiDoveTailSketch", "Editing Logic Function" : "onFeatureChange" }
export const CreateDoveTail = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "edge for split", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
        definition.edge is Query;     
        
        annotation { "Name" : "Base" }
        isLength(definition.tBase, LENGTH_BOUNDS);       
       
        annotation { "Name" : "Height"}
        isLength(definition.tHeight, LENGTH_BOUNDS);   

        annotation { "Name" : "Flair Angle"}
        isAngle(definition.tAngle, ANGLE_360_BOUNDS);
        
                   
        annotation { "Name" : "Joints", "Item name" : "Variable", "Item label template" : "###name : #value" }
        
        definition.joints is array;
        
        for (var variable in definition.joints)
        {
            
            annotation { "Name" : "Offset"}
            isAnything(variable.vOffset);
                       
            annotation { "Name" : "Depth" }
            isAnything(variable.vDepth);  
        }
        

        
         
        
        annotation { "Name" : "Flip" }
        definition.flipped is boolean;
        
        
       
   
    }
    {
  
        opDoveTailSketch(context, id, definition);
            
            
        
    });    


export function onFeatureChange(context is Context, id is Id, oldDefinition is map, definition is map,
    isCreating is boolean, specifiedParameters is map, hiddenBodies is Query) returns map
{
    println("OnFeatureChange");
    
    if(size(definition.joints) == 0)
    {
        definition.tHeight = .01 * meter;
        definition.tAngle = 65 * degree;
    }
    else
    {
        if (size(oldDefinition.joints) < size(definition.joints) && size(definition.joints) > 1)
        {
            println("Adding joint");
            definition.joints[size(definition.joints)-1] = definition.joints[size(definition.joints)-2];

        }
    }
    

    

    return definition;
}

Comments

  • Caden_ArmstrongCaden_Armstrong Member Posts: 177 PRO
    In the annotation for the array parameter type:

     "Item name"  is what you will see in the "Add X" button in the UI. So change this from Variable to Joint.
     "Item label template" is how each item is named. Doing "#parametername" will set the value to the value of that parameter. So if you want it set to the offset, you would do "#vOffset"
    www.smartbenchsoftware.com --- fs.place --- Renaissance
    Custom FeatureScript and Onshape Integrated Applications
  • daniel_cravensdaniel_cravens Member Posts: 29
    Fantastic. Thank you.
Sign In or Register to comment.