Accessing and Modifying Settings in the Ini File

Some interesting settings are stored in and can be modified by editing the Revit ini file Revit.ini.

Peter @pgerz pointed out yet another possibility in his answer to the Revit API discussion forum thread on adding a project template to 'New Project' via API:

Question: I noticed that the UI method for adding a project template to the 'New Project' dialog on the Start Window is by going to Options > File Locations and clicking the little plus symbol.

Is there any way to achieve this same effect using the API?

I would like to add templates to the dropdown.

Answer: You can do it by editing the ini file with standard .NET functions; it is located at:

In the section [DirectoriesENU], modify the setting DefaultTemplate.


  string oriFile = @""
    + Environment.GetEnvironmentVariable( "appdata" )
    + @"\Autodesk\Revit\Autodesk Revit 2019\Revit.ini";

  string tmpFile = @"c:\temp\11.ini";

  if( System.IO.File.Exists( oriFile ) )
    usingStreamReader sr = new StreamReader( 
      oriFile, Encoding.Unicode ) )
      StreamWriter sw = new StreamWriter( tmpFile, 
        falseEncoding.Unicode );

      string inputLine = "";

      while( ( inputLine = sr.ReadLine() ) != null )
        if( inputLine.StartsWith( "DefaultTemplate=" ) )
          if( inputLine.Contains( "Example_SCHEMA.rte" ) )
            // do nothing
            inputLine = inputLine
              + @", Example_SCHEMA=C:\temp\Example_SCHEMA.rte";
        sw.WriteLine( inputLine );
    System.IO.File.Replace( tmpFile, oriFile, null );

Many thanks to Peter for this solution!