本文整理汇总了Python中pymel.versions.current函数的典型用法代码示例。如果您正苦于以下问题:Python current函数的具体用法?Python current怎么用?Python current使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了current函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_vectorArray
def test_vectorArray(self):
if versions.current() < versions.v2011:
cmds.setAttr( 'node.vectorArrayAttr', 2, (1,2,3), "", (1,2,3), type='vectorArray' )
assert cmds.getAttr( 'node.vectorArrayAttr' ) == [1.0, 2.0, 3.0, 1.0, 2.0, 3.0]
else:
cmds.setAttr( 'node.vectorArrayAttr', 2, (1,2,3), (1,2,3), type='vectorArray' )
assert cmds.getAttr( 'node.vectorArrayAttr' ) == [(1.0, 2.0, 3.0), (1.0, 2.0, 3.0)]
示例2: menu
def menu(*args, **kwargs):
"""
Modifications
- added ability to query parent
"""
if _versions.current() < _versions.v2011:
# on create only
if not ( kwargs.get('query', False) or kwargs.get('q', False) ) \
and not ( kwargs.get('edit', False) or kwargs.get('e', False) ) \
and not ( kwargs.get('parent', False) or kwargs.get('p', False) ):
kwargs['parent'] = cmds.setParent(q=1)
if ( kwargs.get('query', False) or kwargs.get('q', False) ) \
and ( kwargs.get('parent', False) or kwargs.get('p', False) ):
name = unicode(args[0])
if '|' not in name:
try:
name = _findLongName(name, 'menu')
except ValueError:
name = _findLongName(name, 'popupMenu')
return name.rsplit('|',1)[0]
result = cmds.menu(*args, **kwargs)
if ( kwargs.get('query', False) or kwargs.get('q', False) ) \
and ( kwargs.get('itemArray', False) or kwargs.get('ia', False) ) \
and result is None:
result = []
return result
示例3: parent
def parent(self):
buf = unicode(self).split('|')[:-1]
if len(buf)==2 and buf[0] == buf[1] and _versions.current() < _versions.v2011:
# pre-2011, windows with menus can have a strange name:
# ex. window1|window1|menu1
buf = buf[:1]
return PyUI( '|'.join(buf) )
示例4: mayaInit
def mayaInit(forversion=None) :
""" Try to init Maya standalone module, use when running pymel from an external Python inerpreter,
it is possible to pass the desired Maya version number to define which Maya to initialize
Part of the complexity of initializing maya in standalone mode is that maya does not populate os.environ when
parsing Maya.env. If we initialize normally, the env's are available via maya (via the shell), but not in python
via os.environ.
Note: the following example assumes that MAYA_SCRIPT_PATH is not set in your shell environment prior to launching
python or mayapy.
>>> import maya.standalone #doctest: +SKIP
>>> maya.standalone.initialize() #doctest: +SKIP
>>> import maya.mel as mm #doctest: +SKIP
>>> print mm.eval("getenv MAYA_SCRIPT_PATH") #doctest: +SKIP
/Network/Servers/sv-user.luma-pictures.com/luma .....
>>> import os #doctest: +SKIP
>>> 'MAYA_SCRIPT_PATH' in os.environ #doctest: +SKIP
False
The solution lies in `refreshEnviron`, which copies the environment from the shell to os.environ after maya.standalone
initializes.
:rtype: bool
:return: returns True if maya.cmds required initializing ( in other words, we are in a standalone python interpreter )
"""
setupFormatting()
global isInitializing
# test that Maya actually is loaded and that commands have been initialized,for the requested version
aboutExists = False
try :
from maya.cmds import about
aboutExists = True
except ImportError:
pass
if aboutExists and mayaStartupHasStarted():
# if this succeeded, we're initialized
isInitializing = False
return False
_logger.debug( "startup.initialize running" )
# for use with pymel compatible maya package
os.environ['MAYA_SKIP_USERSETUP_PY'] = 'on'
if not aboutExists and not sys.modules.has_key('maya.standalone'):
try :
import maya.standalone #@UnresolvedImport
maya.standalone.initialize(name="python")
if versions.current() < versions.v2009:
refreshEnviron()
except ImportError, e:
raise e, str(e) + ": pymel was unable to intialize maya.standalone"
示例5: _makeDgModGhostObject
def _makeDgModGhostObject(mayaType, dagMod, dgMod):
if versions.current() >= versions.v2012:
# only time post-2012 when we should have to call this func is when
# rebuilding caches - ie, running from inside ApiCache
if not GhostObjsOkHere.OK():
_logger.raiseLog(_logger.WARNING, '_makeDgModGhostObject should be unnecessary in maya versions past 2012 (except when rebuilding cache)')
# we create a dummy object of this type in a dgModifier (or dagModifier)
# as the dgModifier.doIt() method is never called, the object
# is never actually created in the scene
# Note: at one point, if we didn't call the dgMod/dagMod.deleteNode method,
# and we call this function while loading a scene (for instance, if the scene requires
# a plugin that isn't loaded, and defines custom node types), then the nodes were still
# somehow created, despite never explicitly calling doIt()...
# ... however, this seems to no longer be the case, and the deleteNode calls are apparently
# harmful
if type(dagMod) is not api.MDagModifier or type(dgMod) is not api.MDGModifier :
raise ValueError, "Need a valid MDagModifier and MDGModifier or cannot return a valid MObject"
# Regardless of whether we're making a DG or DAG node, make a parent first -
# for some reason, this ensures good cleanup (don't ask me why...??)
parent = dagMod.createNode ( 'transform', api.MObject())
try :
# DependNode
obj = dgMod.createNode ( mayaType )
except RuntimeError:
# DagNode
try:
obj = dagMod.createNode ( mayaType, parent )
except Exception, err:
_logger.debug("Error trying to create ghost node for '%s': %s" % (mayaType, err))
return None
示例6: exit_maya
def exit_maya():
import sys
# If we are in standalone we need to make a new file and uninitialize then the virtual machines crash
# if we do not use os._exit to properly exit Maya in CIRCLECI.
# https://groups.google.com/forum/#!topic/python_inside_maya/chpuSyLbryI
try:
import maya.standalone as ms
sys.stdout.write('Anvil is exiting Standalone Maya.')
mc.file(new=True, force=True)
sys.stdout.write('.')
sys.stdout.flush()
from pymel import versions
if not str(versions.current()).startswith('2016'):
ms.uninitialize()
sys.stdout.write('.')
sys.stdout.flush()
except:
pass
finally:
sys.stdout.write('Success...exiting.\n')
sys.stdout.flush()
import os
if os.getenv('CIRCLECI'):
os._exit(0)
示例7: assertMelError
def assertMelError(self, cmd):
# in maya 2014, a RuntimeError is raised... yay!
if versions.current() >= versions.v2014:
self.assertRaises(RuntimeError, mel.eval, cmd)
else:
# tried catch/catchQuiet, but they always return 0...
self.assertEqual(mel.eval(cmd), None)
示例8: objectTypeUI
def objectTypeUI(name, **kwargs):
try:
return cmds.objectTypeUI(name, **kwargs)
except RuntimeError, topError:
try:
# some ui types (radioCollections) can only be identified with their shortname
return cmds.objectTypeUI(name.split('|')[-1], **kwargs)
except RuntimeError:
# we cannot query the type of rowGroupLayout children: check common types for these
uiType = None
typesToCheck = 'checkBox floatField button floatSlider intSlider ' \
'floatField textField intField optionMenu radioButton'.split()
if _versions.current() >= _versions.v2012_SP2:
# 2012 SP2 introducted a bug where doing:
# win = cmds.window(menuBar=True)
# cmds.objectTypeUI(win)
# would error...
typesToCheck.append('window')
for cmdName in typesToCheck:
if getattr(cmds, cmdName)(name, ex=1, q=1):
uiType = cmdName
break
if uiType:
return uiType
raise topError
示例9: test_pointArray
def test_pointArray(self):
if versions.current() < versions.v2011:
# complex array
cmds.setAttr( 'node.pointArrayAttr', 2, (1,2,3,4), "", (1,2,3,4), type='pointArray' )
assert cmds.getAttr( 'node.pointArrayAttr' ) == [(1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0)]
else:
cmds.setAttr( 'node.pointArrayAttr', 2, (1,2,3,4), (1,2,3,4), type='pointArray' )
assert cmds.getAttr( 'node.pointArrayAttr' ) == [(1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0)]
示例10: reload_riggingShelf
def reload_riggingShelf():
version=str(versions.current())[:4]
result = '/software/tools/maya/2012/mel/riggingTools/4.24/rig/ui/shelf_rigging.mel'
if result:
shelf_name = result.split('/')[-1:][0].split('.')[0].split('_')[1]
if pm.shelfLayout(shelf_name,q=True,exists=True):
f=open(result,'r')
createMyShelf( shelf_name, f.read())
示例11: get_user_shelves_dir
def get_user_shelves_dir():
""" Returns the current user's shelves directory
Args:
None
Returns (str): string for the user's shelves directory based on the version of maya
"""
version=str(versions.current())[:4]
return os.path.join(os.path.expanduser('~'), '/maya/%s-x64/prefs/shelves/' % version)
示例12: _installCallbacks
def _installCallbacks():
"""install the callbacks that trigger new nodes and commands to be added to pymel when a
plugin loads. This is called from pymel.__init__
"""
global _pluginLoadedCB
if _pluginLoadedCB is None:
_pluginLoadedCB = True
_logger.debug("Adding pluginLoaded callback")
#_pluginLoadedCB = pluginLoadedCallback(module)
if _versions.current() >= _versions.v2009:
id = _api.MSceneMessage.addStringArrayCallback( _api.MSceneMessage.kAfterPluginLoad, _pluginLoaded )
if hasattr(id, 'disown'):
id.disown()
else:
# BUG: this line has to be a string, because using a function causes a 'pure virtual' error every time maya shuts down
cmds.loadPlugin( addCallback='import pymel.core; pymel.core._pluginLoaded("%s")' )
else:
_logger.debug("PluginLoaded callback already exists")
global _pluginUnloadedCB
if _pluginUnloadedCB is None:
_pluginUnloadedCB = True
# BUG: autodesk still has not add python callback support, and calling this as MEL is not getting the plugin name passed to it
#mel.unloadPlugin( addCallback='''python("import pymel; pymel._pluginUnloaded('#1')")''' )
if _versions.current() >= _versions.v2009:
_logger.debug("Adding pluginUnloaded callback")
id = _api.MSceneMessage.addStringArrayCallback( _api.MSceneMessage.kAfterPluginUnload, _pluginUnloaded )
if hasattr(id, 'disown'):
id.disown()
else:
_logger.debug("PluginUnloaded callback already exists")
# add commands and nodes for plugins loaded prior to importing pymel
preLoadedPlugins = cmds.pluginInfo( q=1, listPlugins=1 )
if preLoadedPlugins:
_logger.info("Updating pymel with pre-loaded plugins: %s" % ', '.join( preLoadedPlugins ))
for plugin in preLoadedPlugins:
_pluginLoaded( plugin )
示例13: read
def read(self, raw=False):
data = super(ApiCache, self).read()
if not raw:
# Before 2012, we cached reservedMayaTypes and reservedApiTypes,
# even though they weren't used...
if data is not None and len(data) != len(self._CACHE_NAMES):
if len(data) == 8 and versions.current() < versions.v2012:
data = data[2:6] + data[7:]
else:
# we need to rebuild, return None
data = None
return data
示例14: _getNodeHierarchy
def _getNodeHierarchy( version=None ):
"""
get node hierarchy as a list of 3-value tuples:
( nodeType, parents, children )
"""
import pymel.util.trees as trees
if versions.current() >= versions.v2012:
# We now have nodeType(isTypeName)! yay!
# For whatever reason, we can't query these objects from the hierarchy
# correctly using nodeType(isTypeName)
inheritances = {'file':[u'texture2d', u'file']}
for nodeType in cmds.allNodeTypes():
inheritance = cmds.nodeType(nodeType, inherited=True,
isTypeName=True)
if inheritance is None:
if nodeType in inheritances:
pass
else:
raise RuntimeError("Could not query the inheritance of node type %s" % nodeType)
else:
inheritances[nodeType] = inheritance
parentTree = {}
# Convert inheritance lists node=>parent dict
for nodeType, inheritance in inheritances.iteritems():
assert inheritance[-1] == nodeType
for i in xrange(len(inheritance)):
child = inheritance[i]
if i == 0:
if child == 'dependNode':
continue
else:
parent = 'dependNode'
else:
parent = inheritance[i - 1]
if child in parentTree:
assert parentTree[child] == parent
else:
parentTree[child] = parent
nodeHierarchyTree = trees.treeFromDict(parentTree)
else:
from parsers import NodeHierarchyDocParser
parser = NodeHierarchyDocParser(version)
nodeHierarchyTree = trees.IndexedTree(parser.parse())
return [ (x.value, tuple( [y.value for y in x.parents()]), tuple( [y.value for y in x.childs()] ) ) \
for x in nodeHierarchyTree.preorder() ]
示例15: shelf_reloader
def shelf_reloader(customShelf=None):
version=str(versions.current())[:4]
prefs=os.path.join(os.path.expanduser('~') + '/maya/%s-x64/prefs/shelves/' % version)
if customShelf:
shelf_name = customShelf.split('/')[-1:][0].split('.')[0].split('_')[1]
f=open(customShelf,'r')
createMyShelf( shelf_name, f.read())
else:
if os.path.exists(prefs):
result=pm.fileDialog2(ff='*.mel', ds=2, fm=4,dir=prefs)
if result:
shelf_name = result[0].split('/')[-1:][0].split('.')[0].split('_')[1]
print 'Replacing shelf %s from file:\n%s' % (shelf_name,result)
if pm.shelfLayout(shelf_name,q=True,exists=True):
f=open(result[0],'r')
createMyShelf( shelf_name, f.read())