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.
How to compute a part property

Hello, I would like to calculate the price of a part based on its mass and its price/kg. I created a property (type List) to select the price/kg of the supplier. The display is the supplier name and the value is its price/kg.
I want to code a feature that get this value, multiply it by the mass of the piece and return the price of the piece to visualise it in my BOM.
Here is the script I get from an LLM but when I create my property and select this feature as the property function source, the cases of the column of the property in the BOM returns "no value", even if the supplier and the mass are known.
FeatureScript 2615;
import(path : "onshape/std/common.fs", version : "2615.0");
annotation { "Property Function Name" : "getCoutMatiereBrute" }
export const getCoutMatiereBrute = defineComputedPartProperty(function(context is Context, part is Query, definition is map) returns number
{
// 1. Lire le prix au kg depuis la propriété "Prix au kg fournisseur brut (€/kg)"
const prixStr = getProperty(context, {
entity : part,
propertyType : PropertyType.PART,
propertyName : "Prix au kg fournisseur brut (€/kg)"
});
// 2. Convertir string → nombre var prixKg = 0.0; if (isStringLiteral(prixStr)) { prixKg = stringToNumber(prixStr); } // 3. Lire le matériau de la pièce const material = getProperty(context, { entity : part, propertyType : PropertyType.PART, propertyName : "Material" }); // 4. Obtenir la densité (kg/m³) const densite = lookupTableDensity(material); // 5. Calculer le volume (m³) const volume = evVolume(context, { entities : part }); // 6. Calculer la masse (kg) const masse = volume * densite; // 7. Retourner le coût brut (nombre sans unité) return prixKg * masse;
});
Thanks for your help
Comments
Before digging into your FeatureScript, have you configured the custom property in your company settings? "Prix au kg fournisseur brut (€/kg)"
Your company will need to have access to Onshape's paid subscription in order to create custom properties.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
There are multiple issues with your code, and yet another example of why you shouldn't use an LLM.
No LLM can produce working featurescript code.
getProperty doesn't even have a "propertyName" parameter
lookupTableDensity → doesn't exist in standard code
getProperty to string conversion is a mess and all wrong…
Custom FeatureScript and Onshape Integrated Applications
Caden's right. If you really need this functionality, I suggest either learning how to FeatureScript the right way.
Or hire a developer that already knows it:
In the future, Onshape's AI Advisor may have knowledge of FeatureScript and App development.
But at the moment you will not be able to use LLM's very well for FeatureScript.
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴