"""
EVS Script
"""
import evs

subsettingcomponent = evs.get_module('plume shell', 'Data Processing', 'Subsetting Component')
subsettinglevel = evs.get_module('plume shell', 'Data Processing', 'Subsetting Level')

new_analyte_index = subsettingcomponent
old_analyte_index = int(evs.get_module('trigger script', 'Variables', 'N1'))
outputnodaldata = evs.get_module_extended('plume shell', 'Data Processing', 'Output Nodal Data')
analyte_names = outputnodaldata['Options']

old_name = analyte_names[old_analyte_index]
new_name = analyte_names[new_analyte_index]

for mod in evs.get_modules():
    if mod.find(old_name) > -1:
        newName = mod.replace(old_name, new_name)
        evs.rename_module(mod, newName)

evs.set_module(newName, 'Subsetting Values', 'Subset List', [{'Component': new_analyte_index, 'IncludeConstantSurface': True, 'SubsettingDirection': 1, 'SubsettingLevel': subsettinglevel}])

#Save last used index
evs.set_module('trigger script', 'Variables', 'N1', new_analyte_index)
