Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Fix Maya 2022 Python 3 compatibility #2445

Merged
merged 18 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 34 additions & 23 deletions openpype/hosts/maya/api/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from functools import partial

import maya.cmds as mc
import maya.cmds as cmds
import maya.mel as mel

from avalon.maya import pipeline
Expand All @@ -31,9 +31,9 @@ def override_component_mask_commands():
log.info("Installing override_component_mask_commands..")

# Get all object mask buttons
buttons = mc.formLayout("objectMaskIcons",
query=True,
childArray=True)
buttons = cmds.formLayout("objectMaskIcons",
query=True,
childArray=True)
# Skip the triangle list item
buttons = [btn for btn in buttons if btn != "objPickMenuLayout"]

Expand All @@ -44,14 +44,14 @@ def on_changed_callback(raw_command, state):
# toggle the others based on whether any of the buttons
# was remaining active after the toggle, if not then
# enable all
if mc.getModifiers() == 4: # = CTRL
if cmds.getModifiers() == 4: # = CTRL
state = True
active = [mc.iconTextCheckBox(btn, query=True, value=True) for btn
in buttons]
active = [cmds.iconTextCheckBox(btn, query=True, value=True)
for btn in buttons]
if any(active):
mc.selectType(allObjects=False)
cmds.selectType(allObjects=False)
else:
mc.selectType(allObjects=True)
cmds.selectType(allObjects=True)

# Replace #1 with the current button state
cmd = raw_command.replace(" #1", " {}".format(int(state)))
Expand All @@ -64,32 +64,43 @@ def on_changed_callback(raw_command, state):
# try to implement the fix. (This also allows us to
# "uninstall" the behavior later)
if btn not in COMPONENT_MASK_ORIGINAL:
original = mc.iconTextCheckBox(btn, query=True, cc=True)
original = cmds.iconTextCheckBox(btn, query=True, cc=True)
COMPONENT_MASK_ORIGINAL[btn] = original

# Assign the special callback
original = COMPONENT_MASK_ORIGINAL[btn]
new_fn = partial(on_changed_callback, original)
mc.iconTextCheckBox(btn, edit=True, cc=new_fn)
cmds.iconTextCheckBox(btn, edit=True, cc=new_fn)


def override_toolbox_ui():
"""Add custom buttons in Toolbox as replacement for Maya web help icon."""
icons = resources.get_resource("icons")

# Ensure the maya web icon on toolbox exists
web_button = "ToolBox|MainToolboxLayout|mayaWebButton"
if not mc.iconTextButton(web_button, query=True, exists=True):
button_names = [
# Maya 2022.1+ with maya.cmds.iconTextStaticLabel
"ToolBox|MainToolboxLayout|mayaHomeToolboxButton",
# Older with maya.cmds.iconTextButton
"ToolBox|MainToolboxLayout|mayaWebButton"
]
for name in button_names:
if cmds.control(name, query=True, exists=True):
web_button = name
break
else:
# Button does not exist
log.warning("Can't find Maya Home/Web button to override toolbox ui..")
return

mc.iconTextButton(web_button, edit=True, visible=False)
cmds.control(web_button, edit=True, visible=False)

# real = 32, but 36 with padding - according to toolbox mel script
icon_size = 36
parent = web_button.rsplit("|", 1)[0]

# Ensure the parent is a formLayout
if not mc.objectTypeUI(parent) == "formLayout":
if not cmds.objectTypeUI(parent) == "formLayout":
return

# Create our controls
Expand All @@ -106,7 +117,7 @@ def override_toolbox_ui():

if look_assigner is not None:
controls.append(
mc.iconTextButton(
cmds.iconTextButton(
"pype_toolbox_lookmanager",
annotation="Look Manager",
label="Look Manager",
Expand All @@ -120,7 +131,7 @@ def override_toolbox_ui():
)

controls.append(
mc.iconTextButton(
cmds.iconTextButton(
"pype_toolbox_workfiles",
annotation="Work Files",
label="Work Files",
Expand All @@ -136,7 +147,7 @@ def override_toolbox_ui():
)

controls.append(
mc.iconTextButton(
cmds.iconTextButton(
"pype_toolbox_loader",
annotation="Loader",
label="Loader",
Expand All @@ -152,7 +163,7 @@ def override_toolbox_ui():
)

controls.append(
mc.iconTextButton(
cmds.iconTextButton(
"pype_toolbox_manager",
annotation="Inventory",
label="Inventory",
Expand All @@ -173,7 +184,7 @@ def override_toolbox_ui():
for i, control in enumerate(controls):
previous = controls[i - 1] if i > 0 else web_button

mc.formLayout(parent, edit=True,
attachControl=[control, "bottom", 0, previous],
attachForm=([control, "left", 1],
[control, "right", 1]))
cmds.formLayout(parent, edit=True,
attachControl=[control, "bottom", 0, previous],
attachForm=([control, "left", 1],
[control, "right", 1]))
5 changes: 3 additions & 2 deletions openpype/hosts/maya/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import json
import logging
import itertools
import contextlib
from collections import OrderedDict, defaultdict
from math import ceil
Expand Down Expand Up @@ -129,8 +128,10 @@ def float_round(num, places=0, direction=ceil):

def pairwise(iterable):
"""s -> (s0,s1), (s2,s3), (s4, s5), ..."""
from six.moves import zip

a = iter(iterable)
return itertools.izip(a, a)
return zip(a, a)


def unique(name):
Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/maya/plugins/create/create_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _create_render_settings(self):
# get pools
pool_names = []

self.server_aliases = self.deadline_servers.keys()
self.server_aliases = list(self.deadline_servers.keys())
self.data["deadlineServers"] = self.server_aliases
self.data["suspendPublishJob"] = False
self.data["review"] = True
Expand Down
2 changes: 1 addition & 1 deletion openpype/hosts/maya/plugins/publish/collect_look.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def collect(self, instance):

# Collect file nodes used by shading engines (if we have any)
files = []
look_sets = sets.keys()
look_sets = list(sets.keys())
shader_attrs = [
"surfaceShader",
"volumeShader",
Expand Down
5 changes: 3 additions & 2 deletions openpype/hosts/maya/plugins/publish/collect_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,14 @@ def process(self, context):
publish_meta_path = None
for aov in exp_files:
full_paths = []
for file in aov[aov.keys()[0]]:
aov_first_key = list(aov.keys())[0]
for file in aov[aov_first_key]:
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
full_path = os.path.join(workspace, default_render_file,
file)
full_path = full_path.replace("\\", "/")
full_paths.append(full_path)
publish_meta_path = os.path.dirname(full_path)
aov_dict[aov.keys()[0]] = full_paths
aov_dict[aov_first_key] = full_paths

frame_start_render = int(self.get_render_attribute(
"startFrame", layer=layer_name))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def grouper(iterable, n, fillvalue=None):

"""
args = [iter(iterable)] * n
return itertools.izip_longest(fillvalue=fillvalue, *args)
from six.moves import zip_longest
return zip_longest(fillvalue=fillvalue, *args)


def unlock(plug):
Expand Down
8 changes: 7 additions & 1 deletion openpype/hosts/maya/plugins/publish/extract_look.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import json
import tempfile
import platform
import contextlib
import subprocess
from collections import OrderedDict
Expand Down Expand Up @@ -58,6 +59,11 @@ def maketx(source, destination, *args):
from openpype.lib import get_oiio_tools_path

maketx_path = get_oiio_tools_path("maketx")

if platform.system().lower() == "windows":
# Ensure .exe extension
maketx_path += ".exe"

BigRoy marked this conversation as resolved.
Show resolved Hide resolved
if not os.path.exists(maketx_path):
print(
"OIIO tool not found in {}".format(maketx_path))
Expand Down Expand Up @@ -212,7 +218,7 @@ def process(self, instance):
self.log.info("Extract sets (%s) ..." % _scene_type)
lookdata = instance.data["lookData"]
relationships = lookdata["relationships"]
sets = relationships.keys()
sets = list(relationships.keys())
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
if not sets:
self.log.info("No sets found")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def maya_is_true(self, attr_val):
Maya API will return a list of values, which need to be properly
handled to evaluate properly.
"""
if isinstance(attr_val, types.BooleanType):
if isinstance(attr_val, bool):
return attr_val
elif isinstance(attr_val, (types.ListType, types.GeneratorType)):
elif isinstance(attr_val, (list, types.GeneratorType)):
return any(attr_val)
else:
return bool(attr_val)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import maya.api.OpenMaya as om
import pymel.core as pm

from six.moves import xrange


class GetOverlappingUVs(object):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def maya_is_true(attr_val):
bool: cast Maya attribute to Pythons boolean value.

"""
if isinstance(attr_val, types.BooleanType):
if isinstance(attr_val, bool):
return attr_val
elif isinstance(attr_val, (types.ListType, types.GeneratorType)):
elif isinstance(attr_val, (list, types.GeneratorType)):
return any(attr_val)
else:
return bool(attr_val)
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}
},
"__dynamic_keys_labels__": {
"2022": "2022 (Testing Only)"
"2022": "2022"
}
}
},
Expand Down