Loop of tasks using python

Hi there,
I used to automate tasks in touchdesigner and still do,
usually i create loop in python script that change parameters, doing pulses and force cook the nodes each cycle of the loop.

But this time,
I try to loop over paths in folder DAT, the path are part of other blender
process i run each loop.

I cant make the automation work, it always stop after the first time.
any ideas ?

the loop :

[code]folderOBJs = op(‘OBJs’)
animateMachine = op(‘animateMachine’)
objectPath = op(‘objectPath’)
numOBJs = folderOBJs.numRows - 1
print ("Number of objs detected : ",numOBJs)

for path in folderOBJs.rows()[1:] :

objPath = path[0]

animateMachine.par.Rawmodel = objPath

animateMachine.par.Run.pulse()[/code]

the process:

[code]
def onPulse(par):

#acquire paths
scriptFile = str(parent().par.Script)
rawModel = str(parent().par.Rawmodel)
animationFile = str(parent().par.Animationfile)
outputModel = str(parent().par.Outputmodel)

print(scriptFile)
print(rawModel)
print(animationFile)
print(outputModel)

directory = str( os.path.dirname(rawModel)+"/out" )
if not os.path.exists(directory):
	os.makedirs(directory)


file_name = rawModel.replace(".obj",".fbx")

outputModel = directory + file_name[file_name.rfind('/'):]

print (outputModel)

process = Popen(
[

r'C:\Program Files\Blender Foundation\Blender\blender.exe',
'--background',
'--python',
scriptFile,
rawModel,
animationFile,
outputModel

],
  stdout=PIPE, stderr=PIPE

)
stdout, stderr = process.communicate()

directory = str( os.path.dirname(rawModel)+"/finish" )
if not os.path.exists(directory):
	os.makedirs(directory)
	
print (directory)
print(rawModel, directory + rawModel[rawModel.rfind('/'):])
os.rename(rawModel, directory + rawModel[rawModel.rfind('/'):])


return[/code]

hey barak,

the python loop (the first script) is fine, but I have a feeling the second script takes a while to complete, so I think before the second (onPulse) script has completed for the first time, all loops of the first script have already passed.

One solution could be to change your setup so you call a new function something like ReportDone() at the end of you onPulse script. This should be a function or Text DAT which knows how many rows you have already processed and how many you still need to perform - when it gets the ReportDone() callback it fires a new call for the next row to animateMachine.par.Run.pulse() until all your rows are processed.

Thank you so much for going over it,
I will give it a try.

Just not sure why the for loop continue,
i should wait till process is done… no ?