Reloading a Family Again

We recently listed a whole set of questions that might arise when

reloading a family
.
Here is some additional clarification by Saikat Bhattacharya on this topic that may still not be obvious:

Question: I implemented an external command that loads a family and all its symbols.
The first time I run it in a new project the family is loaded correctly.
When I rerun it a second time to reload the family, the command returns a null reference for it.
I can understand this behaviour since the family is already loaded in the project.
But shouldn’t the API throw an exception for me to know that it is already loaded?

Answer: The behaviour you describe is correct and expected.
In case you wish to find out if a family has already been loaded, you can retrieve all the loaded families and check if the one you wish to load is already present or not.
If it is already loaded, you can avoid loading it again.
We looked at an example of implementing this for

creating and inserting an extrusion family
.

Question: I also tried to use the options provided by the IFamilyLoadOptions interface.
In this case, my command still behaves exactly as before: it works perfectly when loading the family into a blank project, but returns a null reference to the family when it is already present and I try to reload it, just as if I was not using the FamilyLoadOptions at all.
Shouldn’t the fact that I return true from my implementation of the IFamilyLoadOptions OnFamilyFound method allow me to load the same family multiple times, each time replacing the previous version?

Answer: The behaviour you describe is again as expected.
The IFamilyLoadOptions interface will only allow a family to be reloaded if it has been modified.

If a given family is not loaded, the implementation of this interface is never triggered, and the OnFamilyFound method will not be called.

If the family is already loaded and unchanged, this function will not to do anything, so the IFamilyLoadOptions methods will not be called, just as you describe.

Many thanks to Saikat for the explanation!


Comments

2 responses to “Reloading a Family Again”

  1. How does Revit determine if a family is changed or not? Because we are observing the strange behaviour that the Document.LoadFamilySymbol() will work fine when an instance of a family type of this family is present in the drawing, but will silently fail when no such reference exists.
    I.e. if we delete the references to a Family prior to recreating and reloading it the call will fail, but if we leave at least one reference then the call will succeed and the existing instance will be updated.

  2. Dear Mark,
    I asked my colleagues but received no satisfactory answer as of yet.
    You are an ADN member, aren’t you? Please submit a DevHelp Online case with a reproducible case and a clear description of what you are trying to achieve and in what way it is going wrong to motivate some further exploration of this.
    Thank you!
    Cheers, Jeremy.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading