Emmit Particle by python script

CrashAutoSave.isolateIssue.10.toe (74.7 KB)
isolateIssue.10.toe (74.7 KB)
TouchDesignerCrash.2023.12230_2.dmp (512.5 KB)
Hi !

I would like to emit a bunch of particles by script depending on point number.
I found an easy solution :
I have a line with N points ; i select the point using a GROUP SOP, then inside the PARTICLE SOP, i set the particle number, to the size of the list of points , then i pulse() the Birth parameter.
In the joined file i add a button to activate the script

i would say 25 percent of time it crashes TD
i found a small workaround by add a running the pulse with a delayframe , but i reduce the crash rate, but still crashes …

i found a another workaround that works fine with 50 points , i create 1 particle emmiter per points … but as i aim 1K points .. not sure its a clever solution

Thanks for the help / advices
build 2023.12230

Hi @laurent,

slightly different idea: you could make use of the Particle SOP’s .createParticle() method which lets you specify the number of particles you want to create.
To randomize the whole thing even more, add a Sort SOP before the Particle SOP and randomize points while also animating the Seed parameter with an expression like absTime.frame.
With this you can remove the Group SOP and your script simplifies a bit (using a Panel Execute DAT on the Button instead of a CHOP Execute DAT):

import random
def onOffToOn(panelValue):
	nrParticles = random.randint(1, 10)
	op('particuleRenderer/particle').createParticles(nrParticles)
	return

cheers
Markus