Custom Material#
|
This example demonstrates how to update existing material as user-defined using helper functions for
|
from dlubal.api import rstab
from dlubal.api import common
import pprint
# -------------------------------------------------------
# This example shows how to create and modify a custom material
# in the model by using helper functions to interact with the
# tree table data structure in efficient way.
# -------------------------------------------------------
# Connect to the rstab application
with rstab.Application() as rstab_app:
# Initialize model
rstab_app.create_model(name="custom_material")
base_data = rstab_app.get_base_data()
base_data.addons.concrete_design_active = True
rstab_app.set_base_data(base_data=base_data)
rstab_app.delete_all_objects()
# Create a new material
rstab_app.create_object(rstab.structure_core.Material(
no=1, name="C30/37"
))
# Retrieve the material
material:rstab.structure_core.Material = rstab_app.get_object(
rstab.structure_core.Material(no=1)
)
# Update material values tree table
material_values_tree = material.material_values.rows[0].material_values_tree
common.tree_table.set_values_by_key(
tree=material_values_tree,
key='rho', # Mass density
values=[2400.0]
)
common.tree_table.set_values_by_key(
tree=material_values_tree,
key='gamma', # Specific weight
values=[24000.0]
)
# Update material standard parameters tree table
standard_params_tree = material.standard_parameters
common.tree_table.set_values_by_key(
tree=standard_params_tree,
key='class',
values=[5] # Structural class S5
)
c_min_dur = common.tree_table.get_values_by_key(
tree=standard_params_tree,
key='c_min_dur',
return_paths=True
)
pprint.pprint(c_min_dur)
common.tree_table.set_values_by_key(
tree=standard_params_tree,
key='c_min_dur',
values=[0.075],
path=[
'4_durability_and_concrete_cover',
'4_4_1_minimum_concrete_cover',
'table_4_4n_values_of_minimum_cover_c_min_dur_requirements_with_regard_to_durability_for_reinforcement_steel',
'values_of_minimum_cover_for_structural_class_s5'
],
occurrence=4 # Minimum cover for XC4
)
# Apply modified material back to the model
rstab_app.update_object(
obj=rstab.structure_core.Material(
no=1,
user_defined=True,
material_values=material.material_values,
standard_parameters=material.standard_parameters
)
)
using Rstab = Dlubal.Api.Rstab;
using Common = Dlubal.Api.Common;
using System.Runtime.InteropServices;
// -------------------------------------------------------
// This example shows how to create and modify a custom material
// in the model by using helper functions to interact with the
// tree table data structure in efficient way.
// -------------------------------------------------------
ApplicationRstab? rstabApp = null;
try
{
rstabApp = new ApplicationRstab();
// Initialize model
await rstabApp.create_model(name: "custom_material");
var base_data = await rstabApp.get_base_data();
base_data.Addons.ConcreteDesignActive = true;
await rstabApp.set_base_data(baseData: base_data);
await rstabApp.delete_all_objects();
// Create a new material
await rstabApp.create_object(
new Rstab.StructureCore.Material{
No = 1,
Name = "C30/37"
}
);
// Retrieve the material
Rstab.StructureCore.Material material = await rstabApp.get_object<Rstab.StructureCore.Material>(
new Rstab.StructureCore.Material{No= 1}
);
// Update material values tree table for a temperatue (row=0)
var materialValuesTree = material.MaterialValues.Rows[0].MaterialValuesTree;
Common.TreeTable.SetValuesByKey(
tree: materialValuesTree,
key: "rho", // Mass density
values: new List<object> { 2400.0 }
);
Common.TreeTable.SetValuesByKey(
tree: materialValuesTree,
key: "gamma", // Specific weight
values: new List<object> { 24000.0 }
);
// Update material standard parameters tree table
var standardParameters = material.StandardParameters;
Common.TreeTable.SetValuesByKey(
tree: standardParameters,
key: "class",
values: new List<object> { 5 } // Structural class S5
);
var c_min_dur = Common.TreeTable.GetValuesByKey(
tree: standardParameters,
key: "c_min_dur",
returnPaths: true
);
foreach (var item in c_min_dur)
{
if (item is Common.TreeTable.TreePathValue pv)
{
var path = string.Join(" / ", pv.Path);
Console.WriteLine($"Path: {path}, Value: {pv.Value}");
}
}
Common.TreeTable.SetValuesByKey(
tree: standardParameters,
key: "c_min_dur",
values: new List<object> { 0.075 }, // Minimum cover for XC4
path: new List<string> {
"4_durability_and_concrete_cover",
"4_4_1_minimum_concrete_cover",
"table_4_4n_values_of_minimum_cover_c_min_dur_requirements_with_regard_to_durability_for_reinforcement_steel",
"values_of_minimum_cover_for_structural_class_s5"
},
occurrence: 4
);
// Apply modified Material back to the model
await rstabApp.update_object(
obj: new Rstab.StructureCore.Material{
No= 1,
UserDefined= true,
MaterialValues= material.MaterialValues,
StandardParameters=material.StandardParameters
}
);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
finally
{
// Step 8: Close connection
if (rstabApp != null) await rstabApp.close_connection();
}