Change the ActiveUIDocument
Question
Is there a way through the Revit API to change which document is the current ActiveUIDocument
(ExternalCommandData.Application.ActiveUIDocument
)? I want to print multiple views from multiple project files using the API but I need to be able to change the current ActiveUIDocument first.
Solution
With the Revit 2012 API there is a new method OpenAndActivateDocument
on the UIApplication
object. As the method name says it will open and activate the document that you specify with a file path. I tested this and it worked for printing multiple files.
public void Plot(ExternalCommandData commandData, string[] files)
{
UIApplication uiApplication = commandData.Application;
foreach (string file in files)
{
Document document = uiApplication.OpenAndActivateDocument(file);
//Do action on active document
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow