Opne New family file via API

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I am currently trying to automatically open a family file from local folder (here is my code):
public void OpenFamily(ExternalCommandData commandData)
{
UIApplication uiapp = commandData.Application;
bool hasOpenedFile = this.HasOpenedFile(uiapp);
string path = "";
if (hasOpenedFile)
{
System.Windows.MessageBox.Show("Please close the current project before importing a family!");
}
else
{
string fileImportPath = "file path here"
UIDocument doc = uiapp.OpenAndActivateDocument(fileImportPath);
}
}
private bool HasOpenedFile(UIApplication uiapp)
{
if (uiapp.ActiveUIDocument != null)
{
return true;
}
return false;
}
If I open a Revit and try to open the file, everything works fine. The problem occurs if before that I had another family/project opened and after closing it I try to open the current family (actually there is no longer an active document).
The exception thrown is here OpenAndActivateDocument(fileImportPath) with message : "An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll
Additional information: BuildWindowCore failed to return the hosted child window handle.
"
Any ideas what may cause the problem and how can I fix it?
Thanks!