Announcements
Notice: Upload of PDF documents is currently unavailable across the Community due to an ongoing issue.

Adding Project Template to 'New Project' via API

Adding Project Template to 'New Project' via API

mhillis
Advocate Advocate
2,071 Views
4 Replies
Message 1 of 5

Adding Project Template to 'New Project' via API

mhillis
Advocate
Advocate

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.

0 Likes
2,072 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

Dear Michael,

 

Thank you for your query.

 

I asked the development team for you.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 5

pgerz
Participant
Participant

You can do it by editing the C:\Users\%username%\AppData\Roaming\Autodesk\Revit\Autodesk Revit 2019\Revit.ini file with standard .NET functions.

Section [DirectoriesENU] --> DefaultTemplate

Example:

 

string oriDatei = @"" + Environment.GetEnvironmentVariable("appdata") + @"\Autodesk\Revit\Autodesk Revit 2019\Revit.ini";
            string tmpDatei = @"c:\temp\11.ini";

            if (System.IO.File.Exists(oriDatei))
            {
                using (StreamReader sr = new StreamReader(oriDatei, Encoding.Unicode))
                {
                    StreamWriter sw = new StreamWriter(tmpDatei, false, Encoding.Unicode);
                    string inputLine = "";

                    while ((inputLine = sr.ReadLine()) != null)
                    {
                        if (inputLine.StartsWith("DefaultTemplate="))
                        {
                            if (inputLine.Contains("Example_SCHEMA.rte"))
                            {
                               // do nothing
                            }
                            else
                            {
                                inputLine = inputLine + @", Example_SCHEMA=C:\temp\Example_SCHEMA.rte";
                            }
                        }
                        sw.WriteLine(inputLine);
                    }
                    sw.Close();                                     
                }

                System.IO.File.Replace(tmpDatei, oriDatei, null); 
            }
Cheers
Peter
Message 4 of 5

jeremytammik
Autodesk
Autodesk

Dear Peter,

 

Thank you for the cool and simple solution. 

 

I added it to the blog to preserve it for posterity:

 

https://thebuildingcoder.typepad.com/blog/2019/02/accessing-useful-settings-in-the-ini-file.html

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5

cig_ad
Enthusiast
Enthusiast

Also, just discovered, - Autodesk.Revit.ApplicationServices.Application.CurrentUsersDataFolderPath returns the path where revit.ini is located.