Animation using CanUpdatePeriodically

I am trying to create a simple animation of a sphere moving along a curve. I read here that this can be done using the CanUpdatePeriodically attribute. I am not sure how I should use it, however, so I would appreciate any help for a direction. Here is my initial attempt. It only runs once, so I suppose it needs more than that. Many thanks for your help.

[CanUpdatePeriodically(true)]
public static Sphere MoveAlongCurve(Curve curve, double speed)
{
    double t = 0.0;
    t += speed;
    if(t > 1.0)
    {
        t = 1.0;
    }
    Point p = curve.PointAtParameter(t);
    Sphere sphere = Sphere.ByCenterPointRadius(p, 1.0);
    p.Dispose();
    return sphere;
}

I tested this example here:

which has a method with CanUpdatePeriodically attribute, but similarly it does not seem to be updated, and only runs once. If I run it from DynamoSandbox (outside Revit), the method is completed immediately, but if run from Revit, the methods keeps running, but never visits the method twice.

You could try exporting a view as an image. If your script loops over say 100 different points moving the sphere to a different point each time then export the view after each movement using the ExportAsImage node. Then stitch the 100 images together.

May not be the intended approach, but here is a Dynamo way.
amimateSphere

animateSphere.dyn (5.9 KB)

The Web Request node activates the Periodic run option

//Seconds to Parameter
msc = DSCore.DateTime.Components(dtm)["second"];
prm = msc>30?(60-msc)/30:msc/30;

//Curve
crv = NurbsCurve.ByPoints(Point.ByCoordinates
([0,10,-10,5],[0,10,5,-5],[0,10,5,0]));

//Sphere
sph = Sphere.ByCenterPointRadius(crv.PointAtParameter(prm),2);
4 Likes

Thank you george, but I would like to have a live animation system in Dynamo rather than having to output image files.

Thanks a lot Vikram, this may be what I am looking for. As long as I can have a live animation system in Dynamo, I am happy. Just wondering if there is any way to perform a faster iteration (in milliseconds?).

1 Like

Just figured out that I can change “second” to “millisecond” to get the millisecond value.

1 Like