Update All Clusters in a GH Script

When working with a large script with many clusters, is there any way to update all clusters at once, as opposed to having to comb through the script and update one-by-one?

If not, any ideas for strategies to approach this issue with?

Thanks

are they all the same?

No there will be a number of unique clusters in most cases

this throws an error message for each updated cluster, but it works:

   if (update)
    {
      for (int i = 0; i < GrasshopperDocument.ObjectCount; i++)
      {

        if (GrasshopperDocument.Objects[i] is Grasshopper.Kernel.Special.GH_Cluster)
        {
          var cluster = GrasshopperDocument.Objects[i] as Grasshopper.Kernel.Special.GH_Cluster;
          cluster.CreateFromFilePath(cluster.FilePath); // "Update" cluster
        }
      }
      GrasshopperDocument.ExpireSolution();
    }

updateClusters.gh (2.7 KB)

1 Like

Probably if you delay this logic until after the solution is done you’ll get rid of those error messages.

I’ve upgraded @TomTom’s solution with some extra features we needed.

  1. Recursive mode to update clusters inside clusters
  2. Passwords can be provided if nessesary
  3. Cluster paths can sometimes be different depending on the user. You can submit local path to clusters’ folder and the script will try to find missing references if possible.

UpdateAllClusters.gh (5.7 KB)

3 Likes