Retrieving certain family type parameters out of a bunch of *.rfa files

Retrieving certain family type parameters out of a bunch of *.rfa files

Anonymous
Not applicable
3,095 Views
9 Replies
Message 1 of 10

Retrieving certain family type parameters out of a bunch of *.rfa files

Anonymous
Not applicable

Hello and Happy New Year's Eve to all,

 

I'm trying to make a Revit plugin which basically is a filterable catalog of family files of lighting fixtures. You filter files using some of the parameters and when pick the one you need and load it into the project. But I have a real hard time extracting the parameters out of files. I open families as a document and iterate through every type in the family, retrieving the parameters I need. But for some reason the parameters I retrieve have null values, so all I get when launching the command in Revit is an ArgumentNullException: value cannot be null (screenshot.jpg). But these parameters have values if snoop them using Revit Lookup tool (screenshot2.jpg). Here is the code, maybe I'm missing something, I'll appreciate any insights or help you can provide.

 

 

    [Transaction(TransactionMode.Manual)]
    public class LightingFixture : IExternalCommand
    {
        Application m_rvtApp;
        Document m_rvtDoc;
        public Result Execute(ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication rvtUIApp = commandData.Application;
            UIDocument rvtUIDoc = rvtUIApp.ActiveUIDocument;
            m_rvtApp = rvtUIApp.Application;
            m_rvtDoc = rvtUIDoc.Document;


            string[] filePaths = Directory.GetFiles(@"C:\Users\Admin\Desktop\REVIT_BIM\Revit Family Types", "*.rfa");
            List<List<LightingFixtureType>> listOfTypes = new  List<List<LightingFixtureType>>();

            foreach (string path in filePaths)
            {
                Document doc = m_rvtApp.OpenDocumentFile(path);
                listOfTypes.Add(GetListOfFamilyTypes(doc));
            }

            foreach (List<LightingFixtureType> types in listOfTypes)
            {
                TaskDialog.Show("List of Family Types", types.ToString());
            }

            return Result.Succeeded;
        }


        public List<LightingFixtureType> GetListOfFamilyTypes(Document familyDoc)
        {
            if (familyDoc.IsFamilyDocument)
            {
                FamilyManager familyManager = familyDoc.FamilyManager;

                List<LightingFixtureType> list = new List<LightingFixtureType>();

//all these parameters have null values FamilyParameter familyNameParameter = familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_FAMILY_NAME); FamilyParameter nameParameter = familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME); FamilyParameter typeParameter = familyManager.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS); FamilyParameter loadParameter = familyManager.get_Parameter(BuiltInParameter.RBS_ELEC_APPARENT_LOAD); FamilyParameter colorParameter = familyManager.get_Parameter(BuiltInParameter.FBX_LIGHT_INITIAL_COLOR_TEMPERATURE); string familyName = null; string name = null; string type = null; double load = 0; double colorTemperature = 0; FamilyTypeSet familyTypes = familyManager.Types; FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator(); familyTypesItor.Reset(); while (familyTypesItor.MoveNext()) { FamilyType familyType = familyTypesItor.Current as FamilyType; familyName = familyType.AsString(familyNameParameter); name = familyType.AsString(nameParameter); type = familyType.AsString(typeParameter); load = (double)familyType.AsDouble(loadParameter); colorTemperature = (double)familyType.AsDouble(colorParameter); LightingFixtureType fixture = new LightingFixtureType(familyName, name, type, load, colorTemperature); list.Add(fixture); } return list; } return null; }

 

 

0 Likes
3,096 Views
9 Replies
Replies (9)
Message 2 of 10

jeremytammik
Autodesk
Autodesk

Happy New Year to you too!

 

I think I can spot your problem.

 

I think you need to set the current family type for each of the types you examine using the FamilyManager CurrentType property before examining its parameter values:

 

https://www.revitapidocs.com/2020/3d37cd81-48ba-4011-82bc-dbb7ae14b270.htm

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 10

Anonymous
Not applicable

Hi Jeremy!

 

I'm not sure I understand how to set "Current Type" property before examining parameter values.

 

Here I've wrote a test code for checking how different parameters are retrieved from current Family Type. Some of the parameters actually work and return data I need (ALL_MODEL_TYPE_COMMENTS and RBS_ELEC_APPARENT_LOAD), but most throw ArgumentNullException (ALL_MODEL_TYPE_NAME, ALL_MODEL_FAMILY_NAME, FBX_LIGHT_INITIAL_COLOR_TEMPERATURE). I have no idea why some parameters are read and others aren't.

 

 

        public LightingFixtureType GetListOfFamilyTypes(Document familyDoc)
        {
            if (familyDoc.IsFamilyDocument)
            {
                FamilyManager famManager = familyDoc.FamilyManager;
                FamilyType currentType = famManager.CurrentType;
                FamilyParameter param = famManager.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_NAME);

                string name = currentType.AsString(param);
                LightingFixtureType lft = new LightingFixtureType(name);
                return lft;
            }
            return null;
        }

 

 

0 Likes
Message 4 of 10

FAIR59
Advisor
Advisor

AsString only works for parameters with StorageType.String

[ Return Value

The string contained in the parameter. Returns a null reference ( Nothing in Visual Basic) if the storage type of the input argument is not string type or this parameter has no value. ]

see https://www.revitapidocs.com/2015/6cb7afb5-f59f-3d35-7dc2-2fa665a35183.htm

0 Likes
Message 5 of 10

Anonymous
Not applicable

@FAIR59 wrote:

AsString only works for parameters with StorageType.String


I am aware of it. You can see in the code above that I used string type for extracting ALL_MODEL_TYPE_NAME parameter, which stores its value as a string (see 1.png). For every parameter I've tried to use an according type, but it's still no good. Most of parameters I'm trying to get the value from return null value.

 

0 Likes
Message 6 of 10

FAIR59
Advisor
Advisor

I just checked, those parameters are instance-parameters. So they don't "exist" in the family environment.

SnoopParameters.PNG

0 Likes
Message 7 of 10

Anonymous
Not applicable

The screenshot I made (1.PNG), contains the data from FamilySymbol category. FamilyInstance has that parameter too, but in there the parameter has a null value. Actually, most of the parameters in FamilyInstance have a null value.

What I want to do is to extract data from FamilySymbol category, maybe the problem is here?

0 Likes
Message 8 of 10

Anonymous
Not applicable

It just came to me that you are 100% right. When I tried to look up parameters of my family I used to insert that family into an architectural project and when used Lookup tool: Snoop DB - FamilySymbol - (and inside that category were all the family types of the family with all parameters I need). And I didn't even suspect that what I was doing was wrong, because when I tried to snoop DB inside of a family file I couldn't find any parameters. But what I did was plainly wrong, because my code opens a family file, not a project file and tries to find parameters inside a family file using the approach I used to find parameters inside a project file.

Can you give me any advice on to how to find Family Type parameters inside a Family file using Lookup Tool? I attached an example of a files I'm working with. Only data I managed to find yet was a photometric file info with file name and angle, but not much else.

0 Likes
Message 9 of 10

FAIR59
Advisor
Advisor

the Lookup tool has the same "structure"as the API.

So, select an element, and [Snoop  Current Selection]

click [Document], click [FamilyManager]. click [Parameters]

0 Likes
Message 10 of 10

Anonymous
Not applicable

Okay, so it seems that I can't extract certain parameters from Family Type opened as Document. Majorly, it's photo metric parameters Light Luminous Flux and Light Temperature Color.

Right now I decided to use .txt files of Family Categories to retrieve the data, which is not a solution of the problem but a workaround that will do for now.

0 Likes