How can I read revit family properties before loading it into Revit.exe

How can I read revit family properties before loading it into Revit.exe

Anonymous
Not applicable
630 Views
3 Replies
Message 1 of 4

How can I read revit family properties before loading it into Revit.exe

Anonymous
Not applicable

Hi, I'm a software engineer at Architecture Design Firm in Dubai. I'm developing revit add-ins for their production team. I would like to know is this possible to extract revit family properties (Type and Isntance) before loading it into the Revit 2017.exe. I did some research and wrote the following code. However, on debugging doc.IsFamilyDocument returns false.

 

public static void FamilyTransaction(Document doc, string FamilyPath, out Family family)
        {
            // Load family from file:
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Load Family");
                doc.LoadFamily(FamilyPath, out family);
                
                if (doc.IsFamilyDocument)
                {
                    FamilyManager familyManager = doc.FamilyManager;

                    // get types in family
                    string types = "Family Types: ";
                    FamilyTypeSet familyTypes = familyManager.Types;
                    FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator();
                    familyTypesItor.Reset();
                    while (familyTypesItor.MoveNext())
                    {
                        FamilyType familyType = familyTypesItor.Current as FamilyType;
                        types += "\n" + familyType.Name;
                    }
                    TaskDialog.Show("Revit", types);
                }


                tx.Commit();
            }

 I'm new into the Revit API, maybe I'm doing it wrong way. Would appreciate any help. Thank you.

0 Likes
Accepted solutions (1)
631 Views
3 Replies
Replies (3)
Message 2 of 4

aignatovich
Advisor
Advisor
Accepted solution

Hi!

 

You are loading family to your open document (family or project). You need to open document instead:

 

var famDoc = application.OpenDocumentFile(familyPath);
0 Likes
Message 3 of 4

aignatovich
Advisor
Advisor

Another option is to extract and analyze part atom (xml) from your family using Application.ExtractPartAtomFromFamilyFile method 

0 Likes
Message 4 of 4

Anonymous
Not applicable

Hello aignatovick, Thank you so much for providing the right solution of my problem. Cheers!!!!

0 Likes