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.
Feature Calculates Mass Property
Davide_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:
https://cad.onshape.com/documents/56b59ac47699cf31866a698d/w/df0510ed020f5db0b0d8a8fe/e/99c72fb60c4de7132419cfba
and below the code of the feature script:
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?
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?
0
Comments
You can set the part's material in your FeatureScript and have the user insert a name and a density if you want
IR for AS/NZS 1100
https://cad.onshape.com/documents/f7a56fbf62f83047ff5224f6/w/1d122164d0c55df35ec0b460/e/9822f8561276
8d0b09c6e1c2
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
Edit:
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)
https://forum.onshape.com/discussion/7920/implement-mass-properties-of-materials-into-insert-sheet-reference-dropdown-for-drawings#latest
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
Thanks, I have this a lot
I hope Onshape will make the original mass value available in the drawing (BOM and title block).
Twitter: @onshapetricks & @babart1977
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.
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.