예제 #1
0
def customEvaluatorReadyStateChange(evaluatorName, newValue):
    """
	Callback when a checkbox is ticked to alter the ready state of a custom
	evaluator.
	"""
    print 'Changing evaluator %s ready state to %d' % (evaluatorName, newValue)
    cmds.evaluator(name=evaluatorName, ready=newValue)
예제 #2
0
def customEvaluatorActiveStateChange(evaluatorName, newValue):
    """
	Callback when a checkbox is ticked to alter the active state of a custom
	evaluator.
	"""
    print 'Changing evaluator %s active state to %d' % (evaluatorName,
                                                        newValue)
    cmds.evaluator(name=evaluatorName, enable=newValue)
예제 #3
0
def list_frozen_in_scheduling():
    '''
    Returns a list of all nodes that were frozen either directly or
    indirectly as a result of the frozen evaluator settings.

    If no cluster information is available a TypeError is raised.
    If the frozen evaluator is not enabled an AttributeError is raised.
    '''
    if 'frozen' not in cmds.evaluator(enable=True, query=True):
        raise AttributeError('Frozen evaluator is not active')

    frozen_nodes = []
    try:
        clusters = json.loads(
            cmds.dbpeek(op='graph',
                        evaluationGraph=True,
                        all=True,
                        a='scheduling'))['scheduling']['Clusters']
        for cluster_name, cluster_members in clusters.iteritems():
            if RE_FROZEN_CLUSTER.match(cluster_name):
                frozen_nodes += cluster_members
    except:
        # If an exception was raised it was probably due to the dbpeek command not
        # returning scheduling information, which only happens when the graph is
        # not available
        raise TypeError(
            'Cluster information is not available, evaluation graph needs rebuilding'
        )

    return frozen_nodes
예제 #4
0
 def verifyScopeSetup(self):
     '''
     Meta-test to check that the scope was defined correctly
     :param unit_test: The test object from which this method was called
     '''
     self.unit_test.assertTrue( cmds.evaluationManager( mode=True, query=True )[0] == 'parallel' )
     if cmds.pluginInfo('cacheEvaluator', loaded=True, query=True):
         self.unit_test.assertFalse( cmds.evaluator( query=True, en=True, name='cache' ) )
예제 #5
0
 def __save_state(self):
     '''
     Remember the current state of all EM related parameters so that they
     can be restored on exit.
     '''
     _dbg('*** emModeManager::__save_state')
     self.original_mode = cmds.evaluationManager(mode=True, query=True)[0]
     self.original_evaluators_enabled = as_list(
         cmds.evaluator(query=True, enable=True))
     self.original_evaluators_disabled = as_list(
         cmds.evaluator(query=True, enable=False))
     self.original_evaluator_node_types = {}
     for evaluator in self.original_evaluators_enabled + self.original_evaluators_disabled:
         node_types = cmds.evaluator(nodeType=True,
                                     query=True,
                                     name=evaluator)
         if node_types == None:
             node_types = []
         self.original_evaluator_node_types[evaluator] = node_types
     self.plugins_to_unload = []
     return self
예제 #6
0
    def __init__(self, mode, cacheTimeout):
        self.mode = mode
        self.cacheTimeout = cacheTimeout

        self.activeNodeTypes = cmds.evaluator(query=True,
                                              name='cache',
                                              nodeType=True,
                                              enable=True)

        evaluationCache = CacheEvaluatorContext.getEvaluationCache(['mesh'])
        if len(evaluationCache) != 1 or evaluationCache[0] not in [0, 1]:
            raise RuntimeError('Unexpected value for mesh evaluation cache.')
        self.evaluationCacheMesh = evaluationCache[0]
예제 #7
0
	def restore(self):
		'''
		Restore the evaluation manager to its original mode prior to enabling
		this one.  Not necessary to call this when using the "with emModeManager()"
		syntax. Only needed when you explicitly instantiate the mode manager.
		Then you have to call this if you want your original state restored.
		'''
		_dbg( '*** emModeManager::restore' )
		# Prevent multiple calls
		if not self.enabled:
			_dbg( '    Oops, nothing to restore' )
			return

		# Evaluation mode
		if self.restoreMode:
			_dbg( '     Restore mode to %s' % self.restoreMode )
			cmds.evaluationManager( mode=self.restoreMode )

		# Evaluators turned on
		for evaluator in self.evaluatorsTurnedOn:
			_dbg( '     Re-disable %s' % evaluator )
			cmds.evaluator( enable=False, name=evaluator )

		# Evaluators turned off
		for evaluator in self.evaluatorsTurnedOff:
			_dbg( '     Restore %s' % evaluator )
			cmds.evaluator( enable=True, name=evaluator )

		# Plugins we loaded
		for plugin in self.pluginsToUnload:
			try:
				_dbg( '     Unload %s' % plugin )
				cmds.unloadPlugin( plugin )
			except:
				# Just in case someone else already unloaded it
				pass

		self.enabled = False
예제 #8
0
    def __exit__(self, type, value, traceback):
        # Reset the evaluation cache value for meshes.
        vp2Mode = 'On' if self.evaluationCacheMesh else 'Off'
        cmds.evaluator(name='cache',
                       configuration='evaluationCache%s=mesh' % vp2Mode)

        # Disable the evaluator on all the nodes
        cmds.evaluator(name='cache',
                       nodeType='node',
                       nodeTypeChildren=True,
                       enable=False)
        # Enable the evaluator on nodes that were enabled.
        for node in self.activeNodeTypes:
            cmds.evaluator(name='cache',
                           nodeType='node',
                           nodeTypeChildren=False,
                           enable=True)
예제 #9
0
"""
Toggles the Dynamic Evaluation stage for Maya Parallel evaluation.

Useful if dynmaics are causing the scene to run slowly.
"""

import maya.cmds as mc

state = mc.evaluator(q=True, name='dynamics')
mc.evaluator(en=not state, name='dynamics')
if state:
    print('Dynamics Evaluation Turned OFF'),
else:
    print('Dynamics Evaluation Turned ON'),
예제 #10
0
def customEvaluatorUI():
    """
	Create a simple window showing the current status of the custom evaluators
	and providing a callback so that they can update the status when it changes.
	Layout is a row per evaluator with the following information:

		EvaluatorName   Ready []   Active []   <Evaluator-specific information>
	"""
    global customEvaluatorScriptJob
    print 'Constructing custom evaluator UI'
    windowName = 'CustomEvaluatorUI'
    if not cmds.window(windowName, exists=True):
        windowName = cmds.window(windowName,
                                 title='Custom Evaluators',
                                 iconName='Custom Evaluators')
    else:
        cmds.deleteUI('CustomEvaluatorUIList')
        cmds.setParent(windowName)
    if customEvaluatorScriptJob == None:
        customEvaluatorScriptJob = cmds.scriptJob(event=[
            'customEvaluatorChanged',
            'maya.plugin.evaluator.customEvaluatorUI.customEvaluatorUI()'
        ])
    cmds.frameLayout('CustomEvaluatorUIList',
                     label='Custom Evaluator Information')
    cmds.rowColumnLayout('CustomEvaluatorList',
                         numberOfColumns=4,
                         columnAlign=[(1, 'left'), (2, 'center'),
                                      (3, 'center'), (4, 'left')],
                         columnSpacing=[(1, 10), (2, 10), (3, 10), (4, 10)])
    evaluators = cmds.evaluator(query=True, name=True)
    for evaluatorName in evaluators:
        cmds.text(label=evaluatorName, font='boldLabelFont')
        cmds.checkBox(
            value=cmds.evaluatorInternal(name=evaluatorName,
                                         query=True,
                                         ready=True),
            label='Ready',
            onCommand=
            'maya.plugin.evaluator.customEvaluatorUI.customEvaluatorReadyStateChange("%s",True)'
            % evaluatorName,
            offCommand=
            'maya.plugin.evaluator.customEvaluatorUI.customEvaluatorReadyStateChange("%s",False)'
            % evaluatorName)
        cmds.checkBox(
            value=cmds.evaluator(name=evaluatorName, query=True, enable=True),
            label='Active',
            onCommand=
            'maya.plugin.evaluator.customEvaluatorUI.customEvaluatorActiveStateChange("%s",True)'
            % evaluatorName,
            offCommand=
            'maya.plugin.evaluator.customEvaluatorUI.customEvaluatorActiveStateChange("%s",False)'
            % evaluatorName)
        nodeTypes = cmds.evaluator(name=evaluatorName,
                                   query=True,
                                   nodeType=True)
        if nodeTypes:
            nodeTypeCount = len(nodeTypes)
        else:
            nodeTypeCount = 0
        infoString = 'Node Types = %d' % nodeTypeCount
        info = cmds.evaluator(name=evaluatorName, query=True, info=True)
        if info and len(info) > 0:
            infoString = '%s, %s' % (infoString, info)
        cmds.text(label=infoString)
    cmds.setParent('..')
    cmds.button(
        label='Update',
        command='maya.plugin.evaluator.customEvaluatorUI.customEvaluatorUI()')
    cmds.setParent('..')
    cmds.showWindow(windowName)
예제 #11
0
def load_hyperdrive_plugin():
    plugin_name = "hyperdrive"
    if not cmds.pluginInfo(plugin_name, q=True, l=True):
        cmds.loadPlugin(plugin_name)
    cmds.evaluator(enable=True, name='hdEvaluator')
예제 #12
0
    def restore_state(self):
        '''
        Restore the evaluation manager to its original mode prior to creation
        of this object. Using the "with" syntax this will be called automatically.
        You only need to call explicitly when you instantiate the mode manager
        as an object.

        For now the state is brute-force restored to what the original was without
        regards to current settings. The assumptions are that the states are
        independent, and the performance is good enough that it's not necessary to
        remember just the things that were changed.
        '''
        _dbg('*** emModeManager::restore_state')

        # Evaluation mode
        _dbg('     Restore mode to %s' % self.original_mode)
        cmds.evaluationManager(mode=self.original_mode)

        # Evaluators originally on
        for evaluator in self.original_evaluators_enabled:
            _dbg('     Enabling {}'.format(evaluator))
            cmds.evaluator(enable=True, name=evaluator)

        # Evaluators originally off
        for evaluator in self.original_evaluators_disabled:
            _dbg('     Disabling {}'.format(evaluator))
            cmds.evaluator(enable=False, name=evaluator)

        # Node types for evaluators
        for (evaluator, restored_node_types
             ) in self.original_evaluator_node_types.iteritems():
            # The list of node types is too long to just set/unset everything so instead
            # compare the current list with the original list and toggle on and off as
            # appropriate to restore back to the original.
            current_node_types = cmds.evaluator(name=evaluator,
                                                nodeType=True,
                                                query=True)
            if current_node_types == None:
                current_node_types = []
            for node_type in current_node_types:
                if node_type not in restored_node_types:
                    _dbg('     Enabling node type {} on {}'.format(
                        node_type, evaluator))
                    cmds.evaluator(name=evaluator,
                                   nodeType=node_type,
                                   enable=False)
            for node_type in restored_node_types:
                if node_type not in current_node_types:
                    _dbg('     Disabling node type {} on {}'.format(
                        node_type, evaluator))
                    cmds.evaluator(name=evaluator,
                                   nodeType=node_type,
                                   enable=True)

        # Plugins we loaded
        for plugin in self.plugins_to_unload:
            try:
                _dbg('     Unload %s' % plugin)
                cmds.unloadPlugin(plugin)
            except:
                # Just in case someone else already unloaded it
                pass
예제 #13
0
    def setMode(self, modeName):
        '''
        Ensure the EM has a named mode set. See class docs for details on mode names.
        The changes are cumulative so long as they don't conflict so this only sets
        the mode to serial:
            self.setMode('emp')
            self.setMode('ems')
        however this will enable both evaluators
            self.setMode('+deformer')
            self.setMode('+cache')

        Changes can also be put into one single string:
            self.setMode( 'ems+deformer+cache' )

        Lastly by using the '/' character as a separator the enabled node types on
        evaluators can also be manipulated:
            self.setMode( 'ems+deformer+cache/+expression-transform' )

        raises SyntaxError if the mode name is not legal
        '''
        _dbg('*** Setting mode to %s' % modeName)

        # To avoid partial setting the state isn't touched until all mode information
        # has been parsed.
        #
        evaluators_to_enable = []
        evaluators_to_disable = []
        node_types_to_enable = {}
        node_types_to_disable = {}

        match = RE_MODE.match(modeName)
        if match:
            if match.group(1) == 'ems':
                em_mode = 'serial'
            elif match.group(1) == 'emp':
                em_mode = 'parallel'
            elif match.group(1) == 'dg':
                em_mode = 'off'
            elif match.group(1) == '':
                em_mode = cmds.evaluationManager(query=True, mode=True)[0]
            else:
                raise SyntaxError('%s is not a recognized EM mode' %
                                  match.group(1))

            _dbg('    +++ Processing evaluator modes {}'.format(
                match.group(2)))

            # Separate the evaluators from the node types
            evaluator_split = match.group(2).split('/')
            node_types = evaluator_split[1:]
            node_types_to_add = []
            node_types_to_remove = []

            # Now handle the node type information
            for node_type in node_types:
                _dbg('       Raw Node type {}'.format(node_type))
                action = node_type[0]
                node_type_name = node_type[1:]
                _dbg('    ... Node type {} {}'.format(action, node_type_name))

                # Don't allow both '+' and '-', or even two the same
                if node_type_name in node_types_to_add or node_type_name in node_types_to_remove:
                    raise SyntaxError(
                        'Node type {}s was specified twice'.format(
                            node_type_name))

                if action == '+':
                    _dbg('       Will turn on node type {}'.format(
                        node_type_name))
                    node_types_to_add.append(node_type_name)
                elif action == '-':
                    _dbg('       Will turn off node type {}'.format(
                        node_type_name))
                    node_types_to_remove.append(node_type_name)
                else:
                    raise SyntaxError(
                        '{} is not a recognized node type mode (+XX or -XX)'.
                        format(node_type))

            # Process the evaluator modes
            eval_matches = RE_EVALUATORS.findall(evaluator_split[0])
            for eval_match in as_list(eval_matches):
                _dbg('    ... Processing evaluator mode {}'.format(eval_match))
                action = eval_match[0]
                evaluator_info = eval_match[1:].split('/')
                evaluator = evaluator_info[0]
                node_types = evaluator_info[1:]

                # Don't allow both '+' and '-', or even two the same
                if evaluator in as_list(
                        evaluators_to_enable) or evaluator in as_list(
                            evaluators_to_disable):
                    raise SyntaxError('Evaluator %s was specified twice' %
                                      evaluator)

                if action == '+':
                    _dbg('       Will turn on %s' % evaluator)
                    evaluators_to_enable.append(evaluator)
                elif action == '-':
                    _dbg('       Will turn off %s' % evaluator)
                    evaluators_to_disable.append(evaluator)
                else:
                    raise SyntaxError(
                        '%s is not a recognized EM evaluator command (+XX or -XX)'
                        % eval_match)

                # Now handle the node type information
                for node_type in as_list(node_types_to_add):
                    node_types_to_enable[evaluator] = node_types_to_enable.get(
                        evaluator, []) + [node_type]
                for node_type in as_list(node_types_to_remove):
                    node_types_to_disable[
                        evaluator] = node_types_to_disable.get(
                            evaluator, []) + [node_type]
        else:
            raise SyntaxError(
                '%s is not a recognized EM command "{ems|emp|dg}{[+-]XX}*{/[+-]YY}*"'
                % modeName)

        # Now that the state is prepared switch to the new modes
        cmds.evaluationManager(mode=em_mode)

        # Check to see which evaluators had to be turned on and remember them.
        for turn_on in evaluators_to_enable:
            if turn_on in EVALUATOR_PLUGINS:
                # Check the loaded state first to prevent the warning message if it's already loaded
                if not cmds.pluginInfo(
                        EVALUATOR_PLUGINS[turn_on], query=True, loaded=True):
                    _dbg('    Loading plugin %s' % EVALUATOR_PLUGINS[turn_on])
                    loaded = cmds.loadPlugin(EVALUATOR_PLUGINS[turn_on])
                else:
                    loaded = None
                # We like to avoid perturbing state so if we loaded the
                # plug-in we'll unload it when done
                if loaded != None:
                    self.plugins_to_unload += loaded
            cmds.evaluator(enable=True, name=turn_on)
            _dbg('     Enable {}'.format(turn_on))

        # Check to see which evaluators had to be turned off and remember them.
        for turn_off in evaluators_to_disable:
            cmds.evaluator(enable=False, name=turn_off)
            _dbg('     Disable {}'.format(turn_off))

        # If any node type changes were specified do them now
        for (evaluator, node_types) in node_types_to_enable.iteritems():
            for node_type in node_types:
                cmds.evaluator(name=evaluator, enable=True, nodeType=node_type)
                _dbg('     Enable type {} on {}'.format(node_type, evaluator))
        for (evaluator, node_types) in node_types_to_disable.iteritems():
            for node_type in node_types:
                cmds.evaluator(name=evaluator,
                               enable=False,
                               nodeType=node_type)
                _dbg('     Disable type {} on {}'.format(node_type, evaluator))
예제 #14
0
    def __enter__(self):
        cmds.evaluator(name='cache',
                       enable='transform' in self.mode,
                       nodeType='transform',
                       nodeTypeChildren=True)
        cmds.evaluator(name='cache',
                       enable='mesh' in self.mode,
                       nodeType='mesh',
                       nodeTypeChildren=True)
        cmds.evaluator(name='cache',
                       enable='curves' in self.mode,
                       nodeType='nurbsCurve',
                       nodeTypeChildren=True)

        cmds.evaluator(name='cache',
                       enable=False,
                       nodeType='constraint',
                       nodeTypeChildren=True)

        vp2Mode = 'On' if 'meshOnlyVP2' in self.mode else 'Off'
        cmds.evaluator(name='cache',
                       configuration='evaluationCache%s=mesh' % vp2Mode)

        # Trigger background computation.
        cmds.currentTime(cmds.currentTime(query=True))
        # Wait for it to be done.
        cacheIsReady = cmds.evaluator(name='cache',
                                      configuration='waitForCache=%d' %
                                      self.cacheTimeout)[0]
        if not cacheIsReady:
            print 'WARNING: Cache was not completely filled'

        return self
예제 #15
0
	def _enable(self):
		'''
		Put the evaluation manager into this mode
		'''
		_dbg( '*** emModeManager::_enable' )
		# Prevent multiple calls
		if self.enabled:
			_dbg( '    Oops, tried to enable without a disable' )
			return

		self.evaluatorsTurnedOn = []
		self.evaluatorsTurnedOff = []
		self.pluginsToUnload = []
		self.restoreMode = None

		# Doing this the hard way thanks to MAYA-44444
		alreadyEnabled = []
		alreadyDisabled = []
		for evaluator in cmds.evaluator( query=True ):
			if cmds.evaluator( query=True, name=evaluator ):
				alreadyEnabled.append( evaluator )
			else:
				alreadyDisabled.append( evaluator )
		_dbg( '   already enabled = %s' % str(alreadyEnabled) )
		_dbg( '   already disabled = %s' % str(alreadyDisabled) )

		# Modify the mode if necessary, remember where it came from.
		self.restoreMode = None
		originalMode = cmds.evaluationManager( mode=True, query=True )[0]
		if originalMode != self.emMode:
			cmds.evaluationManager( mode=self.emMode )
			self.restoreMode = originalMode

		# Check to see which evaluators had to be turned on and remember them.
		for turnOn in self.evaluatorsToTurnOn:
			# If it was already on don't do anything.
			if turnOn in alreadyEnabled:
				_dbg( '      No need to enable %s, it is already enabled' % turnOn )
				continue
			if turnOn in evaluatorPlugins:
				_dbg( '    Loading plugin %s' % evaluatorPlugins[turnOn] )
				loaded = cmds.loadPlugin( evaluatorPlugins[turnOn] )
				# We like to avoid perturbing state so if we loaded the
				# plug-in we'll unload it when done
				if loaded != None:
					self.pluginsToUnload += loaded
			self.evaluatorsTurnedOn.append( turnOn )
			cmds.evaluator( enable=True, name=turnOn )
			_dbg( '     Enable %s' % turnOn )

		# Check to see which evaluators had to be turned off and remember them.
		for turnOff in self.evaluatorsToTurnOff:
			# If it was already off don't do anything. Checking the enabled
			# list accounts for the possibility of a plugin not being loaded.
			if turnOff not in alreadyEnabled:
				_dbg( '      No need to disable %s, it is not enabled' % turnOff )
				continue
			self.evaluatorsTurnedOff.append( turnOff )
			cmds.evaluator( enable=False, name=turnOff )
			_dbg( '     Disable %s' % turnOff )

		self.enabled = True