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.

Feature Calculates Mass Property

Davide_CevDavide_Cev Member Posts: 6 PRO
Hi everyone,
I need some help to do this.

What I would like to have is that the mass property, which is a custom property that I've added, Is automatically compiled.
So that in the title block of the production drawing the mass of the component is always updated.

The solution that I've found is to develop a custom feature that measures the mass of the part and compile the custom property.

you can check at this link what I've done so far: 
https://cad.onshape.com/documents/56b59ac47699cf31866a698d/w/df0510ed020f5db0b0d8a8fe/e/99c72fb60c4de7132419cfba

and below the code of the feature script:

FeatureScript 1036;
import(path : "onshape/std/geometry.fs", version : "1036.0");

annotation { "Feature Type Name" : "Mass Calculator", "Feature Name Template" : "#name = #value", "UIHint" : "NO_PREVIEW_PROVIDED" }
export const massCalc = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "Name", "Default" : "Part Mass" }
        definition.name is string;
        
        annotation { "Name" : "Part to measure", "Filter" : EntityType.BODY && BodyType.SOLID, "MaxNumberOfPicks" : 1 }
        definition.part is Query;
   
    }
    {
           
        const result is MassProperties = evApproximateMassProperties(context, {
                        "entities" : definition.part,
                        "density" : 100 * kilogram / meter ^ 3 // this should be read from the part properties.
                });
            
        setFeatureComputedParameter(context, id, {
                "name" : "value",
                "value" : result.mass
        });     
        
        setVariable(context, definition.name, result.mass);
        
        setProperty(context, {
                "entities" : definition.part,
                "propertyType" : PropertyType.CUSTOM,
                "customPropertyId" : "5bf830cdfea53914efe3d9d9",
                "value" : toString(result.mass/kilogram)
        });
        println(toString(result.mass/kilogram));
    });


 
Everything works, but the mass is calculated with the wrong density.
Is there any way get the density value of the part,
so that the mass change if I change the material assigned to the part?


Comments

Sign In or Register to comment.