Open UV editor via Python

Open UV editor via Python

introbuck
Advocate Advocate
1,835 Views
3 Replies
Message 1 of 4

Open UV editor via Python

introbuck
Advocate
Advocate

Is there any way to open UV editor via Python??

0 Likes
Accepted solutions (1)
1,836 Views
3 Replies
Replies (3)
Message 2 of 4

fowlert
Autodesk
Autodesk

The runtime command to open it is TextureViewWindow, so I guess you could do something like...

import maya.cmds as cmds

cmds.TextureViewWindow()
Message 3 of 4

introbuck
Advocate
Advocate

Thank you! As i noticed the mel command of UV  is:

TextureViewWindow

and Python just added those lines:

import maya.cmds as cmds

cmds.

 So to "convert" any of standart editors (no only) to Python i have to add those lines? 

0 Likes
Message 4 of 4

fowlert
Autodesk
Autodesk
Accepted solution

Yes, if you want to call a Maya Command then you can import maya.cmds and call one of the commands like we have there.  The other common thing you'll probably end up doing at some point is wanting to call a MEL procedure, and for that you would do something like...

import maya.mel as mel
mel.eval('someMelProcedure()')

 

If you're trying to put together a script by looking at what you see in the Script Editor then might see a mix of commands and mel procedures.  To know what everything is you can use "whatIs".  e.g. in the script editor you can run...

mel.eval('whatIs "TextureViewWindow"')
# Result: Run Time Command # 

mel.eval('whatIs "toggleUIComponentVisibility"')
# Result: Mel procedure found in: D:/Program Files/Autodesk/Maya2020/scripts/startup/UIComponents.mel # 

 

So to call TextureViewWindow from Python you know you'll need to use maya.cmds, but if you wanted to call toggleUIComponentVisibility then you'd have to execute mel by using mel.eval.

 

Hope that helps