def _buildApiRelationships(self) : """ Used to rebuild api info from scratch. WARNING: will load all maya-installed plugins, without making an attempt to return the loaded plugins to the state they were at before this command is run. Also, the act of loading all the plugins may crash maya, especially if done from a non-GUI session """ # Put in a debug, because this can be crashy _logger.debug("Starting ApiCache._buildApiTypeHierarchy...") if not startup.mayaStartupHasRun(): startup.mayaInit() import maya.cmds import pymel.api.plugins as plugins # load all maya plugins # There's some weirdness with plugin loading on windows XP x64... if # you have a fresh user profile, and do: # import maya.standalone # maya.standalone.initialize() # import maya.mel as mel # mel.eval('''source "initialPlugins.mel"''') # ..then things work. But if you import maya.OpenMaya: # import maya.standalone # maya.standalone.initialize() # import maya.OpenMaya # import maya.mel as mel # mel.eval('''source "initialPlugins.mel"''') # ...it crashes when loading Mayatomr. Also, oddly, if you load # Mayatomr directly, instead of using initialPlugins.mel, it also # crashes: # import maya.standalone # maya.standalone.initialize() # import maya.cmds # maya.cmds.loadPlugin('C:\\3D\\Autodesk\\Maya2012\\bin\\plug-ins\\Mayatomr.mll') # Anyway, for now, adding in the line to do sourcing of initialPlugins.mel # until I can figure out if it's possible to avoid this crash... import maya.mel maya.mel.eval('source "initialPlugins.mel"') plugins.loadAllMayaPlugins() self._buildApiClassInfo() self._buildMayaToApiInfo() self._buildApiTypeToApiClasses() _logger.debug("...finished ApiCache._buildApiTypeHierarchy")
def _buildApiRelationships(self): """ Used to rebuild api info from scratch. WARNING: will load all maya-installed plugins, without making an attempt to return the loaded plugins to the state they were at before this command is run. Also, the act of loading all the plugins may crash maya, especially if done from a non-GUI session """ # Put in a debug, because this can be crashy _logger.debug("Starting ApiCache._buildApiTypeHierarchy...") def _MFnType(x): if x == api.MFnBase: return self.apiEnumsToApiTypes[1] # 'kBase' else: try: return self.apiEnumsToApiTypes[x().type()] except: return self.apiEnumsToApiTypes[0] # 'kInvalid' if not startup.mayaStartupHasRun(): startup.mayaInit() import maya.cmds import pymel.api.plugins as plugins # load all maya plugins # There's some weirdness with plugin loading on windows XP x64... if # you have a fresh user profile, and do: # import maya.standalone # maya.standalone.initialize() # import maya.mel as mel # mel.eval('''source "initialPlugins.mel"''') # ..then things work. But if you import maya.OpenMaya: # import maya.standalone # maya.standalone.initialize() # import maya.OpenMaya # import maya.mel as mel # mel.eval('''source "initialPlugins.mel"''') # ...it crashes when loading Mayatomr. Also, oddly, if you load # Mayatomr directly, instead of using initialPlugins.mel, it also # crashes: # import maya.standalone # maya.standalone.initialize() # import maya.cmds # maya.cmds.loadPlugin('C:\\3D\\Autodesk\\Maya2012\\bin\\plug-ins\\Mayatomr.mll') # Anyway, for now, adding in the line to do sourcing of initialPlugins.mel # until I can figure out if it's possible to avoid this crash... import maya.mel maya.mel.eval('source "initialPlugins.mel"') plugins.loadAllMayaPlugins() # all of maya OpenMaya api is now imported in module api's namespace mfnClasses = inspect.getmembers( api, lambda x: inspect.isclass(x) and issubclass(x, api.MFnBase)) for name, mfnClass in mfnClasses: current = _MFnType(mfnClass) if not current: _logger.warning("MFnClass gave MFnType %s" % current) elif current == 'kInvalid': _logger.warning("MFnClass gave MFnType %s" % current) else: self.apiTypesToApiClasses[current] = mfnClass self._buildApiClassInfo() allMayaTypes = self.reservedMayaTypes.keys() + maya.cmds.ls( nodeTypes=True) self._buildMayaToApiInfo(allMayaTypes) _logger.debug("...finished ApiCache._buildApiTypeHierarchy")
def _buildApiRelationships(self) : """ Used to rebuild api info from scratch. WARNING: will load all maya-installed plugins, without making an attempt to return the loaded plugins to the state they were at before this command is run. Also, the act of loading all the plugins may crash maya, especially if done from a non-GUI session """ # Put in a debug, because this can be crashy _logger.debug("Starting ApiCache._buildApiTypeHierarchy...") def _MFnType(x) : if x == api.MFnBase : return self.apiEnumsToApiTypes[ 1 ] # 'kBase' else : try : return self.apiEnumsToApiTypes[ x().type() ] except : return self.apiEnumsToApiTypes[ 0 ] # 'kInvalid' if not startup.mayaStartupHasRun(): startup.mayaInit() import maya.cmds import pymel.api.plugins as plugins # load all maya plugins # There's some weirdness with plugin loading on windows XP x64... if # you have a fresh user profile, and do: # import maya.standalone # maya.standalone.initialize() # import maya.mel as mel # mel.eval('''source "initialPlugins.mel"''') # ..then things work. But if you import maya.OpenMaya: # import maya.standalone # maya.standalone.initialize() # import maya.OpenMaya # import maya.mel as mel # mel.eval('''source "initialPlugins.mel"''') # ...it crashes when loading Mayatomr. Also, oddly, if you load # Mayatomr directly, instead of using initialPlugins.mel, it also # crashes: # import maya.standalone # maya.standalone.initialize() # import maya.cmds # maya.cmds.loadPlugin('C:\\3D\\Autodesk\\Maya2012\\bin\\plug-ins\\Mayatomr.mll') # Anyway, for now, adding in the line to do sourcing of initialPlugins.mel # until I can figure out if it's possible to avoid this crash... import maya.mel maya.mel.eval('source "initialPlugins.mel"') plugins.loadAllMayaPlugins() # all of maya OpenMaya api is now imported in module api's namespace mfnClasses = inspect.getmembers(api, lambda x: inspect.isclass(x) and issubclass(x, api.MFnBase)) for name, mfnClass in mfnClasses: current = _MFnType(mfnClass) if not current: _logger.warning("MFnClass gave MFnType %s" % current) elif current == 'kInvalid': _logger.warning("MFnClass gave MFnType %s" % current) else: self.apiTypesToApiClasses[ current ] = mfnClass self._buildApiClassInfo() allMayaTypes = self.reservedMayaTypes.keys() + maya.cmds.ls(nodeTypes=True) self._buildMayaToApiInfo(allMayaTypes) _logger.debug("...finished ApiCache._buildApiTypeHierarchy")