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.
In Part/assembly properties allow part number to be a formula
ryan_mcgoldrick
Member Posts: 71 ✭✭✭
Example,
Our part numbers are made from
Project number- Item Number - Version Number - Release Number
In solidworks we could use a formula to automatically generate the Part number
something like #/= Project number - Version Number - Release Number
- = Dash not a minus.
Our part numbers are made from
Project number- Item Number - Version Number - Release Number
In solidworks we could use a formula to automatically generate the Part number
something like #/= Project number - Version Number - Release Number
- = Dash not a minus.
0
Comments
I've done something like this before so it renumbered my entire project.
Basically for the fields here you jut make variables
Here is some base code to get you started:
FeatureScript 1403; import(path : "onshape/std/geometry.fs", version : "1403.0"); annotation { "Feature Type Name" : "Part Propertiesx", "Feature Name Template" : "#Name" } export const PartProperties = defineFeature(function(context is Context, id is Id, definition is map) precondition { annotation { "Name" : "Part", "Filter" : EntityType.BODY && BodyType.SOLID && AllowFlattenedGeometry.YES, "MaxNumberOfPicks" : 1 } definition.entities is Query; annotation { "Name" : "Name" } isAnything(definition.name); annotation { "Name" : "Name Includes Part Number", "Default" : true } definition.NameWithPartNumber is boolean; annotation { "Name" : "Job Number" } isInteger(definition.JobNumber, POSITIVE_COUNT_BOUNDS); annotation { "Name" : "Unit Number" } isInteger(definition.UnitNumber, POSITIVE_COUNT_BOUNDS); annotation { "Name" : "Detail Number" } isInteger(definition.DetailNumber, POSITIVE_COUNT_BOUNDS); annotation { "Name" : "Is Sub Detail", "Default" : false } definition.isSubDetail is boolean; if (definition.isSubDetail) { annotation { "Name" : "Sub Detail Number" } isInteger(definition.SubDetailNumber, POSITIVE_COUNT_BOUNDS); } } { const part = evaluateQuery(context, definition.entities); const JobNumber = toString(definition.JobNumber); /* add leading zeros Detail number */ var x = definition.DetailNumber; if (x < 10) { x = "00" ~ toString(x); } else if (x < 100) { x = "0" ~ toString(x); } else { x = "" ~ toString(x); } const DetailNumber = x; /* add leading zeros Unit Number */ x = definition.UnitNumber; if (x < 10) /* add leading zeros */ { x = "00" ~ toString(x); } else if (x < 100) { x = "0" ~ toString(x); } else { x = "" ~ toString(x); } const UnitNumber = x; /* Format Part Number */ var PartNumber = definition.JobNumber ~ "-" ~ UnitNumber ~ "-" ~ DetailNumber; /* Add .number for sub details */ PartNumber ~= definition.isSubDetail ? "." ~ definition.SubDetailNumber : ""; /* Rename part to include part number if wanted */ const Name = definition.NameWithPartNumber ? PartNumber ~ " - " ~ definition.name : definition.name; /* Make Feature on tree match part name */ setFeatureComputedParameter(context, id, { "name" : "Name", "value" : Name }); /* Save properties to part */ if (part == []) throw regenError(ErrorStringEnum.CANNOT_RESOLVE_ENTITIES, ["entities"]); const Part = part[0]; setProperty(context, { "entities" : Part, "propertyType" : PropertyType.PART_NUMBER, "value" : PartNumber }); setProperty(context, { "entities" : Part, "propertyType" : PropertyType.NAME, "value" : Name }); setProperty(context, { "entities" : Part, "propertyType" : PropertyType.DESCRIPTION, "value" : definition.name }); });