Message 1 of 6
Open and close models from OnStartUp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to loop over a list of models, open each model, make an export and then close the model before going to the next one.
It all works fine if I call the OpenModels-class from and external command in Revit via Add-In-Manager, but if I call it when Revit starts up it stops after the first model is opened and export is made, not continuing to the next model.
My guess is that the UIApplication is created in IExternalApplication is different then the one in IExternalCommand?
From my ExternalApplication
public Result OnStartup(UIControlledApplication a)
{
a.ControlledApplication.ApplicationInitialized += OnApplicationInitialized;
return Result.Succeeded;
}
void OnApplicationInitialized(object sender, ApplicationInitializedEventArgs e)
{
Application app = sender as Application;
UIApplication uiApplication = new UIApplication(app);
new OpenModels().Open(uiApplication);
}In OpenModels
public class OpenModels
{
public void Open(UIApplication uiApplication)
{
var modelsToCheck = [];
foreach (var modelToCheck in modelsToCheck)
{
if (modelToCheck.IsWorkshared)
{
var modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(modelToCheck.ModelFilePath);
document = _uiApplication.OpenAndActivateDocument(modelPath, openOptions, false);
}
else
{
document = _uiApplication.OpenAndActivateDocument(modelToCheck.ModelFilePath);
}
//
//Exports are made
//
if (modelToCheck.IsWorkshared)
{
_uiApplication.ActiveUIDocument.Document.SaveAs(saveModelPath, saveAsOptions);
else
{ _uiApplication.ActiveUIDocument.Document.SaveAs(savePath, saveAsOptions);
}
}
}
}