import bpy import os import numpy import random def animatetext(scene): filebase = 'M33AndMilkyWay5' # Get the current frame frame = bpy.context.scene.frame_current - 100 filename = filebase+'_'+str(frame).zfill(3)+'.txt' print(filename) # Check if the file exists checkfile = str(os.path.isfile(filename)) print(checkfile) if (checkfile == 'True'): #print('hello') # Read in the data from the correct file data = numpy.genfromtxt(filename) sizex = int(numpy.max(data[:,0]))+1 sizey = int(numpy.max(data[:,1]))+1 # Get the minimum flux minf = abs(numpy.nanmin(data[:,3])) if minf >= 0.05: minf = 0.05 # Correct the flux values all at once (faster and makes them easier to # work with later) data[:,3] = 200.0*numpy.sqrt(data[:,3]+minf) medflux = numpy.nanmedian(data[:,3]) for obj in bpy.data.objects: if 'text_' in obj.name: # Alter locations. XY will be fixed. Only Z varies. index = obj.name.split('_')[1] obx = obj.location[0] oby = obj.location[1] obj.location =(obx,oby,0.5*(data[index,3]-medflux)) if numpy.isnan(data[index,3]): obj.location=(obx,oby,0.0) # Edit text values flux = "{:.0f}".format(data[index,3]-medflux) if (data[index,3]-medflux < 0.0): absflux = abs(data[index,3]-medflux) flux = '_'+"{:.0f}".format(absflux) if numpy.isnan(data[index,3]): flux = 'n' if str(0) in flux: if random.random() >= 0.75: flux = str(')') if str(1) in flux: if random.random() >= 0.75: flux = 'm' if str(2) in flux: if random.random() >=0.75: flux = 's' myFontOb = bpy.data.objects.get('text_'+str(index)) myFontOb.data.body = flux # Run the script every time the frame has changed bpy.app.handlers.frame_change_pre.append(animatetext)