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.
Linear Mass Custom Property via FeatureScript
graeme_anderson
Member Posts: 9 PRO
I have successfully created a few lines of FeatureScript to take the volume of a 100mm long extrusion and output the volume per metre (including changing the units) using evVolume.
I want to do the same thing with mass per metre, but it appears evApproximateMassProperties requires a hard-called density, even though the part has a material assigned. I suspect this is why my FeatureScript compiles correctly, but the Custom Property it is linked to returns "computation failed."
FeatureScript code:
annotation { "Property Function Name" : "computeLinearMass" }
export const computeMass = defineComputedPartProperty(function(context is Context, part is Query, definition is map) returns string
{
var linearMass = evApproximateMassProperties(context, { "entities" : part, "density" : 1 * kilogram / meter ^ 3 });
linearMass = toString(roundToPrecision((linearMass / 100), 3)) ~ "g/m"; //convert part mass in kg to gram per linear metre, extrusion only, part must be modelled 100mm long
return linearMass;
});
export const computeMass = defineComputedPartProperty(function(context is Context, part is Query, definition is map) returns string
{
var linearMass = evApproximateMassProperties(context, { "entities" : part, "density" : 1 * kilogram / meter ^ 3 });
linearMass = toString(roundToPrecision((linearMass / 100), 3)) ~ "g/m"; //convert part mass in kg to gram per linear metre, extrusion only, part must be modelled 100mm long
return linearMass;
});
Have anyone found a way around this limitation?
Tagged:
0
Comments
Trying it shows that there was a units error, as well as evApproximateMassProperties returning several things besides mass. A working version is:
export const computeMass = defineComputedPartProperty(function(context is Context, part is Query, definition is map) returns string
{
var linearMass = evApproximateMassProperties(context, { "entities" : part, "density" : 1 * kilogram / meter ^ 3 }).mass;
linearMass = toString(roundToPrecision((linearMass / (100 * millimeter)) / (gram / meter), 4)) ~ " g/m"; //convert part mass in kg to gram per linear metre, extrusion only, part must be modelled 100mm long from the Front Plane
return linearMass;
});
var material = getProperty(context, { "entity" : part, "propertyType" : PropertyType.MATERIAL }); var linearMass = evApproximateMassProperties(context, { "entities" : part, "density" : material.density }).mass;