Production Equipment Model | Dual Live Analysis Folders from Enterprise Production Model rename

Renaming Enterprise Name in Production Equipment Model

You rename your Enterprise name in the Production Model and find that the old and the new Folder(s) name
are now present in the MES Tag Provider

Solution

valid for MES 3.0

to clear up the old legacy Live Analysis Folder we need to run this script in a GW Scope
for example as a Tag Change Script

Python
    f = system.mes.object.filter.createFilter()
f.setMESObjectTypeName("Enterprise")
ent_name = system.mes.loadMESObjects(f).get(0).getName()
from java.lang import Class
from com.inductiveautomation.ignition.common.tags.paths.parser import TagPathParser
from com.inductiveautomation.ignition.common.browsing import BrowseFilter
from com.inductiveautomation.ignition.gateway.tags.managed import ProviderConfiguration
clazz = Class.forName('com.sepasoft.production.gateway.ProductionContext', False, f.class.getClassLoader())
context = clazz.getDeclaredMethod('getInstance').invoke(None)
tag_manager = context.getGatewayContext().getTagManager()
provider = tag_manager.getOrCreateManagedProvider(ProviderConfiguration('MES'))
for x in tag_manager.browseAsync(TagPathParser.parse('[MES]'), BrowseFilter()).get().getResults():
if x.getName() != ent_name:
provider.removeTag(x.getName())

This should run on the Gateway that has the extra Folder. (in Enterprise Settings, Tags are only on a Gateway and not synced.
It removes all top-level folders that do not have a name matching the current Enterprise