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.
Asked
Active
Viewed 2,947 times
1

skeletank
- 2,880
- 5
- 43
- 75
1 Answers
1
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
}
}

skeletank
- 2,880
- 5
- 43
- 75
-
Sorry to bring up an old post. Does it work also if the file is already open? Or have you found a way to switch the active document among documents that are already open in the application? – Andrea Tassera Jul 01 '20 at 00:38
-
@AndreaTassera I believe that you can switch back and forth using this even if they are already open though I haven't tested it. According to the post below this is possible (although note that this gets trickier with BIM 360 and Revit Server). https://forums.autodesk.com/t5/revit-api-forum/change-active-document/td-p/7787792 – skeletank Jul 01 '20 at 14:16
-
Very interesting! Thanks for sharing! – Andrea Tassera Jul 02 '20 at 21:29
-
I tried to use OpenAndActivateDocument(file) on files that are already open and it actually activates them. It must have some logic behind saying "if the file is already open, then just activate". Quite weird as you don't have a method for just activating... – Andrea Tassera Jul 02 '20 at 23:34