Create Material through C# Karamba

Hi,

I created a Karamba.Materials.FemMaterial_Isotrop through C# in Visual Studio, however the units are strange when you compare them in Grasshopper. There is a difference of 10 000 (from N/mm2 to kN/cm2, so this actually 1000). I can change this easily, but what should be the unit input of new Karamba.Materials.FemMaterial_Isotrop() ? The second image shows the definition.


Thanks,
Max

Nevermind, the standard units is set to kN or m. See picture below:

In the light of this: Is it possible to change the units through C# in visual studio?

kind regards,
Max

Hello @maxhamelynck,
by default, Karamba3D internally works with kN, meters and tons. These base units can be changed via the ‘karamba.ini’ file which resides in the installation folder.
For changing the base units via a C# script, one needs to reset some parts of Karamba3D so that no inconsistencies arise (see e.g, ‘Component_Settings’ in karamba.gha):

with

using Karamba.CrossSections;
using Karamba.Materials;
using Karamba.Utilities;
using Materials;
using Utilities;

one needs to clear these singletons

INIReader.ClearSingleton();
UnitsConversionFactory.ClearSingleton();
Material_Default.ClearSingleton();
CroSec_Default.ClearSingleton();
Default_Material_Table_220.ClearSingleton();
Default_Material_Table.ClearSingleton();
Default_CroSec_Table.ClearSingleton();

then it is possible to set

var ini_reader = INIReader.Instance();
ini_reader.Values[“UnitLength”] = “YourFavouriteLengthUnits”

like you would in the karamba.ini-file.

I recommend that however only in case of very large or very small structures. Otherwise, it is more comfortable to work with K3D units-conversion objects:

with

using Karamba.Utilities;

one gets a units-conversion object like this:

var ucf = UnitsConversionFactories.Conv();
UnitConversion cm = ucf.cm();

in order to convert a value from base units to an output unit use

cm.toUnit(YourValueInBaseUnitsHere)

the other way round works via

cm.toBase(YourValueInCMHere)

Be aware that ‘ucf.cm()’ returns a conversion from/to cm only by default and only for the SI system. In Imperial Units inch is used instead. The string representation of the actual unit can be found via ‘cm.unitB’.

–Clemens