Hi all,
I have a simple script that creates a Path3D and align evenly models on it, from the start point to the end point. I’m trying to add better functionality, by using the system events so if the user edits the path points, the models update their new position automatically.
I don’t fully understand why, but OnConnectionDataNotify, raises a RecursionError if I try to update the models translation values and is the only callback registered. The other callbacks update the models once the path is unselected.
def align_models_on_path(control, event):
number_of_bones = 5 # added for testing. It's the value of a spinbox in the ui in the script.
origin = FBVector3d(dist.PathKeyGet(0)[0], dist.PathKeyGet(0)[1], dist.PathKeyGet(0)[2] )
end = FBVector3d(dist.PathKeyGet(1)[0], dist.PathKeyGet(1)[1], dist.PathKeyGet(1)[2])
spacing = (end - origin) / number_of_bones
print(f"origin: {origin}, end {end}")
for bone in dist.bones:
bone.Translation = origin
origin+=spacing
def register():
# Used alone 'OnConnectionDataNotify' gives a Recursion Error if try to use the vector values on objects.
# Printing values works fine. Any other call back will update the models positions once the Path is unselected.
sys.OnConnectionDataNotify.Add(align_models_on_path)
#sys.OnConnectionStateNotify.Add(align_models_on_path)
#sys.OnConnectionNotify.Add(align_models_on_path)
app.OnFileExit.Add(unregister)
Thanks in advance for the help!