Overriding Maya´s textureWindowCreateToolBar

I have made a custom UV editor as some of you might know, and I´m having an issue running it side by side with Maya´s native UV Texture Editor (not literally ofc, as the UV Texture Editor is a singleton).
Before I knew better, I had taken the textureWindowCreateToolBar.mel from Maya´s install directory (under /scripts/others/) and hacked it with my own stuff and placed it in the user script dir.

But now in later versions, I no longer desires that as it overrides the toolbar in the default UV Texture Editor. Instead, I´m using a copy with a different name, like this:
textureWindowCreateToolBar_NSUV.mel

…which I then source from my PyMEL -script.

This works better, but I´m still not fully there. If I start up the native editor then everything is like it should (the default editor is loaded) - without any of my stuff in it.
However, once I start NSUV and textureWindowCreateToolBar_NSUV.mel gets sourced, it also seem to override the native toolbar.
So, closing down NSUV and then opening the native editor, my custom sidebar goes away (as it´s defined in a PyMEL script), but the Maya still thinks that the toolbar from textureWindowCreateToolBar_NSUV.mel should be used instead of textureWindowCreateToolBar.mel in the install dir/scripts/others/

I think this might be due to the fact that the “polyTexturePlacementPanel1” isn´t refreshed/recreated/deleted when the native editor starts. That panel is overrided by NSUV like this:

pm.scriptedPanel( 
    "polyTexturePlacementPanel1", edit=True,
    replacePanel=panelUV,            
)

…and then the override just stays (doing a pm.deleteUI(“polyTexturePlacementPanel1” and restarting the native UV texture editor, doesn´t resolve anything. Maya is still using the overridden version)

TL;DR
I need a way of opening up a custom textureWindowCreateToolBar.mel and temporarly overriding the “polyTexturePlacementPanel1” -panel. A way that doesn´t interfere with the native UV Texture Editor.

The problem you are encountering is even though you have copied and renamed the MEL script that creates the UI, you probably didn’t rename any of the Functions inside, so as soon as you source your version, you override the default UV editor, unless you re-source the original file again.

I would first try re-sourcing the original file when your UI is closed or deleted.

Personally, I would leave the UV editor unmodified and simply re-parent it to a paneLayout. That way you keep the original UV editor in one panel, and another panel contains all of your additional features. This is how I handle our internal extensions to the UV editor.

you could always do something like this


        flowLayout = pm.melGlobals['gUVTexEditToolBar']
        frameLayout = pm.flowLayout(flowLayout, q=True, p=True)
        frameLayout = pm.uitypes.FrameLayout(frameLayout)
        pm.deleteUI(flowLayout)

        flowLayout = pm.flowLayout(p=frameLayout)

to get the texEditToolBar, delete and start from scratch building a UI for it in pymel