Next number in part number scheme feature script

How can I modify my featurescript for an O-ring part studio to automatically generate next part number for each new configuration, following the in-built onshape numbering scheme? Currently, I have to manually enter the desired configuration in the properties and create a version within the part studio. I have read that previously any new configuration that is imported to an assembly would automatically get a new line in the configured properties, but it doesnt seem to be the case.

Screenshot 2024-09-11 124021.png Screenshot 2024-09-11 124150.png

FeatureScript 2433;
import(path : "onshape/std/common.fs", version : "2433.0");

annotation { "Feature Type Name" : "Description with variables" }
export const descriptionWithVariables = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Part", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
definition.part is Query;

    annotation { "Name" : "ID" }
    isLength(definition.ID, LENGTH_BOUNDS);
    
    annotation { "Name" : "Thread" }
    isLength(definition.thread, LENGTH_BOUNDS);
    
    annotation { "Name" : "Material" }
    definition.myMaterial is MaterialOption;
    
    
    
    
}
{
    const IDString = makeLengthString(definition.ID, 5, millimeter, "mm");
    const threadString = makeLengthString(definition.thread, 5, millimeter, "mm");
    //const materialString = definition.myMaterial;
     // Manually set the materialString based on the enum value
    var materialString;
    if (definition.myMaterial == MaterialOption.ONE) {
        materialString = "FKM 70";
    } else if (definition.myMaterial == MaterialOption.TWO) {
        materialString = "NBR 70";
    } else if (definition.myMaterial == MaterialOption.THREE) {
        materialString = "EDPM 70";
    }
    
    
    setProperty(context, {
            "entities" : definition.part,
            "propertyType" : PropertyType.NAME,
            "value" : "O-ring," ~ IDString ~ " x " ~ threadString ~ ", " ~ materialString
            
    });
    setProperty(context, {
            "entities" : definition.part,
            "propertyType" : PropertyType.DESCRIPTION,
            "value" : "O-ring, " ~ IDString ~ " x " ~ threadString ~ ", " ~ materialString
    });
    
    
});

export function makeLengthString (value is ValueWithUnits, precision is number, unit, unitString is string) returns string
{
return roundToPrecision(value / unit, precision) -> toString() ~ " " ~ unitString;
}
export enum MaterialOption
{
annotation { "Name" : "FKM 70" }
ONE,
annotation { "Name" : "NBR 70" }
TWO,
annotation { "Name" : "EDPM 70" }
THREE,

}

Best Answers

Answers