Is there a feature in Dynamo to animate a slider?

I realize Dynamo is not Grasshopper, but this feature appears to be built into Grasshopper and it’s seems incredibly useful and fun. Is there a way to do this in Dynamo? I’ve done a bit of searching, and found Dynanimator (10 years old), but couldn’t get it to work (maybe I need to try harder?) and some fairly involved examples using Python, but I’m curious if there are any recent packages that make this dead simple (a single node to animate a slider or other input node) or if there is a first party solution that I’ve just overlooked. Thanks!

Animations are best done via periodic run mode.

  1. Place a Datetime.Now node on canvas.
  2. Extract the seconds or total time.
  3. Map that to a maximum frame count (in a code block n%frameCount;)
  4. Change the run mode to periodic.
  5. Set the period to your desired execution rate - you want something significantly longer than the worst case run time for your tool.

It can be a bit difficult to wrap your head around the first time out, so give it a shot and let us know if you get stuck.

Thanks Jacob, I’ll give that a shot. Since my goal is to end up with an animation (.mp4 or .gif), I’ll need to capture a consistent bitmap of each step in the sequence. Is there a node that captures the geometry view of the canvas that I can add into my graph?

You can write a node that does an export at each run. There have been a few tools to produce that type of feature over the years, but they tend to be pet projects which are used for a one time thing for a particular task rather than a long term supported tool.

Typically I find that using a screen recording tool gives better results. My go to for that is screen2gif, but if you want videos you can leverage zoom or teams or just about any other recording tool just as well.

With screentogif I set my recording area, and have it take two frames per run. I can then remove every other frame if needed, and adjust the frame times accordingly.

2 Likes

An example with Python (with DynamoRevit)

kit_slider

import sys
import clr
import System

#reference loaded dynamo revit module
clr.AddReference('DynamoRevitDS')
import Dynamo 
clr.AddReference('DynamoCore')
from Dynamo.Graph import UpdateValueParams

#access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
engine = dynamoRevit.RevitDynamoModel.EngineController
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
model = dynamoRevit.RevitDynamoModel

# get code block node and value
nodeF = next((i for i in currentWorkspace.Nodes if i.Name == "factor"), None)
current_factor = nodeF.GetValue(0,engine).Data
# get slider node and values
nodeK = next((i for i in currentWorkspace.Nodes if i.Name == "mySlider"), None)
min = nodeK.Min
max = nodeK.Max
step = nodeK.Step

# update value of code block node
if nodeK.Value == max :
    current_factor = -1
    params = UpdateValueParams("Code", f"{current_factor};")
    nodeF.UpdateValue(params)
elif nodeK.Value == min :
    current_factor = 1
    params = UpdateValueParams("Code", f"{current_factor};")
    nodeF.UpdateValue(params)
else:
    pass
# increment value of slider
nodeK.Value += step * current_factor
3 Likes

Great example. Thank you!

2 Likes