On 17/07/2018 at 02:07, xxxxxxxx wrote:
Hi CodySorgenfry.
Sorry for the delay, first of all, I'm glad you found a workaround about it. But I would like to introduce you two more options.
The first one, probably the cleanest one is to add a custom array with the previous data to mograph generator itself. It's better than using a global variable since, you can have multiple cloners using the same python effector, while the global variable will be global for each python effector.
Here an example code.
import c4d
from c4d.modules import mograph as mo
#Welcome to the world of Python
def main() :
MY_ARR_ID = 123456 # have a unique ID from Plugin Cafe
md = mo.GeGetMoData(op)
if md is None: return False
# A proper DescID is needed for AddArray()
# Especially set the correct data type here!
did = c4d.DescID(c4d.DescLevel(MY_ARR_ID, c4d.DTYPE_MATRIX, 0))
myArr = md.GetArray(MY_ARR_ID)
if myArr is None: # check, if the array has already been added earlier on
idxArr = md.AddArray(did, "my array", 0)
if idxArr == c4d.NOTOK:
print "Error" # handle error here
return False
# Finally fill the array with the current matrice
marr = md.GetArray(c4d.MODATA_MATRIX)
md.SetArray(MY_ARR_ID, marr, True)
else:
previousMarr = md.GetArray(MY_ARR_ID)
marr = md.GetArray(c4d.MODATA_MATRIX)
copyMarr = marr #copy the list in order tosave data before we do any move
# Do your calculation
fall = md.GetFalloffs()
cnt = md.GetCount()
for i in reversed(xrange(0, cnt)) :
marr[i].off = marr[i].off+fall[cnt-i-1]*100.0
# Set the array with the initial state + the new matrice
md.SetArray(c4d.MODATA_MATRIX, marr, True)
md.SetArray(MY_ARR_ID, copyMarr, True)
return True
Second one using HyperFile but also MemoryFileStruct which allow you to save the file in the memory which will be way more efficient than to save/read from the disk.
And a final note all this technique only check for the previous execution, so most of the time the mograph is executed only once per frame, but is not always true.
If you have any other question please let me know.
Cheers,
Maxime.