Search code examples
c#revit-api

How can I read Revit Family Properties using Revit API before importing it into the Revit 2017.exe


I'm a software developer working at Architecture Design Firm. Here we are developing custom plugins for Revit 2017 using Revit API. I'd like to know is this possible to read family type and instance properties before importing it into the Revit 2017 editor? If yes, would appreciate some initial guide.


Solution

  • By struggling through some hours, I finally came up with a solution. All I have to do was to read revit family file by using application.OpenDocumentFile(FamilyPath); method. The following code will help anyone to extract revit family types information.

        private void ExtractFamilyInfo(Application app)
        {
            //A placeholder to store types information
            string types = "Family Types: ";
    
    
            //Open Revit Family File in a separate document
            var famDoc = app.OpenDocumentFile(FamilyPath);
    
            //Get the familyManager instance from the open document
            var familyManager = famDoc.FamilyManager;
    
            //Get the reference of revit family types
            FamilyTypeSet familyTypes = familyManager.Types;
            //Set iteration to forward
            FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator();
            familyTypesItor.Reset();
    
            //Loop through all family types
            while (familyTypesItor.MoveNext())
            {
                FamilyType familyType = familyTypesItor.Current as FamilyType;
                //read all family type names
                types += "\n" + familyType.Name;
            }
    
            //Display text on the UI
            DefaultControl.Instance.PropertyText.Text = types.ToString();
    
        }