PyQt

Mayaui

dpiScale(value)

Get the appropriate QSize based on maya’s current dpi setting

Parameters:

value (int or float) –

Returns:

Return type:

int

sizeByDpi(size)

Scales the QSize by the current dpi scaling from maya.

Parameters:

size (QSize) – The QSize to Scale by the dpi setting from maya

Returns:

The newly scaled QSize

Return type:

QSize

mayaWindow()
Returns:

instance, the mainWindow ptr as a QMainWindow widget.

Return type:

QtWidgets.QMainWindow

getMayaWindow()
Returns:

instance, the mainWindow ptr as a QMainWindow widget.

Return type:

QtWidgets.QMainWindow

mayaViewport()

Returns the currently active maya viewport as a widget :return: :rtype:

fullName(widget)
getMayaWindowName()

Returns the maya window objectName from Qt :return:

toQtObject(mayaName, widgetType=MockExt.QtWidgets.QWidget)

Convert a Maya ui path to a Qt object.

Parameters:

mayaName – Maya UI Path to convert eg. “scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|testButton”

Returns:

PyQt representation of that object

Return type:

QtWidgets.QWidget

outlinerPaths()
getOutliners()
openGraphEditor()
refreshOutliners()

Refreshes all outliner panels in maya

statusLineLayout()

Returns the maya status line as a QLayout

Return type:

QtWidgets.QLayout

applyScriptEditorHistorySyntax(sourceType, highlighter=None, **kwargs)
highlighterEditorWidget(sourceType, **kwargs)
suppressOutput()

Supresses all output to the script editor

restoreOutput()

Restores the script editor to include all results

setChannelBoxAtTop(channelBox, value)
Parameters:
  • channelBox (str) – mainChannelBox

  • value (bool) –

setChannelBoxAtTop("mainChannelBox",True)
setChannelShowType(channelBox, value)
Parameters:
  • channelBox (str) – mainChannelBox

  • value (str) –

setChannelShowType("mainChannelBox", "all")
activeModelEditor()

Get the model editor with focus.

modelEditors()

Returns all maya model editors

disableColorManagement(editors=None)

Disables color management for modelEditors.

Parameters:

editors (list of basestring) – List of Model Editors to disable.

Returns:

bool, True

enableColorManagement(editors=None)

Disables color management for modelEditors.

Parameters:

editors (list[str]) – List of Model Editors to disable.

Returns:

bool

setModelEditorColorManagement(editor, value)
rebuild(objectName)

If the bootstrap widget exists then we reapply it to mayas layout, otherwise do nothing.

Parameters:

objectName (str) – the bootStrap objectName

bootstrapDestroyWindow(objectName)

Function to destroy a bootstrapped widget, this use the maya workspaceControl objectName

Parameters:

objectName (str) – The bootstrap Widget objectName

Return type:

bool

class BootStrapWidget(*args: Any, **kwargs: Any)

Bases: MayaQWidgetDockableMixin, QWidget

Class to wrap mayas workspace dockable mixin into something useful,

customWidget = QtWidget()
boostrap = BootStrapWidget(customWidget, "customWidget")
boostrap.show(dockable=True, retain=False, width=size.width(), widthSizingProperty='preferred',
             minWidth=minSize.width(),
             height=size.height(), x=250, y=200)
setSizeHint(size)
close(*args, **kwargs)

Overridden to call the bootstrap user widget.close()

show(**kwargs)
dockableShow(*args, **kwargs)

Copied from mayaMixin.MayaQWidgetDockableMixin().show() so we can tweak the docking settings.

Nodeeditor

getPrimaryNodeEditor()

Find and return the name of the primary node editor if it exists.

Returns:

The node editor name

Return type:

str

createNodeEditor()

Creates(opens) the maya node editor.

Returns:

Returns the NodeEditorWrapper object linked to the current node editor.

Return type:

NodeEditorWrapper

currentNodeEditorPanel()

Returns the currently active node editor panel if any.

Returns:

The maya node editor panel name

Return type:

str

currentNodeEditor()

Returns the currently active nodeEditor name if any.

Note

This function should be used when using NodeEditorWrapper if you want to work with the current active Node Editor.

Note

This is not the same getPrimaryEditor() which doesn’t depend on user focus.

Returns:

The maya node editor path

Return type:

””

class NodeEditorWrapper(*args: Any, **kwargs: Any)

Bases: QObject

This class wraps Autodesk Maya’s node editor and provides Qt-related functions for working with it.

ATTR_VIEW_SIMPLE = 0
ATTR_VIEW_CONNECTED = 1
ATTR_VIEW_ALL = 2
ATTR_VIEW_CUSTOM = 3
ITEM_ALIGN_SPACING = 20
static nodeEditorAsQtWidgets(nodeEditor)

Returns the node editor widget, graphics view, and graphics scene as Qt widgets.

Parameters:

nodeEditor (str) – The node editor as a Maya or Qt object.

Returns:

The node editor widget, graphics view, and graphics scene as Qt widgets.

Return type:

Tuple[QtWidgets.QWidget, QtWidgets.QGraphicsView, QtWidgets.QGraphicsScene]

static itemsRect(items)

Returns the bounding rectangle that encloses the specified graphics items.

Parameters:

items (List[QtWidgets.QGraphicsItem]) – The list of graphics items.

Returns:

The bounding rectangle that encloses the graphics items.

Return type:

QtCore.QRect

exists()

Returns whether a Node Editor with the object’s name exists in Maya.

Returns:

True if a Node Editor with the object’s name exists, False otherwise.

Type:

bool

show()

Shows the Node Editor in Maya.

selectedNodeItems()

Returns the selected node items in the Node Editor.

Returns:

A list of the selected node items.

Return type:

List[QtWidgets.QGraphicsItem]

selectedConnections()

Returns the selected connections in the Node Editor.

Returns:

A list of the selected connections.

Return type:

List[QtWidgets.QGraphicsPathItem]

addNodes(nodes)

Adds a list of nodes to the current node editor

Parameters:

nodes (list(om2.MObject)) – a list of maya mobject representing valid nodes

addNodesOnCreate()

Returns whether new nodes are added to the Node Editor when they are created.

Returns:

True if new nodes are added to the Node Editor when they are created, False otherwise.

Return type:

bool

setAddNodesOnCreate(state)

Sets whether new nodes are added to the Node Editor when they are created.

Parameters:

state (bool) – True if new nodes should be added to the Node Editor when they are created, False otherwise.

setNodeAttributeDisplay(viewMode)

Sets either the currently selected node or all viewed nodes attribute display to one of the follow states,ATTR_VIEW_SIMPLE, ATTR_VIEW_CONNECTED, ATTR_VIEW_ALL and ATTR_VIEW_CUSTOM.

Parameters:

viewMode (int) – View mode based on NodeEditorWrapper.VIEW_MODE_# .

graphDownstreamFromSelection()

This Graphs the downstream nodes from the currently selected nodes.

itemTypeUnderCursor()

Returns the type of item under the cursor in the Node Editor.

Returns:

The type of item under the cursor.

Return type:

str

plugUnderCursor()

Returns the plug under the cursor in the Node Editor.

Returns:

The plug under the cursor.

Return type:

str

graphDownstreamFromPlug(plug)

Graphs the nodes downstream from the specified plug in the Node Editor.

Parameters:

plug (str) – The plug to graph downstream from.

graphUpstreamFromPlug(plug)

Graphs the nodes upstream from the specified plug in the Node Editor.

Parameters:

plug (str) – The plug to graph upstream from.

connectedGraphingModeContext()

A context manager that temporarily disables connected graphing mode in the Node Editor.

alignLeft(items=None)

Aligns a list of QGraphicsItems to the left-most x position.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignRight(items=None)

Aligns a list of QGraphicsItems to the left-most x position.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignTop(items)

Aligns a list of QGraphicsItems to the top-most y position.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignBottom(items)

Aligns a list of QGraphicsItems to the bottom-most y position.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignCenterX(items)

Aligns a list of QGraphicsItems to the center x position.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignCenterY(items)

Aligns a list of QGraphicsItems to the center y position.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignItemsDiagonallyLeftToRight(items=None)

Aligns a list of QGraphicsItems in a diagonal line from left to right, distributing them based on their bounding rectangles and a specified spacing value to prevent overlap. The x position of each item is set to half the width of the previous item.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

alignItemsDiagonallyRightToLeft(items=None)

Aligns a list of QGraphicsItems in a diagonal line from right to left, distributing them based on their bounding rectangles and a specified spacing value to prevent overlap. The x position of each item is set to half the width of the previous item.

Parameters:

items (List[QGraphicsItem]) – The list of QGraphicsItems to align. If not specified, the selected node items will be used.

disableNodeEditorAddNodeContext()

Context manager which disables the current nodeEditors “Add to graph on create” which slows the maya down alot. So this function temporarily disables it.

alignItemsToXPos(items, xPos, spacing=0)

Aligns a list of QGraphicsItems to a given x position, distributing them along the yaxis based on their bounding rectangles and a specified spacing value to prevent overlap.

Parameters:
  • items (List[QtWidgets.QGraphicsItem]) – The list of QGraphicsItems to align.

  • xPos (float) – The x position to align the items to.

  • spacing (float) – The spacing between the items. Default is 0.

alignItemsToYPos(items, yPos, spacing=0)

Aligns a list of QGraphicsItems to a given y position, distributing them along the xAxis based on their bounding rectangles and a specified spacing value to prevent overlap.

Parameters:
  • items (List[QtWidgets.QGraphicsItem]) – The list of QGraphicsItems to align.

  • yPos (float) – The y position to align the items to.

  • spacing (float) – The spacing between the items. Default is 0.

alignItemsDiagonallyLeftToRight(items, spacing=0)

Aligns a list of QGraphicsItems diagonally, centering the distribution around the average X and Y of the total bounding box of all items, and distributing them diagonally based on their bounding rectangles and a specified spacing value to prevent overlap.

Parameters:
  • items (List[QtWidgets.QGraphicsItem]) – The list of QGraphicsItems to align.

  • spacing (float) – The spacing between the items. Default is 0.

alignItemsDiagonallyRightToLeft(items, spacing=0)

Aligns a list of QGraphicsItems diagonally, centering the distribution around the average X and Y of the total bounding box of all items, and distributing them diagonally based on their bounding rectangles and a specified spacing value to prevent overlap.

Parameters:
  • items (List[QtWidgets.QGraphicsItem]) – The list of QGraphicsItems to align.

  • spacing (float) – The spacing between the items. Default is 0.

Scripteditor

class ScriptEditorState

Bases: object

Provides methods to suppress and restore script editor output.

suppress_results = None
suppress_errors = None
suppress_warnings = None
suppress_info = None
classmethod suppress_output()

Hides all script editor output.

classmethod restore_output()

Restores the script editor output settings to their original values.

Change Renderer UI

ui_loadRenderer(renderer)

Popup window for loading a renderer

Parameters:

renderer (str) – Renderer nicename

Return okPressed:

Was the ok button pressed or not

Rtype okPressed:

bool

checkRenderLoaded(renderer, bypassWindow=False)

Checks that the renderer is loaded, if not opens a window asking the user to load it

Parameters:
  • renderer (str) – the nice name of the renderer “Arnold” or “Redshift” etc

  • bypassWindow (bool) – If True don’t show the popup window, just return if the renderer is loaded or not

Return rendererLoaded:

True if the renderer is loaded

Rtype rendererLoaded:

bool

globalChangeRenderer(renderer, toolsets)

Updates all GUIs with the current renderer.

From toolset code run:

toolsets = toolsetui.toolsets(attr="global_receiveRendererChange")
self.generalSettingsPrefsData = elements.globalChangeRenderer(self.properties.rendererIconMenu.value,
                                                              toolsets,
                                                              self.generalSettingsPrefsData,
                                                              pc.PREFS_KEY_RENDERER)
Parameters:
  • renderer (str) – The renderer nice name to change to for all UIs

  • toolsets (list) – A list of all the toolset UIs to change. Should be strings but may be objects.

Returns:

The preferences data file now updated

Return type:

object

Cmds Widgets

class MayaColorBtn(*args: Any, **kwargs: Any)

Bases: QWidget, MenuCreateClickMethods

colorChanged

alias of object

colorDragged

alias of object

setColorMinimumWidth(width)

Set the minimum width of the color widget

Parameters:

width

Returns:

setColorMinimumHeight(height)

Set the minimum height of the color widget

Parameters:

width

Returns:

text()

returns the label name as a string

Return labelName:

the text name of the label

Rtype labelName:

str

fullName()
setColorFixedWidth(width)

Sets the size of the color widget, dpi scale handled

Parameters:

width (int) – Width in pixels of the color btn

setColorFixedHeight(height)

sets the size of the color widget, dpi scale handled

setDisabled(disabled=True)
setEnabled(enabled=True)
setDisabledLabel(disabled=True)
setColorLinearFloat(color, noEmit=True)

Sets the color as renderspace color (or linear) in 0-1.0 float ranges Eg (1.0, .5, .6666)

emits the color as a Srgb Int color Eg (0, 255, 134)

setColorSrgbFloat(color, noEmit=True)

sets the color as display tuple with 0-1.0 float ranges Eg (1.0, .5, .6666) emits the color as a display Int color Eg (0, 255, 134)

Note: Maya 2023 and above this now supports Display Color as SRGB. 2022 and below is SRGB only.

Parameters:
  • color (list(float)) – Color as display color float 0-1.0

  • noEmit (bool) – Emit the color?

setColorSrgbInt(color, noEmit=True)

Sets the color as srgb Int tuple with 0-255 integer ranges Eg (0, 255, 134)

Emits the color as a Srgb Int color Eg (0, 255, 134)

Note: Maya 2023 and above this now supports Display Color as SRGB. 2022 and below is SRGB only.

Parameters:
  • color (list(int)) – Color as display color 0-255 integer. Always srgb in 2022 and below.

  • noEmit (bool) – Emit the color?

colorLinearFloat()

returns the color of the color picker in linear color With 0-1.0 float ranges Eg (1.0, .5, .6666), the color is in Linear color, not SRGB

colorSrgbInt()

returns rgb tuple with 0-255 ranges Eg (128, 255, 12)

colorSrgbFloat()

returns rgb tuple with 0-1.0 float ranges Eg (1.0, .5, .6666)

data()

Returns the stored dictionary key (None by default) and a hex color. The key is usually a dictionary key that is passed in on creation of the instance, used in stylesheets This method is pretty specific to stylesheets and could be moved, method must be named data

Return self.key:

the dict key passed into the initialise function, stylesheet key “FRAMELESS_TITLELABEL_COLOR”

Rtype self.key:

str

Return hexColor:

the color as hex, 6 letters eg ffffff

Rtype hexColor:

str

setMenu(menu, modeList=None, mouseButton=MockExt.QtCore.Qt.RightButton)

Add the left/middle/right click menu by passing in a QMenu,

Note

Only works on the label currently.

If a modeList is passed in then create/reset the menu to the modeList:

[("icon1", "menuName1"), ("icon2", "menuName2")]

If no modelist the menu won’t change.

Parameters:
  • menu (QtWidgets.QMenu) – The Qt menu to show on middle click.

  • modeList (list(tuple(str))) – Menu modes. eg [(“icon1”, “menuName1”), (“icon2”, “menuName2”)]

  • mouseButton (QtCore.Qt.ButtonClick) – the mouse button clicked QtCore.Qt.LeftButton, QtCore.Qt.RightButton, QtCore.Qt.MiddleButton

addActionList(modes, mouseButton=MockExt.QtCore.Qt.RightButton)

resets the appropriate mouse click menu with the incoming modes

Note: only works on the label currently

modeList: [(“icon1”, “menuName1”), (“icon2”, “menuName2”), (“icon3”, “menuName3”)]

resets the lists and menus:

self.menuIconList: [“icon1”, “icon2”, “icon3”] self.menuIconList: [“menuName1”, “menuName2”, “menuName3”]

Parameters:
  • modes (list(tuple(str))) – a list of menu modes (tuples) eg [(“icon1”, “menuName1”), (“icon2”, “menuName2”)]

  • mouseButton (QtCore.Qt.ButtonClick) – the mouse button clicked QtCore.Qt.LeftButton, QtCore.Qt.RightButton, QtCore.Qt.MiddleButton

class MayaColorHsvBtns(*args: Any, **kwargs: Any)

Bases: MayaColorBtn

offsetClicked

alias of tuple

hsvShowHide(showHue=True, showSat=True, showValue=True)

Hide/show the hue saturation buttons

Parameters:
  • showHue (bool) – Show/hide the hues buttons

  • showSat (bool) – Show/hide the hues buttons

  • showValue (bool) – Show/hide the hues buttons

class MayaColorSlider(*args: Any, **kwargs: Any)

Bases: QWidget

colorChanged

alias of tuple

text()

returns the label name as a string

Return labelName:

the text name of the label

Rtype labelName:

str

setColorBtnWidth(width)

Sets the color button widget width, dpi scale handled, will scale with cmds as pyside has issues overriding.

Not Tested should work.

Parameters:

width (int) – pixel width of the color button.

setColorBtnHeight(height)

Sets the size of the color button widget, dpi scale handled

setDisabled(disabled=True)

Disables the color button, slider and label so it cannot be clicked

setEnabled(enabled=True)

Enables the color button, slider and label so it cannot be clicked

setDisabledLabelSlider(disabled=True)

Disables the color widget label and slider, the color picker and slider will work as per normal

setColorLinearFloat(color, noEmit=True)

Sets the color as rendering space color in 0-1.0 float ranges Eg (1.0, .5, .6666) emits the color as a Srgb Int color Eg (0, 255, 134)

Parameters:
  • color (tuple(float)) – color as rendering space Float (1.0, .5, .6666)

  • noEmit (bool) – Block the signals so no emit takes place

setColorSrgbFloat(color, noEmit=True)

Sets the color as srgb tuple with 0-1.0 float ranges Eg (1.0, .5, .6666) emits the color as a Srgb Int color Eg (0, 255, 134)

Parameters:
  • color (tuple(float)) – color as srgbFloat (1.0, .5, .6666)

  • noEmit (bool) – Block the signals so no emit takes place

setColorSrgbInt(color, noEmit=True)

Sets the color as srgb Int tuple with 0-255 int ranges Eg (0, 255, 134) emits the color as a Srgb Int color Eg (0, 255, 134)

Parameters:
  • color (tuple(int)) – color as srgbInt (0, 255, 134)

  • noEmit (bool) – Block the signals so no emit takes place

colorLinearFloat()

Returns the color of the color picker in linear color With 0-1.0 float ranges Eg (1.0, .5, .6666), the color is in Linear color, not srgb

Return colorLinearFloat:

color in linear float range, eg (1.0, .5, .6666)

Rtype colorLinearFloat:

tuple(float)

colorSrgbInt()

Returns rgb tuple with 0-255 ranges Eg (128, 255, 12)

Return colorSrgbInt:

color in srgb int range, eg (128, 255, 12)

Rtype colorSrgbInt:

tuple(int)

colorSrgbFloat()

Returns rgb tuple with 0-1.0 float ranges Eg (1.0, .5, .6666)

Return colorSrgbFloat:

color in srgb float range, eg (1.0, .5, .6666)

Rtype colorSrgbFloat:

tuple(float)

uiConnections()

Setup the emit signals