import rfem
from rfem.client import RFEM
from rfem.types_for_nodes.NodalSupport_pb2 import NodalSupport
from rfem.structure_core import Material

with RFEM(api_key_value='ak-542585dcc0644786a3eea8fa8babd3501c53193350ee4263') as client:
    client.create_model(rfem.Application.CreateModelRequest(name='cantilever'))

    structure = [
        Material(no=1, name='S235'),
        rfem.structure_core.Section(no=1, name='HEA 200', material = 1),
        rfem.structure_core.Node(no = 1),        # default values for coordinates 0/0/0 used
        rfem.structure_core.Node(no = 2, coordinate_1=3),
        rfem.structure_core.Line(no = 1, definition_nodes=[1,2]),
        rfem.structure_core.Member(no = 1, line = 1, section_start = 1)
    ]

    client.create_object_list(structure)

    client.update_object(rfem.types_for_nodes.NodalSupport(no = 2, nodes=[1]))  # changes nodes of default support number 2

    loading = [
        rfem.loading.LoadCase(no=2, name='DL'),
        rfem.loads.NodalLoad(no=1, load_case=2, nodes=[2], force_magnitude=10, load_direction=rfem.loads.NODAL_LOAD_LOAD_DIRECTION_GLOBAL_Z_OR_USER_DEFINED_W),
    ]

    client.create_object_list(loading)

    member = client.get_object(rfem.structure_core.Member(no=1))
    print(member)
