Thanks for the reply and the code. I don't fully understand what is happening. It is still doing the odd thing of sometimes working and sometimes not.
In your file you make an object and then build the cache yourself. But what happens if I have a scene already, and am not creating the stuff?
I have this file as a simplified test: https://www.dropbox.com/s/yafk8a0syry52sc/test_0001.c4d?dl=0
And I am running this code(Make sure to select the cube before running it):
import c4d
from c4d import gui
# Welcome to the world of Python
# Script state in the menu or the command palette
# Return True or c4d.CMD_ENABLED to enable, False or 0 to disable
# Alternatively return c4d.CMD_ENABLED|c4d.CMD_VALUE to enable and check/mark
#def state():
# return True
# Main function
def build_cache(op):
"""Builds the caches for a node and returns a clone that contains the caches.
Args:
op (c4d.BaseObject): The node to build the caches for.
Returns:
c4d.BaseObject: The clone with the caches.
"""
# Nodes must not be attached to more than one document, so we
# need to clone our node first.
clone = op.GetClone(c4d.COPYFLAGS_NONE)
# Create a temporary document and execute the cache pass with
# our clone attached to the temporary document.
doc = c4d.documents.BaseDocument()
doc.InsertObject(clone)
doc.ExecutePasses(bt=None, animation=False, expressions=False,
caches=True, flags=c4d.BUILDFLAGS_NONE)
# Remove the clone and return it.
clone.Remove()
return clone
def main():
obj=op
origPoints=[x.z for x in obj.GetAllPoints()]
print origPoints
null=doc.SearchObject("mod_0")
null.SetRelPos(c4d.Vector(0,0,-1.0))
clone=build_cache(obj)
deformed=clone.GetDeformCache()
deformedPoints=[x.z for x in clone.GetAllPoints()]
print deformedPoints
deltas=[abs(x-origPoints[id]) for id, x in enumerate(deformedPoints)]
print deltas
vMap=obj.MakeVariableTag(c4d.Tvertexmap, obj.GetPointCount())
obj.InsertTag(vMap)
vMap.SetName(null.GetName())
vMap.SetAllHighlevelData(deltas)
c4d.EventAdd()
# Execute main()
if __name__=='__main__':
main()
But it is still not working. It basically prints the same sets of points which results in a zero delta. I'm sorry if I am being dense I just don't fully understand what's happening with the caches and when they happen and when I need to fire new ones etc. Long term, this script would be cycling through 12 or so controllers(ie, move 1 unit, get the deformed cache, reset back to 0, reset the cache, repeat per controller), so I want to just get an understanding of what's happening and how to set things properly.