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: 8 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: 

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

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?


  • MBartlett21MBartlett21 Member, OS Professional, Developers Posts: 2,017 EDU
    Sorry, you cannot get the mass density from the part.
    You can set the part's material in your FeatureScript and have the user insert a name and a density if you want
    mb - draughtsman - also FS author: View FeatureScripts
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 4,397
    Unfortunately not - there is no way currently to read custom properties. Please create an improvement request (the nearest I could find is this: https://forum.onshape.com/discussion/comment/45034#Comment_45034)
    Director, Technical Services, EMEAI
  • john_mcclaryjohn_mcclary Member, Developers Posts: 3,709 PRO
    edited April 2019
    Here is a link to my solution.


    It works great, even changes the part color to match the material, paint, or override to custom color.
    also re-numbers my parts etc..

    you basically need to have your own custom material library hard coded, or csv (I'm not smart enough to figure that out)
    I have a custom material too that lets you add a material name and density on the fly.

    Steal what you can from it, but it writes to custom properties, so you will need to address that.

    Also this outputs in pounds, so get rid of the *2.2 on line 357

    Remember, if you change a property manually (using the BOM, or Onshape builtin features like "assign material") feature scripts will no longer write to that property. You will have to break its internal ID and create a new part. (usually I'd delete the first feature of the part and re-create it, then chase the red down the tree)
  • chrisjh777chrisjh777 Member Posts: 199 ✭✭✭
    There is an IR regarding mass property to be automatically inserted into drawings here.  Seems to be hidden in a bottom drawer.

  • sebastian_glanznersebastian_glanzner Member, Developers, Simulation EVP Posts: 256 PRO
    edited April 2019
    Nice feature script! I also wrote me a small featureScript to set materialname, density and surface.
    It can calculate the mass and stores it in a custom property.

    But how can you get the mass of an assembly to automatically display in the drawing?
    At the moment I have to set the property manually  :(
  • john_mcclaryjohn_mcclary Member, Developers Posts: 3,709 PRO
    Assemblies are still manual, but typically I only have a hand full of them, so I make due :(
  • sebastian_glanznersebastian_glanzner Member, Developers, Simulation EVP Posts: 256 PRO
    Thanks, I have this a lot  :#
    I hope Onshape will make the original mass value available in the drawing (BOM and title block).
  • brucebartlettbrucebartlett Member, OS Professional, Mentor, User Group Leader Posts: 2,123 PRO
    edited April 2019
    I am looking for a solution here. ATM I am leaving a blank space for mass on drawings and only adding manually when really needed but it would be nice to have it automatically appear after setting the stock material on parts which I am doing out of a custom material library made into a stock list. 
    Engineer ı Product Designer ı Onshape Consulting Partner
    Twitter: @onshapetricks  & @babart1977   
  • romeograhamromeograham Member, Simulation EVP Posts: 612 PRO
    @brucebartlett I use Morgan's Set Material FS: https://cad.onshape.com/documents/3ca261a95938af152088fca8/v/e1a0d34103707be3050748c8/e/82151ac6fb25c86ba23d7f85?jumpToIndex=938

    It populates your Custom Properties with mass / volume values (you have to set Density for each instance), which then will populate your drawings.

    Works really well.

    HOWEVER: these types of FeatureScripts can't populate custom property fields if you've manually messed with the value there before....as long as the property is empty, it works great, and updates as you make changes to your geometry.
  • Davide_CevDavide_Cev Member Posts: 8 PRO
    Hello everyone, I'm back to ask again if there is a way to automatically compile a custom property mass with auto-calculated data?
    Morgan's feature is, great, but it's not automatic. 
    I've seen in the lasts updates that the tables can calculate the mass for each part in the partStudio.
    So I've tried to compile the data at the end of the feature studio that creates the table with all the masses but it doesn't work.
    I've also tried to call the table feature studio within a custom feature in the feature list, but it tells that cannot read the properties while the regeneration of the features is running.

    Ok it seems logical to not read some properties while they still have to be processed.

    But I don't understand why I can't read the density of the material applied to the part if I can read the volume at any time of the feature list.
    For sure the density will not be affected by a modeling feature.

    Reading the density properties will at least Morgan's feature automatically update the mass, if the material applied is changed.

    any suggestion?

    thanks in advance.
Sign In or Register to comment.