Skip to content

Instantly share code, notes, and snippets.

@johnpierson
Created November 20, 2018 14:08
Show Gist options
  • Save johnpierson/7cf16606b8e61cf26786c20e662122e6 to your computer and use it in GitHub Desktop.
Save johnpierson/7cf16606b8e61cf26786c20e662122e6 to your computer and use it in GitHub Desktop.
Example for background open of revit docs.
using Autodesk.DesignScript.Runtime;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using RevitServices.Persistence;
namespace ZeroTouchNode.Revit.Application
{
/// <summary>
/// Wrapper class for application level nodes.
/// </summary>
public class Applications
{
private Applications()
{ }
/// <summary>
/// This node will open the given file in the background.
/// </summary>
/// <param name="filePath">The file to obtain document from.</param>
/// <param name="audit">Choose whether or not to audit the file upon opening. (Will run slower with this)</param>
/// <param name="detachFromCentral">Choose whether or not to detach from central upon opening. Only for RVT files. </param>
/// <returns name="document">The document.</returns>
/// <search>
/// Application.OpenDocumentFile, rhythm
/// </search>
public static Autodesk.Revit.DB.Document OpenDocumentFile(string filePath, bool audit = false, bool detachFromCentral = false)
{
var uiapp = DocumentManager.Instance.CurrentUIApplication;
var app = uiapp.Application;
//declare open options for user to pick to audit or not
OpenOptions openOpts = new OpenOptions();
openOpts.Audit = audit;
if (detachFromCentral == false)
{
openOpts.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach;
}
else
{
openOpts.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets;
}
//convert string to model path for open
ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(filePath);
return app.OpenDocumentFile(modelPath, openOpts);
}
}
}
@sabeelcoder
Copy link

hello john pierson, can u please suggest me how to install this script in revit for usage.

@ricardyn
Copy link

Thank you for share John

@johnpierson
Copy link
Author

@ricardyn For sure! I hope it helps out.

@ricardyn
Copy link

hello john pierson, can u please suggest me how to install this script in revit for usage.

@sabeelcoder this code was made to be implemented on ZeroTouch Node. The link below is one reference of how to do this.

https://developer.dynamobim.org/03-Development-Options/3-0-developing-for-dynamo.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment