Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- 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.
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.
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
-
NeilCooke Moderator, Onshape Employees Posts: 5,671
There is no way to automate this, manual only I'm afraid.
Senior Director, Technical Services, EMEAI1 -
Caden_Armstrong Member Posts: 164 PRO
This can't be done with FeatureScript, but it can be done with the API.
www.smartbenchsoftware.com --- fs.place --- Renaissance
Custom FeatureScript and Onshape Integrated Applications1
Answers
Anyone?
There is no way to automate this, manual only I'm afraid.
This can't be done with FeatureScript, but it can be done with the API.
Custom FeatureScript and Onshape Integrated Applications