Load Family - Overwrite the existing version

Load Family - Overwrite the existing version

arirobinson
Explorer Explorer
2,357 Views
3 Replies
Message 1 of 4

Load Family - Overwrite the existing version

arirobinson
Explorer
Explorer

I am trying to load families using the Document.LoadFamily() function.

I have set up IFamilyLoadOptions.

 

The problem I have is if a family already exists, I want to add types that don't exist but not overwrite existing types.

Currently if the family exists it adds "_XX" to the end of the family name and imports it separately.

 

I am looking for the functionality of the "Overwrite the existing version" option that is presented in the Load Family button (shown below).

Load family.PNG

 

Thank you!

0 Likes
2,358 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @arirobinson ,

Try using the below code

 familyLoadOption famloadOption = new familyLoadOption();
 doc.LoadFamily(doc, famloadOption);
 public class familyLoadOption : 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)
            {
                throw new NotImplementedException();
            }
        }

I hope this helps.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

David_Robison
Advocate
Advocate

Have you looked at LoadFamilySymbol()? It will load a single type/symbol from a family.

 

It requires you to know the name of the type you want to load, which you likely don't have.

 

I'm not sure if you can open a family with Application.OpenDocumentFile(). If that works, then work through that document to find the type. Load the ones that are missing.

 

If you can't, you could use Application.NewProjectDocument() to get a document. Then LoadFamily() on the new document to get the family loaded. Then work the the types and load the ones that are missing into your original document.

0 Likes
Message 4 of 4

theknownsilhouette
Enthusiast
Enthusiast

Hi @naveen.kumar.t 
That's insightful. below function from the interface will check if the family is shared or not.

 

public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
            {
                throw new NotImplementedException();
            }

 

But how can one make a family shared while loading? Is there any other approach where user can decide if a family needs to be shared or not?

0 Likes