Loading Family into another Family and saving
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Before I begin let me preface:
- I understand there are other similar posts and have read through them, but they are partial to my question.
- What has helped me most was the discussions between @Anonymous & @Anonymous here: https://forums.autodesk.com/t5/revit-api-forum/saving-family-after-editing-with-familymanager/td-p/5...
- I am running this in a blank new document project
I am looking to reload a family into another family and save that parent family. Unlike the thread mentioned above, I am using the OpenDocumentFile() class instead of the EditFamily() class. I get an error stating
"saving is not allowed. File has been opened by another Revit instance"
The portion I am struggling with is:
SaveAsOptions saveoptions = new SaveAsOptions();
saveoptions.OverwriteExistingFile = true;
foreach (string parentPath in parentPaths)
{
Document familyDoc = doc.Application.OpenDocumentFile(parentPath); FilteredElementCollector fC = new FilteredElementCollector(familyDoc); ICollection<Autodesk.Revit.DB.Element> nestedFamilies = fC.OfClass(typeof(Autodesk.Revit.DB.Family)).ToElements();
foreach (Autodesk.Revit.DB.Family nestedFamily in nestedFamilies) { if (Some custom condition is met) { Document nfamilyDoc = doc.Application.OpenDocumentFile(filePath of family I want to reload); nfamilyDoc.LoadFamily(familyDoc, Custom iLoad Option); familyDoc.SaveAs(parentPath,saveoptions); nfamilyDoc.Dispose(); } }
}
I've tried running with both a manual start and commit transaction and with no transaction. Still same error. In the same thread mentioned above, there was a discussion about a similar issue but again EditFamily was used and not OpenDocumentFile. The solution in that thread was to use doc.SaveAs instead of the family doc but that does not work for my case. Sometimes it actually does Save the new updated family but it is inconsistent with errors. How do I resolve this issue to save the updated parent families? Thank you.