from dlubal.api import rfem, common

def main():
    with rfem.Application(port=9000) as rfem_app:
        # Check subscription info
        print(rfem_app.get_subscription_info())

        # Get global settings tree table for Steel Design add-on (active model)
        design_settings: rfem.GlobalSettingsTreeTable = rfem_app.get_design_settings(
            addon=rfem.DesignAddons.STEEL_DESIGN
        )
        print(f"rfem.DesignAddons.STEEL_DESIGN:\n{design_settings}")
        # *************************************************************************
        chapter = 'configuration'
        key1='configuration_uls'
        design_path = [
            chapter,
            key1
        ]
        # get_tree_value is not necessary just for demonstration
        # it is the best way to test the path, if it is wrong None is returned
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=True,
        )

        key1 = 'configuration_sls'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f'{design_path}: {design_val}')
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=False,
        )

        key1 = 'configuration_fire_resistance'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=False,
        )

        # *************************************************************************
        chapter = 'analysis_method'
        key1 = 'analysismethod_member' # 0 - global, 1 - member, 2 - surface
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=1,
        )

        key1 = 'analysismethod_surface'  # 0 - global, 1 - member, 2 - surface
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=1,
        )

        # *************************************************************************
        chapter='member_slendernesses'
        key1='member_slendernesses_tension_ec3'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=240,
        )

        key1='member_slendernesses_compression_ec3'
        design_path = [
            chapter,
            key1
        ]
        design_val = common.get_tree_value(
            tree=design_settings,
            path=design_path
        )
        print(f"{design_path}: {design_val}")
        common.set_tree_value(
            tree=design_settings,
            path=design_path,
            value=210,
        )



        # Set specific value from the global settings
        rfem_app.set_design_settings(
            addon=rfem.DesignAddons.STEEL_DESIGN,
            global_settings_tree_table=design_settings
        )

if __name__ == '__main__':
    main()