Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created June 19, 2020 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/2d2445f6847a5c674736f939957848fa to your computer and use it in GitHub Desktop.
Save chuongmep/2d2445f6847a5c674736f939957848fa to your computer and use it in GitHub Desktop.
/// <summary>
/// Get or Create Shared Params File
/// </summary>
/// <param name="app"></param>
/// <returns></returns>
public static DefinitionFile GetOrCreateSharedParamsFile(Autodesk.Revit.ApplicationServices.Application app)
{
string fileName = string.Empty;
try // generic
{
// Get file
fileName = app.SharedParametersFilename;
// Create file if not set yet (ie after Revit installed and no Shared params used so far)
if (string.Empty == fileName)
{
fileName = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments + "\\MyRevitSharedParams.txt";
StreamWriter stream = new StreamWriter(fileName);
stream.Close();
app.SharedParametersFilename = fileName;
}
return app.OpenSharedParameterFile();
}
catch(Exception ex)
{
MessageBox.Show("ERROR: Failed to get or create Shared Params File: " + ex.Message);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment