Export Table to Excel#
|
Exporting RFEM model object and result tables to Excel:
Keywords:
Excel export truss object table results xlsx |
from math import inf
from dlubal.api import rfem, common
# -------------------------------------------------------
# This example demonstrates how to export RFEM tables to Excel.
# It creates and calculates a simple truss model, exports the node object table
# to one worksheet, and exports nodal deformation results to another worksheet.
# -------------------------------------------------------
# Editable parameters
EXCEL_FILE_PATH = "truss_export.xlsx"
NODES_SHEET_NAME = "Nodes"
DEFORMATIONS_SHEET_NAME = "Node Deformations"
def define_structure() -> list:
"""Define a simple triangular truss model."""
return [
rfem.structure_core.Material(
no=1,
name="S235",
),
rfem.structure_core.CrossSection(
no=1,
material=1,
name="RO 60.3x5.6",
),
rfem.structure_core.Node(
no=1,
coordinate_1=0.0,
coordinate_2=0.0,
coordinate_3=0.0,
comment="Start node",
),
rfem.structure_core.Node(
no=2,
coordinate_1=6.0,
coordinate_2=0.0,
coordinate_3=0.0,
comment="Right support",
),
rfem.structure_core.Node(
no=3,
coordinate_1=3.0,
coordinate_2=0.0,
coordinate_3=2.5,
comment="Loaded top node",
),
rfem.structure_core.Line(
no=1,
definition_nodes=[1, 2],
),
rfem.structure_core.Line(
no=2,
definition_nodes=[1, 3],
),
rfem.structure_core.Line(
no=3,
definition_nodes=[3, 2],
),
rfem.structure_core.Member(
no=1,
line=1,
type=rfem.structure_core.Member.TYPE_TRUSS,
cross_section_start=1,
),
rfem.structure_core.Member(
no=2,
line=2,
type=rfem.structure_core.Member.TYPE_TRUSS,
cross_section_start=1,
),
rfem.structure_core.Member(
no=3,
line=3,
type=rfem.structure_core.Member.TYPE_TRUSS,
cross_section_start=1,
),
rfem.types_for_nodes.NodalSupport(
no=1,
nodes=[1],
spring_x=inf,
spring_y=inf,
spring_z=inf,
),
rfem.types_for_nodes.NodalSupport(
no=2,
nodes=[2],
spring_y=inf,
spring_z=inf,
),
rfem.types_for_nodes.NodalSupport(
no=3,
nodes=[3],
spring_y=inf,
),
]
def define_loading() -> list:
"""Define one static load case with a vertical nodal load."""
return [
rfem.loading.StaticAnalysisSettings(
no=1,
analysis_type=rfem.loading.StaticAnalysisSettings.ANALYSIS_TYPE_GEOMETRICALLY_LINEAR,
),
rfem.loading.LoadCase(
no=1,
name="Top node load",
static_analysis_settings=1,
self_weight_active=False,
),
rfem.loads.NodalLoad(
no=1,
load_case=1,
nodes=[3],
load_type=rfem.loads.NodalLoad.LOAD_TYPE_COMPONENTS,
components_force_z=-10000.0,
),
]
# -------------------------------------------------------
# MAIN SCRIPT
# -------------------------------------------------------
with rfem.Application() as rfem_app:
# Initialize model
rfem_app.close_all_models(save_changes=False)
rfem_app.create_model(name='truss_model')
rfem_app.delete_all_objects()
# Create and calculate truss model
rfem_app.create_object_list(
define_structure() +
define_loading()
)
rfem_app.calculate_all(skip_warnings=True)
# Export node object table and nodal deformation results to one workbook
node_table = rfem_app.get_object_table(
object_type=rfem.OBJECT_TYPE_NODE,
show_header_details=True,
)
node_deformation_results = rfem_app.get_results(
results_type=rfem.results.ResultsType.STATIC_ANALYSIS_NODES_GLOBAL_DEFORMATIONS,
filters=[
rfem.results.ResultsFilter(
column_id="loading",
filter_expression="LC1",
),
],
)
common.export_to_excel.export_table_to_excel(
node_table,
common.export_to_excel.ExcelExportSettings(
sheet_name=NODES_SHEET_NAME,
include_table_header=True,
use_header_details=True,
),
excel_file_path=EXCEL_FILE_PATH,
)
common.export_to_excel.export_table_to_excel(
node_deformation_results,
common.export_to_excel.ExcelExportSettings(
sheet_name=DEFORMATIONS_SHEET_NAME,
include_table_header=True,
use_header_details=True,
),
excel_file_path=EXCEL_FILE_PATH,
)