Skip to content

Instantly share code, notes, and snippets.

@imAliAsad
Last active February 8, 2024 15:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imAliAsad/198a6cac035f9474456390d0aba10a9c to your computer and use it in GitHub Desktop.
Save imAliAsad/198a6cac035f9474456390d0aba10a9c to your computer and use it in GitHub Desktop.
Read and export all parameter data of a family

Revit API C# Code Snippet

The code snippet help you export family parameter data in a nice manner

Installation

Clone project or copy and paste from .cs files.

Usage

Works in conjuntion with Revit. Developed with Visual Studio using the Revit API.

License

This sample is licensed under the terms of the MIT License.

Copyright (c) 2018 Ali Asad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

public class FParameterData
{
public string Family { get; set; }
public string BuiltinParameter { get; set; }
public string ParameterType { get; set; }
public string ParameterName { get; set; }
public string ParameterValue { get; set; }
public string ParameterGroup { get; set; }
public string BuiltinGroup { get; set; }
public override string ToString()
{
return $"{BuiltinParameter, 25}, {ParameterType, 25}, {ParameterName, 25}, {BuiltinGroup, 25}, {ParameterGroup,25}";
}
public static FParameterData GetParameterData(FamilyParameter familyparam, Document doc)
{
FParameterData parameterdata = new FParameterData
{
Family = doc.Title.ToString().Replace(".rfa", ""),
ParameterName = familyparam.Definition.Name,
BuiltinParameter = ((InternalDefinition)familyparam.Definition).BuiltInParameter.ToString(),
ParameterGroup = LabelUtils.GetLabelFor(familyparam.Definition.ParameterGroup),
BuiltinGroup = familyparam.Definition.ParameterGroup.ToString(),
ParameterType = familyparam.Definition.ParameterType.ToString(),
};
return parameterdata;
}
}
/// Export Family Properties in a list
private void ExportFamilyParameterInfo(Application app)
{
/// Open Revit Family File in a separate document
var doc = app.OpenDocumentFile(FamilyPath);
/// Get the familyManager instance from the open document
var familyManager = doc.FamilyManager;
int totalParams = familyManager.Parameters.Size;
List<FParameterData> ParametersData = new List<FParameterData>();
foreach (FamilyParameter familyParameter in familyManager.Parameters)
{
/// Add Parameter Data into a list
ParametersData.Add(FParameterData.GetParameterData(familyParameter, doc));
}
Debug.WriteLine($"\n\n{"BuiltInParameter", 25}, {"Parameter Type", 25}, {"Parameter Name", 25}, {"BuiltInGroup", 25}, {"Group Name", 25}");
Debug.WriteLine("====================================================================================================================================");
/// Display the data
ParametersData.ForEach((para) =>
{
Debug.WriteLine(para);
});
}
@imAliAsad
Copy link
Author

imAliAsad commented Jan 30, 2018

Here's the output:


         BuiltInParameter,            Parameter Type,            Parameter Name,              BuiltInGroup,                Group Name
====================================================================================================================================
                  INVALID,                     Length,               Pump Length,               PG_GEOMETRY,                Dimensions
                  INVALID,                   PipeSize,  Discharge Nominal Radius,               PG_GEOMETRY,                Dimensions
                  INVALID,                     Length,             Pump Radius 2,                   INVALID,                     Other
                  INVALID,                     Length,               Moto Length,               PG_GEOMETRY,                Dimensions
                  INVALID,                   PipeSize,    Suction Outside Radius,               PG_GEOMETRY,                Dimensions
                DOOR_COST,                   Currency,                      Cost,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                   PipeSize,  Suction Outside Diameter,               PG_GEOMETRY,                Dimensions
  ALL_MODEL_TYPE_COMMENTS,                       Text,             Type Comments,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                     Number,                       RPM,            PG_AELECTRICAL,                Electrical
                  INVALID,                   PipeSize,  Suction Nominal Diameter,               PG_GEOMETRY,                Dimensions
                  INVALID,                     Length,     Suction Flange Radius,                   INVALID,                     Other
                  INVALID,                   PipeSize, Discharge Nominal Diameter,               PG_GEOMETRY,                Dimensions
                  INVALID,        ElectricalPotential,                   Voltage,            PG_AELECTRICAL,                Electrical
                  INVALID,                     Length,   Suction Flange Diameter,                   INVALID,                     Other
                  INVALID,                     Length,            Suction Length,               PG_GEOMETRY,                Dimensions
                  INVALID,                     Length,           Pump Diameter 2,               PG_GEOMETRY,                Dimensions
                  INVALID,                     Length,          Discharge Length,               PG_GEOMETRY,                Dimensions
                  INVALID,              NumberOfPoles,           Number of Poles,            PG_AELECTRICAL,                Electrical
                  INVALID,                     Length,             Symbol Radius,                   INVALID,                     Other
            KEYNOTE_PARAM,                       Text,                   Keynote,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                     Length,             Pump Radius 1,                   INVALID,                     Other
                  INVALID,                   PipeSize,  Discharge Outside Radius,               PG_GEOMETRY,                Dimensions
                  INVALID,    ElectricalApparentPower,             Apparent Load,       PG_ELECTRICAL_LOADS,        Electrical - Loads
                  INVALID,                     Length,               Base Length,               PG_GEOMETRY,                Dimensions
          ALL_MODEL_MODEL,                       Text,                     Model,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                   Material,             Pump Material,              PG_MATERIALS,    Materials and Finishes
                  INVALID,                   PipeSize, Discharge Outside Diameter,               PG_GEOMETRY,                Dimensions
                  INVALID,                     Length,           Pump Diameter 1,               PG_GEOMETRY,                Dimensions
     ALL_MODEL_TYPE_IMAGE,                      Image,                Type Image,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                     Length,                   Length1,                   INVALID,                     Other
                  INVALID,                     Length,           Axletree Height,               PG_GEOMETRY,                Dimensions
    ALL_MODEL_DESCRIPTION,                       Text,               Description,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                     Length,   Discharge Flange Radius,                   INVALID,                     Other
   ALL_MODEL_MANUFACTURER,                       Text,              Manufacturer,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                   PipeSize,    Suction Nominal Radius,               PG_GEOMETRY,                Dimensions
                  INVALID,                     Length,                Base Width,               PG_GEOMETRY,                Dimensions
                  INVALID,         LoadClassification,       Load Classification,            PG_AELECTRICAL,                Electrical
           UNIFORMAT_CODE,                       Text,             Assembly Code,          PG_IDENTITY_DATA,             Identity Data
                  INVALID,                     Length, Discharge Flange Diameter,                   INVALID,                     Other
            ALL_MODEL_URL,                        URL,                       URL,          PG_IDENTITY_DATA,             Identity Data

@xgwdy06
Copy link

xgwdy06 commented Apr 15, 2022

don't forget FmilyType!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment