Link Cluster with relative Path

Hi,
is there some way to link a .ghcluster file with a relative filepath?

-Stefan

It seems that gh sometime ā€œsearchā€ for the cluster on the same folder of current gh file… unclear to me…

This small c# script pick the first-found cluster on the same group and replace its path with the input string filename.
Cluster_path
Cluster_path.gh (7.1 KB)

You can edit this to cover similar but different situations…
Hope it helps!

Code:

using System.IO;

private void RunScript(string Cluster_File_Name, ref object Full_path)
  {
    bool searching = true;

    string current_folder = Path.GetDirectoryName(this.GrasshopperDocument.FilePath) + @"\";
    full_path = current_folder + Cluster_File_Name + ".ghcluster";
    Full_path = full_path;

    GH_Document ghdoc = this.GrasshopperDocument;
    for (int i = 0; i < ghdoc.ObjectCount; i++){
      IGH_DocumentObject obj = ghdoc.Objects[i];
      string type = obj.Attributes.DocObject.ToString();
      if(searching && type.Equals("Grasshopper.Kernel.Special.GH_Group")){
        Grasshopper.Kernel.Special.GH_Group groupp = (Grasshopper.Kernel.Special.GH_Group) obj;
        List<System.Guid> guids = groupp.ObjectIDs;
        foreach(System.Guid guid in guids){
          IGH_DocumentObject obj2 = this.GrasshopperDocument.FindObject(guid, true);
          string type2 = obj2.Attributes.DocObject.ToString();
          if(type2.Equals("Grasshopper.Kernel.Special.GH_Cluster")){
            cluster = (Grasshopper.Kernel.Special.GH_Cluster) obj2;
            this.GrasshopperDocument.ScheduleSolution(5, ReplaceCluster);
            searching = false;
          }
          if(!searching) break;
        }
      }
      if(!searching) break;
    }
  }

  // <Custom additional code> 
  public Grasshopper.Kernel.Special.GH_Cluster cluster;
  public string full_path;
  private void ReplaceCluster(GH_Document doc){
    cluster.CreateFromFilePath(full_path);
  }
5 Likes

Thats great, thanks a lot

Hi, could you tell me how to edit the link, if I want to have all my clusters in the same folder, for example, on desktop in C:\ drive, so I can use it in different .gh files. Thanks.