Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changes to nested families

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
492 Views, 1 Reply

Changes to nested families

I'm currently trying to write a translation tool for Revit Families. The user has the possibility to load *.rfa files into my plugin and translate its types and parameters by a CSV file. The same process will be applied for its nested families automatically. Now all changes made during the process should be temporary until the user decides to save the modified families. But if I reload the families without saving them, the changes made to the nested families are still there. Is this an expected behavior of Revit? If yes, is there a possibilty to load a nested family with temporary changes, or do I have to save a nested family in a temporary directory to load the family in this way back to its parent?

 

As soon as a nested family is translated I load the family back to it's parent by calling:

Family nestedFamily;
Family parentFamily;
nestedFamily.Document.LoadFamily(parentFamily, new FamilyLoadOptions());

 

This is my implementation of IFamilyLoadOptions: 

public class FamilyLoadOptions : IFamilyLoadOptions
{
    public bool OnFamilyFound(bool familyInUse, out bool overwriteParameterValues)
    {
        overwriteParameterValues = false;
        return true;
    }

    public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
    {
        overwriteParameterValues = false;
        source = FamilySource.Family;
        return true;
    }
}

 

Thanks!

1 REPLY 1
Message 2 of 2
Anonymous
in reply to: Anonymous

I solved this problem by myself. If anyone is interested here is my solution:

Family nestedFamily;
Document parentDocument;

// Save family to a temporary directory to avoid
// saving it automatically to its parent family 
// by Revit when calling LoadFamily()
string pathToFamily = $"Path.GetTempPath()\\{nestedFamily.Name}.rfa";
nestedFamily.SaveAs(pathToFamily);

// Load family back to its parent
nestedFamily = nestedFamily.Document.LoadFamily(parentDocument, new FamilyLoadOptions());

// Remove temporary file since Revit closes the document
// after calling LoadFamily()
File.Delete(pathToFamily);

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report