def load(self, name): """ Loads the specified attribute set Args: name (str): Name of the attribute set to import """ attrs = self[name]['attributes'] # check if substrate is available substrateAttr = "{0}.substrateTexture".format(mnpr_info.configNode) p = lib.Path(lib.getLibDir()).parent().child("textures") textures = os.listdir(p.path) if attrs[substrateAttr] not in textures: # check if substrates have been installed if len(textures) <= 2: result = cmds.confirmDialog(t="Substrates (papers/canvas) not found", m="The required substrate is not available.\nWould you like to download the MNPR substrates?", b=['Yes', 'Load anyway', 'Close'], icn="warning") if result == "Close": return elif result == "Yes": mnpr_runner.downloadSubstrates() return else: cmds.warning("Substrate texture not found, reverting to default substrate (style might not display correctly)") attrs[substrateAttr] = "rough_default_2k.jpg" else: cmds.warning("Substrate texture not found, reverting to default substrate (style might not display correctly)") attrs[substrateAttr] = "rough_default_2k.jpg" # check change of style first styleAttr = "{0}.style".format(mnpr_info.configNode) if styleAttr in attrs: style = attrs[styleAttr] if style != cmds.mnpr(style=True): lib.setAttr(mnpr_info.configNode, "style", style) func = functools.partial(self.loadStyle, attrs) return cmds.scriptJob(runOnce=True, event=["SelectionChanged", func]) else: # set attributes for attr in attrs: splitter = attr.split('.') lib.setAttr(splitter[0], splitter[1], attrs[attr]) else: # for legacy presets (we do not worry about styles here) for attr in attrs: splitter = attr.split('.') if "NPRConfig" in splitter[0]: splitter[0] = "mnprConfig" lib.setAttr(splitter[0], splitter[1], attrs[attr]) lib.printInfo("Attributes set successfully")
def getSubstrates(): """ Downloads and extracts the substrate textures """ url = "https://researchdata.ntu.edu.sg/api/access/datafile/2793?gbrecs=true" if lib.localOS() == "mac": result = cmds.confirmDialog(t="Download substrates", m="Please download the substrates and extract them into the textures folder of MNPR.", b="Download", icn="information") if result == "Download": lib.openUrl("https://doi.org/10.21979/N9/HI7GT7") lib.openUrl(url) return else: print "No substrates will be downloaded.", return # windows and linux import zipfile result = cmds.confirmDialog(t="Downloading substrates", m="Do you wish to download the substrates \nautomatically in the background?", b=['Yes', 'Manual download', 'Close'], icn="question") if result == "Manual download": lib.openUrl("https://doi.org/10.21979/N9/HI7GT7") lib.openUrl(url) return elif result == "Close": print "No substrates will be downloaded.", return else: p = lib.Path(lib.getLibDir()) p.parent().child("textures") dest = os.path.join(p.path, "seamless_textures_light.zip") if lib.downloader(url, dest): print "Substrates downloaded, extracting..." zip = zipfile.ZipFile(dest, 'r') zip.extractall(p.path) zip.close() os.remove(dest) print "MNPR substrates installed successfully", cmds.confirmDialog(t="Download successful", m="The substrates downloaded successfully", b="Yay!", icn="information") else: cmds.warning("Problem downloading substrates, please download and install manually") result = cmds.confirmDialog(t="Download substrates", m="Please download the substrates and extract them into the textures folder of MNPR.", b="Download", icn="information") if result == "Download": lib.openUrl("https://doi.org/10.21979/N9/HI7GT7") lib.openUrl(url)
import os, json, logging, pprint, operator, traceback, functools from PySide2 import QtWidgets, QtCore, QtGui import maya.cmds as cmds import coopLib as lib import coopQt as qt import mnpr_system import mnpr_runner import mnpr_info # LOGGING logging.basicConfig() # errors and everything else (2 separate log groups) logger = logging.getLogger("mnpr_presets") # create a logger for this file logger.setLevel(logging.DEBUG) # defines the logging level (INFO for releases) # logger.setLevel(logging.INFO) # defines the logging level (DEBUG for debugging) PATH = lib.Path(lib.getLibDir()).parent() # _ _ _ _ _ # ___| |_ _ _| | ___ | (_) |__ # / __| __| | | | |/ _ \ | | | '_ \ # \__ \ |_| |_| | | __/ | | | |_) | # |___/\__|\__, |_|\___| |_|_|_.__/ # |___/ class AttributeSetsLibrary(dict): """ Attribute sets library """ type = "attrSets" objects = [] def save(self, name, screenshot=True, **info): """