def mayaDocsLocation(version=None): docLocation = os.environ.get('MAYA_DOC_DIR') if (not docLocation and (version is None or version == versions.installName() ) and mayaIsRunning()): # Return the doc location for the running version of maya from maya.cmds import showHelp docLocation = showHelp("", q=True, docs=True) # Older implementations had no trailing slash, but the result returned by # showHelp has a trailing slash... so eliminate any trailing slashes for # consistency while docLocation != "" and os.path.basename(docLocation) == "": docLocation = os.path.dirname(docLocation) # Want the docs for a different version, or maya isn't initialized yet if not docLocation or not os.path.isdir(docLocation): docBaseDir = os.environ.get('MAYA_DOC_BASE_DIR') if not docBaseDir: docBaseDir = getMayaLocation(version) # use original version if docBaseDir is None and version is not None: docBaseDir = getMayaLocation(None) _logger.warning("Could not find an installed Maya for exact version %s, using first installed Maya location found in %s" % (version, docBaseDir) ) if platform.system() == 'Darwin': docBaseDir = os.path.dirname(os.path.dirname(docBaseDir)) docBaseDir = os.path.join(docBaseDir, 'docs') if version: short_version = versions.parseVersionStr(version, extension=False) else: short_version = versions.shortName() docLocation = os.path.join(docBaseDir , 'Maya%s' % short_version, 'en_US') return os.path.realpath(docLocation)
def mayaDocsLocation(version=None): docLocation = None if (version == None or version == versions.installName() ) and mayaIsRunning(): # Return the doc location for the running version of maya from maya.cmds import showHelp docLocation = showHelp("", q=True, docs=True) # Older implementations had no trailing slash, but the result returned by # showHelp has a trailing slash... so eliminate any trailing slashes for # consistency while docLocation != "" and os.path.basename(docLocation) == "": docLocation = os.path.dirname(docLocation) # Want the docs for a different version, or maya isn't initialized yet if not docLocation or not os.path.isdir(docLocation): docLocation = getMayaLocation(version) # use original version if docLocation is None and version is not None: docLocation = getMayaLocation(None) _logger.warning("Could not find an installed Maya for exact version %s, using first installed Maya location found in %s" % (version, docLocation) ) if version: short_version = versions.parseVersionStr(version, extension=False) else: short_version = versions.shortName() if platform.system() == 'Darwin': docLocation = os.path.dirname(os.path.dirname(docLocation)) docLocation = os.path.join(docLocation , 'docs/Maya%s/en_US' % short_version) return os.path.realpath(docLocation)
def maya_version_check(cls, *args, **kwargs): ''' check the maya version code ''' minVersion = 2014 if int(versions.shortName()) < minVersion: return False return True
def path(self, ext=None): if ext is None: ext = self.DEFAULT_EXT if self.USE_VERSION: if hasattr(self, 'version'): short_version = str(self.version) else: short_version = shortName() else: short_version = '' newPath = _moduleJoin('cache', self.NAME + short_version) return newPath + ext
def _overridePythonScripts(): root = mtoaPackageRoot() maya_version = versions.shortName() path = os.path.join(root, maya_version) if not os.path.isdir(path): return sys.path.insert(0, path) # for root, dirnames, filenames in os.walk('path'): for f in os.listdir(path): if f.endswith('.py'): print>>sys.__stdout__, "Maya %s importing * from Python override %s from %s" % (maya_version, f, path) print "Maya %s importing * from Python override %s from %s" % (maya_version, f, path) import_string = "from %s import *" % os.path.splitext(f)[0] exec import_string
def getMayaLocation(version=None): # type: (bool) -> Optional[str] """ Get the path to the Maya install directory. .. note:: The Maya location is defined as the directory above /bin. Uses the ``MAYA_LOCATION`` environment variable and ``sys.executable`` path. Returns None if not found. Parameters ---------- version : bool if passed, will attempt to find a matching Maya location. If the version found above does not match the requested version, this function uses a simple find/replace heuristic to modify the path and test if the desired version exists. Returns ------- Optional[str] """ try: loc = os.path.realpath(os.environ['MAYA_LOCATION']) except: loc = os.path.dirname(os.path.dirname(sys.executable)) # get the path of a different maya version than current if version: # note that a recursive loop between getMayaLocation / getMayaVersion # is avoided because getMayaVersion always calls getMayaLocation with # version == None actual_long_version = versions.installName() actual_short_version = versions.shortName() if version != actual_long_version: short_version = versions.parseVersionStr(version, extension=False) if version == short_version: try_version = actual_long_version.replace(actual_short_version, short_version) else: try_version = version try_loc = loc.replace(actual_long_version, try_version) if os.path.exists(try_loc): loc = try_loc else: _logger.warn("No Maya found for version %s" % version) loc = None return loc
def path(self): if self.USE_VERSION: if hasattr(self, 'version'): short_version = str(self.version) else: short_version = shortName() else: short_version = '' newPath = _moduleJoin( 'cache', self.NAME+short_version ) if self.COMPRESSED: newPath += '.zip' else: newPath += '.bin' return newPath
def path(self): if self.USE_VERSION: if hasattr(self, 'version'): short_version = str(self.version) else: short_version = shortName() else: short_version = '' newPath = _moduleJoin('cache', self.NAME + short_version) if self.COMPRESSED: newPath += '.zip' else: newPath += '.bin' return newPath
def _overridePythonScripts(): root = mtoaPackageRoot() maya_version = versions.shortName() path = os.path.join(root, maya_version) if not os.path.isdir(path): return sys.path.insert(0, path) # for root, dirnames, filenames in os.walk('path'): for f in os.listdir(path): if f.endswith('.py'): print >> sys.__stdout__, "Maya %s importing * from Python override %s from %s" % ( maya_version, f, path) print "Maya %s importing * from Python override %s from %s" % ( maya_version, f, path) import_string = "from %s import *" % os.path.splitext(f)[0] exec import_string
def _overrideMelScripts(): # for those procedures that we could not simply define overrides interactively, we keep edited files # per version of maya root = mtoaPackageRoot() maya_version = versions.shortName() meldir = os.path.join(root, maya_version, 'mel') meldir = mtoa.utils.convertToUnicode(meldir) pathsep = mtoa.utils.convertToUnicode(os.pathsep) maya_script_path = mtoa.utils.convertToUnicode(mtoa.utils.getEnvironmentVariable(u'MAYA_SCRIPT_PATH')) mtoa.utils.setEnvironmentVariable(u'MAYA_SCRIPT_PATH', meldir + pathsep + maya_script_path) for f in glob.glob(os.path.join(meldir, '*.mel')): print>>sys.__stdout__, "Maya %s sourcing MEL override %s" % (maya_version, f) print "Maya %s sourcing MEL override %s" % (maya_version, f) pm.mel.source(pm.mel.encodeString(f)) test = pm.mel.whatIs(os.path.split(f)[1]).split(': ', 1) if len(test) == 2 and test[1].replace('\\', '/') != f.replace('\\', '/'): pm.warning("Overriding failed: Maya is still using %s" % test[1])
def getMayaLocation(version=None): """ Get the path to the Maya install directory. .. note:: The Maya location is defined as the directory above /bin. Uses the ``MAYA_LOCATION`` environment variable and ``sys.executable`` path. Parameters ---------- version : bool if passed, will attempt to find a matching Maya location. If the version found above does not match the requested version, this function uses a simple find/replace heuristic to modify the path and test if the desired version exists. Returns ------- str or None The path to Maya's installation directory or None, if not found """ try: loc = os.path.realpath(os.environ['MAYA_LOCATION']) except: loc = os.path.dirname(os.path.dirname(sys.executable)) # get the path of a different maya version than current if version: # note that a recursive loop between getMayaLocation / getMayaVersion # is avoided because getMayaVersion always calls getMayaLocation with # version == None actual_long_version = versions.installName() actual_short_version = versions.shortName() if version != actual_long_version: short_version = versions.parseVersionStr(version, extension=False) if version == short_version: try_version = actual_long_version.replace(actual_short_version, short_version) else: try_version = version try_loc = loc.replace(actual_long_version, try_version) if os.path.exists(try_loc): loc = try_loc else: _logger.warn("No Maya found for version %s" % version) loc = None return loc
def _overrideMelScripts(): # for those procedures that we could not simply define overrides interactively, we keep edited files # per version of maya root = mtoaPackageRoot() maya_version = versions.shortName() meldir = os.path.join(root, maya_version, 'mel') meldir = mtoa.utils.convertToUnicode(meldir) pathsep = mtoa.utils.convertToUnicode(os.pathsep) maya_script_path = mtoa.utils.convertToUnicode( mtoa.utils.getEnvironmentVariable(u'MAYA_SCRIPT_PATH')) mtoa.utils.setEnvironmentVariable(u'MAYA_SCRIPT_PATH', meldir + pathsep + maya_script_path) for f in glob.glob(os.path.join(meldir, '*.mel')): print >> sys.__stdout__, "Maya %s sourcing MEL override %s" % ( maya_version, f) print "Maya %s sourcing MEL override %s" % (maya_version, f) pm.mel.source(pm.mel.encodeString(f)) test = pm.mel.whatIs(os.path.split(f)[1]).split(': ', 1) if len(test) == 2 and test[1].replace('\\', '/') != f.replace( '\\', '/'): pm.warning("Overriding failed: Maya is still using %s" % test[1])
def loadCache( filePrefix, description='', useVersion=True, compressed=True): if useVersion: short_version = shortName() else: short_version = '' newPath = _moduleJoin( 'cache', filePrefix+short_version ) if compressed: newPath += '.zip' func = picklezip.load else: newPath += '.bin' func = _load if description: description = ' ' + description #_logger.info("Loading%s from '%s'" % ( description, newPath )) try: return func(newPath) except Exception, e: _logger.error("Unable to load%s from '%s': %s" % (description, newPath, e))
def writeCache( data, filePrefix, description='', useVersion=True, compressed=True): if useVersion: short_version = shortName() else: short_version = '' newPath = _moduleJoin( 'cache', filePrefix+short_version ) if compressed: newPath += '.zip' func = picklezip.dump else: newPath += '.bin' func = _dump if description: description = ' ' + description _logger.info("Saving%s to '%s'" % ( description, newPath )) try : func( data, newPath, 2) except Exception, e: _logger.error("Unable to write%s to '%s': %s" % (description, newPath, e))
import sys import inspect import mtoa.utils import arnoldShelf def mtoaPackageRoot(): '''return the path to the mtoa python package directory''' return os.path.dirname( os.path.dirname(inspect.getfile(inspect.currentframe()))) if 'pymel' not in globals(): import pymel import pymel.versions as versions maya_version = versions.shortName() print "Maya %s importing module pymel %s (%s)" % ( maya_version, pymel.__version__, pymel.__file__) else: print "Maya %s had already imported module pymel %s (%s)" % ( maya_version, pymel.__version__, pymel.__file__) import pymel.core as pm try: import mtoa.utils as utils import mtoa.ui.exportass as exportass import mtoa.ui.nodeTreeLister as nodeTreeLister import mtoa.ui.globals.common from mtoa.ui.globals.common import createArnoldRendererCommonGlobalsTab, updateArnoldRendererCommonGlobalsTab from mtoa.ui.globals.settings import createArnoldRendererGlobalsTab, updateArnoldRendererGlobalsTab, updateBackgroundSettings, updateAtmosphereSettings, createArnoldRendererOverrideTab, updateArnoldRendererOverrideTab
def lcTb_open_tool(windowName, heightAdjust, commandString='', *args, **kwargs): ''' ''' prefix = conf['prefix'] if lcUtility.Utility.maya_version_check(): if pm.columnLayout(prefix + '_columLayout_holder', exists=True): pm.deleteUI(prefix + '_columLayout_holder') if pm.formLayout('fl_form', exists=True): pm.deleteUI('fl_form') if pm.columnLayout('fl_form_shelf', exists=True): pm.deleteUI('fl_form_shelf') if pm.columnLayout('fl_form_tool', exists=True): pm.deleteUI('fl_form_tool') pm.setParent(prefix + '_columnLayout_main') pm.columnLayout(prefix + '_columLayout_holder', rowSpacing=0) pm.formLayout('fl_form', numberOfDivisions=100) pm.picture('fl_form_header', image=os.path.join( iconPath, 'header_{}.png'.format(lct_conf['release']))) if lct_conf['release'] == 'dev': pm.symbolButton('fl_form_reload', image=os.path.join(iconPath, 'reload.png'), command=functools.partial( lcTb_open_tool_new_window, shelfCommand)) pm.columnLayout('fl_form_shelf') shelfHeight = 32 fl_flow_layout = pm.flowLayout(width=204, height=shelfHeight + 4, wrap=True, columnSpacing=0) # list published tools except lcToolbox toolList = lcUtility.Utility.buildPublishList(inline=False) toolCount = 0 for item in toolList: if item[0] != 'lcToolbox': toolCount = toolCount + 1 toolName = item[0] toolPrefix = item[1] toolAnnotation = item[2] toolHeight = int(item[5]) toolIcon = os.path.normpath( os.path.join(srcPath, toolName, toolName + '.png')) shelfIcon = os.path.normpath( os.path.join(srcPath, toolName, 'icons', toolName + '_shelf.png')) toolShelfCommand = "import lct.src.{0}.{0} as {1}\nreload({1})\n{1}.{0}UI()".format( toolName, toolPrefix) toolExecString = unicode( "import lct.src.{0}.{0} as {1}\nreload({1})\n{1}.{0}UI(asChildLayout=True)" .format(toolName, toolPrefix)) toolButton = pm.symbolButton(prefix + '_' + toolName, image=toolIcon, annotation=toolAnnotation, command=functools.partial( lcTb_open_tool, windowName, toolHeight, toolExecString)) popup = pm.popupMenu(prefix + '_' + toolName + 'popup', parent=toolButton) pm.menuItem(l='Open in new window', parent=popup, command=functools.partial( lcTb_open_tool_new_window, toolShelfCommand)) pm.menuItem(l='Add to shelf', parent=popup, command=functools.partial( lcShelf.Shelf.makeShelfButton, toolName, toolShelfCommand, shelfIcon, toolAnnotation)) if pm.window( toolName, ex=True ): # if i have the tool window open seperately use the return arrow icon pm.symbolButton( prefix + '_' + toolName, edit=True, image=os.path.normpath( os.path.join(srcPath, toolName, 'icons', toolName + '_Return.png')), command=functools.partial(lcTb_open_tool, windowName, toolHeight, toolExecString)) # if i am loading a specific tool back into the window update its icon to standard if commandString and toolName in commandString: pm.symbolButton( toolButton, edit=True, image=os.path.normpath( os.path.join(srcPath, toolName, 'icons', toolName + '_Release.png')), command=functools.partial(lcTb_open_tool_new_window, toolShelfCommand)) rowCount = max(1, math.ceil(toolCount / 5.0)) shelfHeight = shelfHeight * rowCount + 4 pm.flowLayout(fl_flow_layout, edit=True, height=shelfHeight) pm.setParent('fl_form') fl_form_tool = pm.columnLayout('fl_form_tool', width=224, columnOffset=('left', 10)) pm.separator(style='double', h=5, w=205) if not commandString: pm.picture(image=os.path.join(iconPath, 'none.png')) else: exec commandString in locals() lct_cfg.set('lcToolboxCurrentTool', commandString) lct_cfg.set('lcToolboxHeight', heightAdjust) if lct_conf['release'] == 'dev': pm.formLayout('fl_form', edit=True, attachForm=[('fl_form_header', 'top', 0), ('fl_form_shelf', 'top', 54), ('fl_form_shelf', 'left', 25), ('fl_form_reload', 'top', 0), ('fl_form_reload', 'left', 103)], attachControl=[(fl_form_tool, 'top', 0, 'fl_form_shelf')]) else: pm.formLayout('fl_form', edit=True, attachForm=[('fl_form_header', 'top', 0), ('fl_form_shelf', 'top', 54), ('fl_form_shelf', 'left', 25)], attachControl=[(fl_form_tool, 'top', 0, 'fl_form_shelf')]) pm.setParent(prefix + '_columLayout_holder') pm.picture('fl_form_footer', image=os.path.join( iconPath, 'footer_{}.png'.format(lct_conf['release']))) pm.window(windowName, edit=True, height=heightAdjust + shelfHeight + 122) # +conf['height'])#, width=mainWindow.width) else: pm.separator(style='none', h=30) pm.text(l='Your Maya Version:', al='center', w=231, h=25, font='boldLabelFont') pm.text(l='{}'.format(versions.shortName()), al='center', w=231, h=10, font='boldLabelFont') pm.separator(style='none', h=10) pm.text( l='You must have\nMaya 2014 or greater\nto run the\nLEOCOV Toolbox', al='center', w=231, h=60, font='boldLabelFont') pm.window(windowName, edit=True, height=231)
def createArnoldTextureSettings(): """The patched version of the original file """ import pymel.core as pm import maya.cmds as cmds import pymel.versions as versions from mtoa.ui.globals import settings pm.setUITemplate('attributeEditorTemplate', pushTemplate=True) pm.columnLayout(adjustableColumn=True) pm.attrControlGrp('autotx', cc=settings.updateAutoTxSettings, label="Auto-convert Textures to TX (Disabled in Anima)", attribute='defaultArnoldRenderOptions.autotx', enable=False) pm.attrControlGrp( 'use_existing_tiled_textures', label="Use Existing TX Textures", attribute='defaultArnoldRenderOptions.use_existing_tiled_textures') # disable autotx pm.setAttr('defaultArnoldRenderOptions.autotx', 0) settings.updateAutoTxSettings() cmds.separator() # don't create texture_automip for 2017 as autoTx is ON by default maya_version = versions.shortName() if int(float(maya_version)) < 2017: pm.attrControlGrp( 'texture_automip', label="Auto-mipmap", attribute='defaultArnoldRenderOptions.textureAutomip') pm.attrControlGrp( 'texture_accept_unmipped', label="Accept Unmipped", attribute='defaultArnoldRenderOptions.textureAcceptUnmipped') cmds.separator() pm.checkBoxGrp('ts_autotile', cc=settings.updateAutotileSettings, label='', label1='Auto-tile') pm.connectControl('ts_autotile', 'defaultArnoldRenderOptions.autotile', index=2) pm.intSliderGrp('ts_texture_autotile', label="Tile Size", minValue=16, maxValue=64, fieldMinValue=16, fieldMaxValue=1024) pm.connectControl('ts_texture_autotile', 'defaultArnoldRenderOptions.textureAutotile', index=1) pm.connectControl('ts_texture_autotile', 'defaultArnoldRenderOptions.textureAutotile', index=2) pm.connectControl('ts_texture_autotile', 'defaultArnoldRenderOptions.textureAutotile', index=3) '''pm.attrControlGrp('texture_autotile', label="Auto-tile Size", attribute='defaultArnoldRenderOptions.textureAutotile')''' pm.attrControlGrp( 'texture_accept_untiled', label="Accept Untiled", attribute='defaultArnoldRenderOptions.textureAcceptUntiled') pm.attrControlGrp( 'texture_max_memory_MB', label="Max Cache Size (MB)", attribute='defaultArnoldRenderOptions.textureMaxMemoryMB') pm.attrControlGrp( 'texture_max_open_files', label="Max Open Files", attribute='defaultArnoldRenderOptions.textureMaxOpenFiles') cmds.separator() cmds.attrControlGrp( 'texture_diffuse_blur', label="Diffuse Blur", attribute='defaultArnoldRenderOptions.textureDiffuseBlur') # cmds.attrControlGrp('texture_glossy_blur', # label="Glossy Blur", # attribute='defaultArnoldRenderOptions.textureGlossyBlur') pm.setParent('..') pm.setUITemplate(popTemplate=True)
def createArnoldTextureSettings(): """The patched version of the original file """ import pymel.core as pm import maya.cmds as cmds import pymel.versions as versions from mtoa.ui.globals import settings pm.setUITemplate('attributeEditorTemplate', pushTemplate=True) pm.columnLayout(adjustableColumn=True) pm.attrControlGrp( 'autotx', cc=settings.updateAutoTxSettings, label="Auto-convert Textures to TX (Disabled in Anima)", attribute='defaultArnoldRenderOptions.autotx', enable=False ) pm.attrControlGrp('use_existing_tiled_textures', label="Use Existing TX Textures", attribute='defaultArnoldRenderOptions.use_existing_tiled_textures') # disable autotx pm.setAttr('defaultArnoldRenderOptions.autotx', 0) settings.updateAutoTxSettings() cmds.separator() # don't create texture_automip for 2017 as autoTx is ON by default maya_version = versions.shortName() if int(float(maya_version)) < 2017: pm.attrControlGrp('texture_automip', label="Auto-mipmap", attribute='defaultArnoldRenderOptions.textureAutomip') pm.attrControlGrp('texture_accept_unmipped', label="Accept Unmipped", attribute='defaultArnoldRenderOptions.textureAcceptUnmipped') cmds.separator() pm.checkBoxGrp('ts_autotile', cc=settings.updateAutotileSettings, label='', label1='Auto-tile') pm.connectControl('ts_autotile', 'defaultArnoldRenderOptions.autotile', index=2) pm.intSliderGrp('ts_texture_autotile', label="Tile Size", minValue=16, maxValue=64, fieldMinValue=16, fieldMaxValue=1024 ) pm.connectControl('ts_texture_autotile', 'defaultArnoldRenderOptions.textureAutotile', index=1) pm.connectControl('ts_texture_autotile', 'defaultArnoldRenderOptions.textureAutotile', index=2) pm.connectControl('ts_texture_autotile', 'defaultArnoldRenderOptions.textureAutotile', index=3) '''pm.attrControlGrp('texture_autotile', label="Auto-tile Size", attribute='defaultArnoldRenderOptions.textureAutotile')''' pm.attrControlGrp('texture_accept_untiled', label="Accept Untiled", attribute='defaultArnoldRenderOptions.textureAcceptUntiled') pm.attrControlGrp('texture_max_memory_MB', label="Max Cache Size (MB)", attribute='defaultArnoldRenderOptions.textureMaxMemoryMB') pm.attrControlGrp('texture_max_open_files', label="Max Open Files", attribute='defaultArnoldRenderOptions.textureMaxOpenFiles') cmds.separator() cmds.attrControlGrp('texture_diffuse_blur', label="Diffuse Blur", attribute='defaultArnoldRenderOptions.textureDiffuseBlur') # cmds.attrControlGrp('texture_glossy_blur', # label="Glossy Blur", # attribute='defaultArnoldRenderOptions.textureGlossyBlur') pm.setParent('..') pm.setUITemplate(popTemplate=True)
import glob import os import sys import inspect import mtoa.utils import arnoldShelf def mtoaPackageRoot(): '''return the path to the mtoa python package directory''' return os.path.dirname(os.path.dirname(inspect.getfile(inspect.currentframe()))) if 'pymel' not in globals(): import pymel import pymel.versions as versions maya_version = versions.shortName() print "Maya %s importing module pymel %s (%s)" % (maya_version, pymel.__version__, pymel.__file__) else : print "Maya %s had already imported module pymel %s (%s)" % (maya_version, pymel.__version__, pymel.__file__) import pymel.core as pm try: import mtoa.utils as utils import mtoa.ui.exportass as exportass import mtoa.ui.nodeTreeLister as nodeTreeLister import mtoa.ui.globals.common from mtoa.ui.globals.common import createArnoldRendererCommonGlobalsTab, updateArnoldRendererCommonGlobalsTab from mtoa.ui.globals.settings import createArnoldRendererGlobalsTab, updateArnoldRendererGlobalsTab, updateBackgroundSettings, updateAtmosphereSettings, createArnoldRendererOverrideTab, updateArnoldRendererOverrideTab from mtoa.ui.globals.settings import createArnoldRendererDiagnosticsTab, updateArnoldRendererDiagnosticsTab, createArnoldRendererSystemTab, updateArnoldRendererSystemTab from mtoa.ui.aoveditor import createArnoldAOVTab, updateArnoldAOVTab import mtoa.ui.ae.utils as aeUtils