def getSelectedTokenUid(self): """ This returns the URL of the currently selected token, or None. """ conn = nimble.getConnection() result = conn.runPythonModule(GetSelectedUidList, runInMaya=True) # Check to see if the remote command execution was successful if not result.success: PyGlassBasicDialogManager.openOk( self, 'Failed UID Query', 'Unable to get selected UID list from Maya', 'Error') return None selectedUidList = result.payload['selectedUidList'] if len(selectedUidList) == 0: return None # check to see if it really is a proxy or token that was selected uid = selectedUidList[0] if uid.endswith('_proxy') or uid.endswith('_token'): return uid else: return None
def getSelectedTracks(self): """ This returns a list of track model instances corresponding to the track nodes that are currently selected. To achieve this, it first runs a remote script to get a list of track UIDs from the selected Maya track nodes. A list of the corresponding track models is then returned. """ conn = nimble.getConnection() result = conn.runPythonModule(GetSelectedUidList, runInMaya=True ) # Check to see if the remote command execution was successful if not result.success: PyGlassBasicDialogManager.openOk( self, 'Failed UID Query', 'Unable to get selected UID list from Maya', 'Error') return None # from this UID list, create the corresponding track list selectedUidList = result.payload['selectedUidList'] if len(selectedUidList) == 0: return None tracks = list() for uid in selectedUidList: track = self.getTrackByUid(uid) if track: track.updateFromNode() tracks.append(track) return tracks
def getSelectedTokenUids(self): """ This returns a list of URL of the currently selected tokens, or None. """ conn = nimble.getConnection() result = conn.runPythonModule(GetSelectedUidList, runInMaya=True) # Check to see if the remote command execution was successful if not result.success: PyGlassBasicDialogManager.openOk( self, 'Failed UID Query', 'Unable to get selected UID list from Maya', 'Error') return None selectedUidList = result.payload['selectedUidList'] if len(selectedUidList) == 0: return None # return those UIDs corresponding to proxies or tokens tokenUidList = list() for uid in selectedUidList: if uid.endswith('_proxy') or uid.endswith('_token'): tokenUidList.append(uid) return tokenUidList
def __init__(self, parent, **kwargs): """Creates a new instance of AlloyHomeWidget.""" PyGlassWidget.__init__(self, parent, widgetFile=False, **kwargs) try: conn = nimble.getConnection() except Exception, err: pass
def deleteTokens(self): """ This sets the attributes in the Maya token based on the properties of the props dictionary that is passed. """ conn = nimble.getConnection() result = conn.runPythonModule(DeleteTokens, runInMaya=True) return result.success
def render(directory=None, name=None, flags=None): """ Renders the current scene and saves the result to an image file """ conn = nimble.getConnection() return conn.runPythonClass(RenderScene, name=name, directory=directory, render_flags=flags)
def setTokenProps(self, uid, props): """ This sets the attributes in the Maya token based on the properties of the props dictionary that is passed. """ conn = nimble.getConnection() result = conn.runPythonModule( UpdateToken, uid=uid, props=props, runInMaya=True) return result.success
def _handleInitializeSceneClick(self): conn = nimble.getConnection() result = conn.runPythonModule(InitializeTrackwayScene) if not result.success: header = u'Failed' message = u'Unable to initialize your Maya scene' PyGlassBasicDialogManager.openOk( self.mainWindow, header, message, u'Initialize Scene') self._iniBtn.setText(u'Reinitialize')
def getTokenProps(self, uid): """ This returns a dictionary of properties from the Maya token specified by the uid, or an error if it does not exist. This function treats a token and a track node as equivalent. """ conn = nimble.getConnection() result = conn.runPythonModule(GetTokenProps, uid=uid, runInMaya=True) if result.payload.get('error'): print('Error in getTokenProps:', result.payload.get('message')) return False return result.payload.get('props')
def createTokens(self, propsList): """ Create tokens in Maya, each based on the properties specified by a corresponding dictionary props within the list propsList. """ conn = nimble.getConnection() result = conn.runPythonModule( CreateTokens, propsList=propsList, runInMaya=True) if result.payload.get('error'): print('Error in createTokens:', result.payload.get('message')) return False
def render(directory=None, name=None, flags=None): """ Renders the current scene and saves the result to an image file """ conn = nimble.getConnection() return conn.runPythonClass( RenderScene, name=name, directory=directory, render_flags=flags )
def createToken(self, props): """ Create a token in Maya, using the uid and properties specified in the dictionary props. """ conn = nimble.getConnection() result = conn.runPythonModule( CreateToken, uid=props['uid'], props=props, runInMaya=True) if result.payload.get('error'): print('Error in createToken:', result.payload.get('message')) return False
def updateNode(self): """ Sends values to Maya nodeName representation of the track to synchronize the values in the model and the nodeName. """ conn = nimble.getConnection() result = conn.runPythonModule( UpdateTrackNode, uid=self.uid, props=self.toMayaNodeDict(), runInMaya=True) if not result.success: return False self.nodeName = result.payload.get('nodeName') return True
def getTokenNodeName(self, uid): """ This gets the name of the token (i.e., the string name of the transform node for a specified UID string). It returns None if that token is not found. """ # if asking for nothing, then get nothing in return if uid is None: return None conn = nimble.getConnection() result = conn.runPythonModule(GetTokenProps, uid=uid, runInMaya=True) if result.payload.get('error'): print('Error in getTokenNodeName:', result.payload.get('message')) return False return result.payload.get('nodeName')
def getUidList(self): """ Returns a list of the UIDs of all track nodes currently loaded into Maya. """ conn = nimble.getConnection() result = conn.runPythonModule(GetUidList, runInMaya=True) # and check to see if the remote command execution was successful if not result.success: PyGlassBasicDialogManager.openOk( parent=self, header='ERROR', message='Unable to get UID list from Maya') self.closeSession() return None self.closeSession() return result.payload['uidList']
def pingTest(): from pyaid.string.StringUtils import StringUtils import nimble nimble.changeKeepAlive(keepAlive) conn = nimble.getConnection() #----------------------------------------------------------------------------------------------- # PING # An empty call that tests that the Nimble connection is able to complete a request and # response loop and prints the response object when complete. for i in range(iterations): result = conn.ping() if not runSilent: print(u'PING:', result.echo(True, True)) #----------------------------------------------------------------------------------------------- # ECHO # A basic call that sends an echo message, which the remote Nimble server returns in the # response. Confirms that data can be set, read, and returned through the Nimble # connection. smallMessage = 'This is a test' for i in range(iterations): result = conn.echo(smallMessage) if not runSilent: print(u'ECHO:', result.echo(True, True)) #----------------------------------------------------------------------------------------------- # LONG ECHO # A repeat of the echo test, but with a very long echo message that tests the ability for # the Nimble socket protocols to chunk and stream large messages without losing data. The # test is also repeated numerous times to confirm that the nimble socket connection # survives through high-intensity multi-stage communication. largeMessage = StringUtils.getRandomString(64000) for i in range(iterations): result = conn.echo(largeMessage) if not runSilent: print(u'LARGE ECHO[#%s]:' % i, result.echo(True, True)) print(u'\nTests Complete')
def getTrackNode(self, track): """ This gets the (transient) Maya node name corresponding to a given track, or returns None if that track has not yet been loaded into Maya as a node. """ # if asking for nothing, then get nothing in return if track is None: return None conn = nimble.getConnection() result = conn.runPythonModule( GetTrackNodeProps, uid=track.uid, nodeName=track.nodeName, runInMaya=True) if result.payload.get('error'): print('Error in getTrackNode:', result.payload.get('message')) return False return result.payload.get('nodeName')
def updateFromNode(self): """ Retrieves Maya values from the nodeName representation of the track and updates this model instance with those values. """ conn = nimble.getConnection() result = conn.runPythonModule( GetTrackNodeProps, uid=self.uid, nodeName=self.nodeName, runInMaya=True) if result.payload.get('error'): print('Error in updateFromNode:', result.payload.get('message')) return False self.nodeName = result.payload.get('nodeName') if self.nodeName: self.fromDict(result.payload.get('props')) return True return False
def createTrackNode(self): """ Create a visual representation of a track, to signify the position, dimensions (length and width), and rotation of either a manus or pes track. The representation has basic dimensions of one meter so that the scale in x and z equates to the width and length of the manus or pes in fractional meters (e.g., 0.5 = 50 cm). The node is prohibited from changing in y (elevation) or to rotate about either x or z. """ conn = nimble.getConnection() out = conn.runPythonModule( CreateTrackNode, uid=self.uid, props=self.toMayaNodeDict(), runInMaya=True) if not out.success: print('Error in CreateNode:', out.error) return None self.nodeName = out.payload.get('nodeName') return self.nodeName
def _handleExecuteCommand(self, payload): if 'commandID' in payload: command = AlloyData.getCommandData(payload['commandID']) elif 'variantID' in payload: command = AlloyData.getVariantData(payload['variantID']) else: return False if not command: return False if command['language'] == 'python': if command['location'] == 'remote': return remoteExec(command['script']) else: try: conn = nimble.getConnection() conn.runPythonScript(command['script']) except Exception, err: print err return False
return False if command['language'] == 'python': if command['location'] == 'remote': return remoteExec(command['script']) else: try: conn = nimble.getConnection() conn.runPythonScript(command['script']) except Exception, err: print err return False else: print 'Executing mel script' try: conn = nimble.getConnection() conn.runMelScript(command['script']) except Exception, err: print err return False return True #___________________________________________________________________________________________________ _handleGetImageCategories def _handleGetImageCategories(self, payload): out = [] rootPath = AlloyEnvironment.getRootIconPath() for p in os.listdir(rootPath): path = os.path.join(rootPath, p) if not os.path.isdir(path): continue
name = result[0] offset = kwargs.get('offset', 10) cmds.move(offset, offset, offset, name) cmds.rotate(50, 20, 10, name) cmds.scale(2, 2, 2, name) response = nimble.createRemoteResponse(globals()) response.put('name', name) response.put('offset', offset) """ #--------------------------------------------------------------------------------------------------- print('RUNNING SCRIPT:') conn = nimble.getConnection() result = conn.runPythonScript(script, offset=20) print('\tRESULT:', result, type(result)) print('\tPAYLOAD:', result.payload) #--------------------------------------------------------------------------------------------------- print('RUNNING FILE:') result = conn.runPythonScriptFile(FileUtils.createPath(os.path.abspath( os.path.dirname(__file__)), 'pythonTestScript.py', isFile=True), offset=5) print('\tRESULT:', result, type(result)) print('\tPAYLOAD:', result.payload)
def _runImpl(self): """Doc...""" self._output = nimble.getConnection().runPythonModule(*self._args, **self._kwargs)