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.

In Part/assembly properties allow part number to be a formula

ryan_mcgoldrickryan_mcgoldrick Member Posts: 66 ✭✭✭
edited December 2020 in Data management
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.
0
0 votes

Declined · Last Updated

Due to the current close tie to Release management, we will be opting to integrate to another system to provide this sort of number generator.

Comments

  • lougallolougallo Member, Moderator, Onshape Employees, Developers Posts: 2,001
    We will not be considering this at this time due to the close tie to Release management but are looking at integration into other systems that do this number scheme.
    Lou Gallo / PD/UX - Support - Community / Onshape, Inc.
  • john_mcclaryjohn_mcclary Member, Developers Posts: 3,894 PRO
    edited December 2020
    you can do this today very easily with featurescript.

    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
                    });
        });

Sign In or Register to comment.