Application: AutoParameter
Revit Platform: All
Revit Version: 2011.0
First Released For: 2010.0
Programming Language: C#
Skill Level: Medium
Category: Parameters, Families
Type: ExternalCommand

Subject: Auto add parameters to family document.
Summary: 
This sample demonstrates how to automatically add parameters (shared or not) to family documents.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.Document
Autodesk.Revit.DB.FamilyManager
Autodesk.Revit.DB.FamilyParameter
Autodesk.Revit.DB.ExternalDefinition

Project Files: 
Command.cs
      This file contains 2 classes: AddParameterToFamily and AddParameterToFamilies. AddParameterToFamily implements the Execute method and be used to add parameters to the active family document. AddParameterToFamilies implements the Execute method and be used to add parameters to all families in the “AutoParameter_Families” folder under “My Documents” folder.
FamilyParameterAssigner.cs
      This file contains the class FamilyParameterAssigner. This class adds all the parameters to the family file.

Description: 
This sample utilizes FamilyManager class to implement the features: add parameters (shared or not) to the specified family file.
-	To add family parameters, use the AddParameter(String paramName, BuiltInParameterGroup paramGroup, ParameterType paramType, bool isInstance) method;
-	To add shared parameters, use the AddParameter(ExternalDefinition familyDefinition, BuiltInParameterGroup paramGroup, bool isInstance) method;

Instructions: 
1.	In order to auto-add parameters to family files, user should prepare the parameter files: family parameter file and shared parameter file.
The family parameter file should be named as “familyParameter.txt” and put in the same folder as the sample DLL. 
The shared parameter file should be named as “sharedParameter.txt” and put in the same folder as the sample DLL.
Here is a sample for how to organize the files:

RootFolder:
│  AutoParameter.dll	   (this is the sample DLL)
    │      SharedParameter.txt
    │       FamilyParameter.txt

2.	The format for the parameter files: for shared parameter file, it follows the format of Revit shared parameter file; for family parameter file, it has a similar format: Every line starts with “#” or “*” will be treated as the comment line and will be skipped, every parameter line should follow this format: “ParamName	ParamGroup	ParamType	IsInstance”, and be separated by spaces.
Here is a template for the family parameter file: 
# This is a Revit family parameter file.
# allows to edit manually.
# make sure the "ParamGroup" and "ParamType" values are correct (with or without #"BuiltInParameterGroup." and "ParameterType." doesn't affect the features).

*ParamName	ParamGroup	ParamType	IsInstance
FamilyParam1	PG_TEXT		Text	false
FamilyParam2	BuiltInParameterGroup.PG_TEXT	ParameterType.Text	true

3.	In order to add parameters to a family file, Launch Revit, open the family file, and click the external command “AddParameterToFamily”, all parameters (shared or not) will be added to the active family document;
4.	In order to add parameters to multiple family files, need to follow the steps:
a)	Create a folder “AutoParameter_Families” in “My Documents” folder;
b)	Put all the family files into that new folder, make sure all files are write-able (if some files are read-only, the parameters can’t be added in.);
c)	Launch Revit, create a project, click the external command “AddParameterToFamilies”, all the parameters will be added to all the family files in the “AutoParameter_Families” folder