app4soft
1 supporter
How to add Physical Property into FreeCA ...

How to add Physical Property into FreeCAD

Jul 02, 2023

FreeCAD 0.21 release is coming soon, which means all feature requests are now frozen and no new features would be add till the next release.

For now FreeCAD has no implemented materials yet, but its already possible to add material manually "by hands".

In this tutorial I will show You how to solve this missing feature issue with a workaround trick.

What is Material?

Material, in the means of physical properties, defines Color, Volume, Density, Mass of the physical object (in the CAD apps its called as Solid Part or Solid Body), where:

Mass=Volume*Density

What is Property and Expression?

Every object in FreeCAD has a set of properties of various types, which could be called using internal API.

Any Property could be used in value inputs fields in a form of Expressions.

Base solid object in FreeCAD is the PartDesign Body (aka Body, which Shape defined with one or a set of PartDesign Features).

Latest FreeCAD 0.21 weekly builds (test builds) already has a property to calculate and return volume of shapes in cubic millimeters (FreeCAD internally uses mm as length units, mm^2 as area units and mm^3 for volume) as next:

Body.Shape.Volume

(where Body is a Label name, UID of any object inside project tree)

For calculating the Mass its just need to know Density value of the Material of the Body — the rest could be solved with Expressions inside Property Value.

So, the first thing to do is defining Material of the body — for that it would be nice to has a list of materials. How to do that?

Adding Material Property

Lets start with creating custom Property in Property editor:

  • Select existing Body object in the Model tab of Combo view panel (for create bodies use PartDesign Workbench);

  • Move pointer on the Data tab and Right-click or press Menu key to open context menu. In the context menu "Show all";

  • Now You may see more properties, because some properties are set to be hidden by default.

  • Move pointer on any existing Propery (first column), open context menu again (it also has listed more options now) and click on "Add property";

  • In "Add property" dialog set Type as:

App::PropertyEnumeration

  • Set Group name (e.g. Physical, or use any other name) that would be a separator in Property table;

  • Set Name as Material and click OK. Now there is new entry in the table

  • Material row also has a collapsable sub-row Enum — fill it with a list of possible materials. Click in on its Value cell and on the right click tripple dot ("...") button — You would see a text editor with numbered lines. Input a list of possible materials names, for example here are three materials designed part might be made from:

1060 Aluminium Alloy

ABS

Plain Carbon Steel

  • Click OK, and now in the Material row there would be a drop-down list with the listed materials:

Adding Density Property

  • Now add new property for Density (see previous steps), but for this use next Type:

App::PropertyDensity

  • After Density property would be created click on its Value char and press "f(x)" (blue circle button on the right of entry field) or type "=" (equal key) to open "Formula editor" (alternatively open it with move pointer directly on the Density property name on the left in a a row, open context menu and click "Expression..."). In "Formula editor" type next expression:

(Physical_Material == 0 ? 2700 : (Physical_Material == 1 ? 1020 : (Physical_Material == 2 ? 7800 : 0))) * 1 kg/m^3

  • In this formula:

    • Physical_Material is a variable of Material property from Physical group;

    • == (double equal) is an "IF EQUAL" operator to check active list ID, here for App::PropertyEnumeration numbering starts with 0 (zero) for first list entry;

    • ? (question mark) is an "THEN" operator used to otput "TRUE" and "FALSE", where "FALSE" value is coming after "TRUE" value and separated with":" (colon) symbol (read more about Conditional expressions on FreeCAD wiki);

    • 2700, 1020 and 7800 are possible values of the Density (in kg/m^3) of the first (i.e. 1060 Aluminium Alloy), the second (i.e. ABS) and the third (i.e. Plain Carbon Steel) materials on the Material property list accordingly;

    • 0 (zero) is the last "FALSE" value in these sequence added just for the case if Material property would not be set or might be broken;

    • * 1 kg/m^3 (multiply by one kilogram ) is used to set units of Density input value as kg/m^3 (as said, FreeCAD internally uses g/mm^3 units for App::PropertyDensity, so this part of the expression is used just for simplify entering real density values listed in catalogs in kg/m^3).

Adding Volume Property

  • Now add new property for Volume (see previous steps), but for this use next Type:

App::PropertyVolume

  • As a formula for Volume property set the next expression:

.Shape.Volume

  • Here we call .Shape.Volume ("dot" means a reference link) without defining Label of the Body, because we call it from the actual object, so it is relative value (for object with the label Body both Body.Shape.Volume and .Shape.Volume are equal calls for be referenced);

Adding Mass Property

  • Now add new property for Mass (see previous steps), but for this use next Type:

App::PropertyMass

  • As a formula for Mass property set the next expression:

Physical_Density * Physical_Volume

Hide Unneeded Properties

  • Now set Density, Volume and Mass as a "Read-only" properties (to not mistakenly modify it in the future). To do that move pointer on each property and in context menu set "Read-only" and finally uncheck "Show all".

Enjoy

Since now your FreeCAD project file would include Body with defined Material and Density, and its Volume and Mass would be auto-calculated and re-calculated if choose another material from a drop-down list of available materials.

FCStd-file for FreeCAD 0.21 available for free: https://www.patreon.com/posts/85447291

Thank You all for your support!

P.S.

There are plenty of addons for FreeCAD that may help to calculate physical properties (e.g. Arch Survey, Macro FCInfo, etc.), but most of them are just calculators that does not store physical properties in the project file.

Actual tutorial has been designed to show how to make storable physical properties in FreeCAD 0.21 without installing any 3rd-party addons.

Enjoy this post?

Buy app4soft a coffee