Change Particle Size Via Script

Hi,
is there a way to change the Particle Size via Script?
I tried doing it with:


 bpy.data.objects['MyPartikelEmitter'].particle_systems[0].particles[1].size = 10

It works in the Viewport but as soon as I hit render the particle Size goes back to whatever is set in the Particle Systems Size Value.

What I am trying to do is write an importer for Particles. It works quite good for Position and Rotation so far. Only the Size keeps hopping back to the setting in the particle system.

The script reads a .txt file per frame containing information about locaton, rotation and scale.

A Textfile is created with 3ds Max and might look like this if the system has 7 particles:


7
#(1, 1678, 518.801, 656.922, 100.133, -180.0, 0.0, 0.0, 0.993611, 1, 1)
#(2, 1679, 518.799, 656.915, 100.078, -180.0, 0.0, 0.0, 0.927934, 1, 1)
#(3, 1680, 518.798, 656.909, 100.023, -180.0, 0.0, 0.0, 1.0385, 1, 1)
#(4, 1681, 531.588, 673.46, 20.6493, -180.0, 0.0, 0.0, 1.02504, 1, 1)
#(5, 1682, 531.571, 673.454, 20.5221, -180.0, 0.0, 0.0, 1.02756, 1, 1)
#(6, 1683, 531.554, 673.447, 20.3949, -180.0, 0.0, 0.0, 1.02471, 1, 1)
#(7, 1684, 540.263, 676.135, 17.0832, -180.0, 0.0, 0.0, 1.02202, 1, 1)

The script then loops through all particles and sets their location, rotation and size.
Hier is the script:


import bpy
import math
import mathutils
from math import radians, pi
from mathutils import Vector, Euler, Quaternion
ob_emitter = bpy.data.objects
mysystem = ob_emitter['PartikelEmitter_RAT'].particle_systems[0]

def load_handler(dummy):
    mycurrentframe = bpy.context.scene.frame_current + 1
    mycurrentstring = str(mycurrentframe - 1) 
    filepath = bpy.path.abspath("//ParticleCaches//RAT//RAT1_"+mycurrentstring+".txt")
    myfile2 = open(filepath)
    myfile = open(filepath)
    myfile3 = open(filepath)
    testmy = myfile3.read().splitlines()
    PartCount = testmy[0]#myfile2.read().splitlines()[0]
    PartCountInt = int(PartCount)
    if (len(testmy))>1:
        myarray =  testmy[1].split(',') 
        del myarray[0]
        del myarray[9]
        
        myfloats = [float(s) for s in myarray]
        
        for x in range(1,PartCountInt+1):        #script loops through all particles in the particle system
            myarray = []
            
            myarray =  testmy[x].split(',')
            del myarray[0]
            del myarray[9]    
            myfloats = [float(s) for s in myarray]
            myID = int(myfloats[0]-1)

            mysystem.particles[myID].location = [(myfloats[1])*0.01,(myfloats[2])*0.01,(myfloats[3])*0.01]  
            myroteuler = (Euler((math.radians(myfloats[4]),math.radians(myfloats[5]),math.radians(myfloats[6])), 'XYZ'))
            myrotquat = myroteuler.to_quaternion()
            
            mysystem.particles[myID].rotation = myrotquat
            mysystem.particles[myID].size = myfloats[7] * 0.01      #HERE THE PARTICLES SIZE IS SET

    myfile2.close()
       
   
#bpy.app.handlers.frame_change_pre.append(load_handler)    # I have tried calling the handler with different options such as pre and post rendering but nothing works
bpy.app.handlers.frame_change_post.append(load_handler) 
#bpy.app.handlers.render_pre.append(load_handler) 
#bpy.app.handlers.render_post.append(load_handler)   
#bpy.app.handlers.scene_update_post.append(load_handler)
#bpy.app.handlers.scene_update_pre.append(load_handler)

Here is an example: I rendered two images, one by displaying the viewport as rendered. The image is correct. The other image shows what happens if I render with F12, the Render Button or the Animate Button. The particles are scaled back to the value they are set to in the particle system, in this case 0.001.

Is it possible to override this setting somehow?


Attachments