C# - Custom counter node trigger by periodic

Hi,

I am new to Dynamo custom nodes development.

I have been trying to create a custom counter triggered by DateTime.Now using periodic run.

My understanding is that, since Dynamo 2.0 there is no longer the option to store persistent data into nodes, so, I created a custom Object that allows to (de)serialize into a XML file which it is store in the user temp folder to push and pull a number to later on increment it, it works in the console application.

But unfortunately when I try implement it in the custom node it does not work. I am trying to understand how Dynamo executes the node because I cant get my head around.

I have seen people implementing in similar logic but creating a sender and a receiver in two separated components instead of executing the entire task in a single node

Sample code here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.DesignScript.Runtime;
using Autodesk.DesignScript.Interfaces;
using Autodesk.DesignScript.Geometry;
using De_SerializationXML;

namespace DynamoCounter
{
public class Counter
{
internal Counter ()
{

    }
    public static int engine(DateTime time,int listLength, bool run, bool reset)
    {

        int t = time.Second%1;

        Number n1 = new Number();
        Number n2;

        n1.numb = 0;

        if (run)
        {
            
           
            n1.SerializeXML();

            n2 = Number.DeserializeXML();

            n1.numb = n2.numb+t;

            if (reset)
            {
                n1.numb = 0;
            }

        }

        return n1.numb;
    }

}

}

1 Like

Probably the nodes you want to use are cached so it won’t update. That is a guess, I am not sure if that is the case.

You can find more information here:

And a topic with a similar question here:

(direct link to a solution where the number is updated in a periodic loop)

1 Like

Found an example with proper implementation for Periodic Update in Dynamo for who ever is looking for similar implementation.

See link below:

2 Likes