def Push(groups="sync"): # create Internet TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'localhost' # server address port = 51234 # server port try: try: print >> sys.stderr, "CONNECTING TO SERVER" # connect to server s.connect((host, port)) file = s.makefile("rw", 0) if type(groups) != list: if groups == "sync": file.write("PUSH sync\n") fromMaya = MasReader.read(file) groups = [] for group in fromMaya.groups: groups.append(group.name) else: raise Errors.BadArgumentError( "%s is not a supported 'groups' value." % groups) else: file.write("PUSH\n") MsvPlacement.dump(file, groups) except Exception, e: print >> sys.stderr, e finally: s.close() # close socket print >> sys.stderr, "CONNECTION CLOSED"
def Push(groups="sync"): # create Internet TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'localhost' # server address port = 51234 # server port try: try: print >> sys.stderr, "CONNECTING TO SERVER" # connect to server s.connect((host, port)) file = s.makefile("rw", 0) if type(groups) != list: if groups == "sync": file.write("PUSH sync\n") fromMaya = MasReader.read(file) groups = [] for group in fromMaya.groups: groups.append(group.name) else: raise Errors.BadArgumentError("%s is not a supported 'groups' value." % groups) else: file.write("PUSH\n") MsvPlacement.dump(file, groups) except Exception, e: print >> sys.stderr, e finally: s.close() # close socket print >> sys.stderr, "CONNECTION CLOSED"
def setMas(self, masFile): '''Load a .mas file into a MasSpec, and any referenced .cdl files into AgentSpecs.''' self._baseName = os.path.splitext(os.path.basename(masFile))[0] self._mas = MasReader.read(masFile) for cdlFile in self._mas.cdlFiles: self.addCdl(cdlFile.file, cdlFile.type)
def doQuery( self, argData ): if argData.isFlagSet( kSelectionFlag ): if argData.isFlagSet( kMasFileFlag ): masFile = argData.flagArgumentString( kMasFileFlag, 0 ) fileHandle = open(masFile, "r") try: mas = MasReader.read( fileHandle ) finally: fileHandle.close() self.setResult( mas.selectionGroup.selectionNames() ) else: raise ns.py.Error.BadArgumentError( "When querying the -selection flag please use the -masFile to indicate which .mas file's selections to query." ) else: raise ns.py.Error.BadArgumentError( 'Only the -selection flag is queryable.' )
def Pull(): # create Internet TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'localhost' # server address port = 51234 # server port try: print >> sys.stderr, "CONNECTING TO SERVER" # connect to server s.connect((host, port)) file = s.makefile("rw", 0) file.write("PULL\n") #for line in file.readlines(): # print >> sys.stderr, line.strip() mas = MasReader.read(file) MsvPlacement.build(mas) finally: s.close() # close socket print >> sys.stderr, "CONNECTION CLOSED"
def main(): Timer.push("MsvTranslator") (args, flags) = parseArgs() if not args['masFile'] or not args['outputDir']: raise Exception( "Both the -masFile and -outputDir flags must be specified.") mas = MasReader.read(args['masFile']) basename = os.path.splitext(os.path.basename(args['masFile']))[0] fileSuffix = mayaFileSuffix(args['outputType']) groupSize = args['groupSize'] if groupSize < 1: groupSize = mas.numAgents finalLog = "%s/%s.log" % (args['outputDir'], basename) tempLog = "%s/%s.temp.log" % (args['outputDir'], basename) for group in range(1, mas.numAgents + 1, groupSize): currentFile = "" rangeStr = "" if groupSize < mas.numAgents: currentFile = "%s/%s_%d.%s" % (args['outputDir'], basename, group, fileSuffix) if groupSize == 1: rangeStr = ' -range \\"%s\\"' % str(group) else: rangeStr = ' -range \\"%d-%d\\"' % (group, group + groupSize - 1) else: currentFile = "%s/%s.%s" % (args['outputDir'], basename, fileSuffix) # Ideally we could do this as a standalone script using # maya.standalone. However, for some reason, when nsImportMsv # is run as part of a standalone script it doesn't work right. # For example, extra anim curves get created for ry and rz # when only rx is keyed, and the keyed values are not correctly # saved out to disk. Running it as part of maya batch, however, # seems to work fine. This may be because nsImportMsv is implemented # using the python interface to MEL as opposed to the API and # maya.standalone is, perhaps, intended for use with the python # API bindings (although this is pure speculation). # mel = 'cmdFileOutput -o \\"%s\\";' % tempLog mel += ' loadPlugin \\"MsvTools.py\\";' mel += ' msvSimImport%s%s;' % (rangeStr, flags) mel += ' file -rename \\"%s\\";' % currentFile mel += ' file -f -uc 0 -type \\"%s\\" -save;' % args['outputType'] mel += ' cmdFileOutput -closeAll;' batchCmd = 'maya -batch -command "%s"' % mel print >> sys.stderr, batchCmd os.system(batchCmd) tempLogFile = open(tempLog, "r") finalLogFile = open(finalLog, "a") finalLogFile.writelines(tempLogFile.readlines()) finalLogFile.close() tempLogFile.close() if groupSize < mas.numAgents: mel = 'cmdFileOutput -o \\"%s\\";' % tempLog mel += ' msvCombiner( \\"%s\\", \\"%s\\", \\"%s\\", %d, %d );' % ( args['outputDir'], basename, args['outputType'], groupSize, mas.numAgents) mel += ' cmdFileOutput -closeAll;' batchCmd = 'maya -batch -command "%s"' % mel print >> sys.stderr, batchCmd os.system(batchCmd) tempLogFile = open(tempLog, "r") finalLogFile = open(finalLog, "a") finalLogFile.writelines(tempLogFile.readlines()) finalLogFile.close() tempLogFile.close() os.remove(tempLog) Timer.pop() print >> sys.stderr, "" print >> sys.stderr, "######################################################################" print >> sys.stderr, "### Done in %f seconds" % Timer.elapsed( "MsvTranslator") print >> sys.stderr, "### %s" % args['masFile'] print >> sys.stderr, "### converted to" print >> sys.stderr, "### %s/%s.%s" % (args['outputDir'], basename, fileSuffix) print >> sys.stderr, "###" print >> sys.stderr, "### See %s for a log of results." % finalLog print >> sys.stderr, "######################################################################" print >> sys.stderr, "" exit(0)
def main(): Timer.push("MsvTranslator") (args, flags) = parseArgs() if not args['masFile'] or not args['outputDir']: raise Exception("Both the -masFile and -outputDir flags must be specified.") mas = MasReader.read(args['masFile']) basename = os.path.splitext(os.path.basename(args['masFile']))[0] fileSuffix = mayaFileSuffix( args['outputType'] ) groupSize = args['groupSize'] if groupSize < 1: groupSize = mas.numAgents finalLog = "%s/%s.log" % (args['outputDir'], basename) tempLog = "%s/%s.temp.log" % (args['outputDir'], basename) for group in range(1, mas.numAgents+1, groupSize ): currentFile = "" rangeStr = "" if groupSize < mas.numAgents: currentFile = "%s/%s_%d.%s" % (args['outputDir'], basename, group, fileSuffix) if groupSize == 1: rangeStr = ' -range \\"%s\\"' % str(group) else: rangeStr = ' -range \\"%d-%d\\"' % (group, group + groupSize - 1) else: currentFile = "%s/%s.%s" % (args['outputDir'], basename, fileSuffix) # Ideally we could do this as a standalone script using # maya.standalone. However, for some reason, when nsImportMsv # is run as part of a standalone script it doesn't work right. # For example, extra anim curves get created for ry and rz # when only rx is keyed, and the keyed values are not correctly # saved out to disk. Running it as part of maya batch, however, # seems to work fine. This may be because nsImportMsv is implemented # using the python interface to MEL as opposed to the API and # maya.standalone is, perhaps, intended for use with the python # API bindings (although this is pure speculation). # mel = 'cmdFileOutput -o \\"%s\\";' % tempLog mel += ' loadPlugin \\"MsvTools.py\\";' mel += ' msvSimImport%s%s;' % (rangeStr, flags) mel += ' file -rename \\"%s\\";' % currentFile mel += ' file -f -uc 0 -type \\"%s\\" -save;' % args['outputType'] mel += ' cmdFileOutput -closeAll;' batchCmd = 'maya -batch -command "%s"' % mel print >> sys.stderr, batchCmd os.system(batchCmd) tempLogFile = open( tempLog, "r" ) finalLogFile = open( finalLog, "a" ) finalLogFile.writelines( tempLogFile.readlines() ) finalLogFile.close() tempLogFile.close() if groupSize < mas.numAgents: mel = 'cmdFileOutput -o \\"%s\\";' % tempLog mel += ' msvCombiner( \\"%s\\", \\"%s\\", \\"%s\\", %d, %d );' % (args['outputDir'], basename, args['outputType'], groupSize, mas.numAgents) mel += ' cmdFileOutput -closeAll;' batchCmd = 'maya -batch -command "%s"' % mel print >> sys.stderr, batchCmd os.system(batchCmd) tempLogFile = open( tempLog, "r" ) finalLogFile = open( finalLog, "a" ) finalLogFile.writelines( tempLogFile.readlines() ) finalLogFile.close() tempLogFile.close() os.remove( tempLog ) Timer.pop() print >> sys.stderr, "" print >> sys.stderr, "######################################################################" print >> sys.stderr, "### Done in %f seconds" % Timer.elapsed("MsvTranslator") print >> sys.stderr, "### %s" % args['masFile'] print >> sys.stderr, "### converted to" print >> sys.stderr, "### %s/%s.%s" % (args['outputDir'], basename, fileSuffix) print >> sys.stderr, "###" print >> sys.stderr, "### See %s for a log of results." % finalLog print >> sys.stderr, "######################################################################" print >> sys.stderr, "" exit(0)