Auto-Assign Grasshopper Template File Path

I’m updating our Rhino/Gh deployment actions and login script. Although Gh now allows a template location to be set in Preferences, I cannot see any settings files or registry keys that store this information outside Rhino/Gh, meaning that I can’t auto-fill the Template File path field for other users.

Do you have any thoughts as to how this could be accomplished? Thank you for your time.

at nbbj we use a custom script that copies a centrally-stored template file to the user’s GH folder, and then modifies the author information of that template to match the current user. The user need only run the script (added to the user’s toolbar) once, and the template is set from then on.

Pardon the egregious xml shunting. I’m sure I’m not doing that the smartest way…

private void RunScript()
  {
    if(true){
      string MasterTemplate = "TEMPLATE FILE LOCATION";
      string settingsFolder = Grasshopper.Folders.SettingsFolder;
      string personalTemplate = settingsFolder + "Document Template.gh";
      System.IO.File.Delete(personalTemplate);
      System.IO.File.Copy(MasterTemplate, personalTemplate);
      changeAuthorData(personalTemplate, Grasshopper.CentralSettings.AuthorName, Grasshopper.CentralSettings.AuthorEMail, Grasshopper.CentralSettings.AuthorCompany);
      Grasshopper.CentralSettings.TemplateFile = personalTemplate;
    }
  }

  // <Custom additional code> 

 private void changeAuthorData(string x, string name, string email, string company){
    bool ovrride = true;
    GH_Archive archive = new GH_Archive();
    archive.ReadFromFile(x);
    GH_Chunk rootNode = archive.GetRootNode;

    GH_Chunk defChunk = rootNode.FindChunk("Definition") as GH_Chunk;
    GH_Chunk authChunk = defChunk.FindChunk("Author") as GH_Chunk;
    if(authChunk == null){
      defChunk.CreateChunk("Author");
    }
    authChunk = defChunk.FindChunk("Author") as GH_Chunk;

    if(authChunk.FindItem("Name") == null){

      authChunk.SetString("Name", name);
    } else if(ovrride){
      authChunk.RemoveItem("Name");
      authChunk.SetString("Name", name);
    }
    if(authChunk.FindItem("Company") == null){

      authChunk.SetString("Company", company);
    } else if(ovrride){
      authChunk.RemoveItem("Company");
      authChunk.SetString("Company", company);
    }
    if(authChunk.FindItem("EMail") == null){

      authChunk.SetString("EMail", email);
    } else if(ovrride){
      authChunk.RemoveItem("EMail");
      authChunk.SetString("EMail", email);
    }

    archive.WriteToFile(x, true, true);



  }


  public string objNickName(GH_Chunk chunk){
    GH_Chunk container = chunk.FindChunk("Container") as GH_Chunk;
    GH_IO.Types.GH_Item nicknameItem = container.FindItem("NickName");
    return nicknameItem._string;
  }

  public string objPanelContents(GH_Chunk chunk){
    GH_Chunk container = chunk.FindChunk("Container") as GH_Chunk;
    GH_IO.Types.GH_Item nicknameItem = container.FindItem("UserText");
    return nicknameItem._string;
  }

  public byte[] FileToByteArray(string fileName)
  {
    byte[] buff = null;
    FileStream fs = new FileStream(fileName,
      FileMode.Open,
      FileAccess.Read);
    BinaryReader br = new BinaryReader(fs);
    long numBytes = new FileInfo(fileName).Length;
    buff = br.ReadBytes((int) numBytes);
    return buff;
  }

Beautiful! Thanks Andrew I’ll give it a whirl.