Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
For some reason Revit API does not allow to close an ActiveUIDocument, and I know is possible to close using press F4 or PostCommand.Close.
I want to share a different approach using UIFramework reference.
Here is the extension for the UIApplication to enable CloseAllUIDocument and CloseActiveUIDocument.
Basically the code close UI document window and use the event DialogBoxShowing to force to save or not the document if the save popup happens.
Here is a simple Command to close the ActiveUIDocument.
[Transaction(TransactionMode.Manual)]
public class CommandCloseActiveUIDocument : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;
uiapp.CloseActiveUIDocument();
return Result.Succeeded;
}
}
To use the extension your project need to have the UIFramework reference, you can add the reference using the packages below.
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="$(RevitVersion).*" IncludeAssets="build; compile" PrivateAssets="All" />
or
<PackageReference Include="Nice3point.Revit.Api.UIFramework" Version="$(RevitVersion).*"/>
See yaa!
Solved! Go to Solution.