Application: ValidateParameters
Revit Platform: All
Revit Version: 2011.0
First Released For: 2010.0
Programming Language: C#
Skill Level: Beginning
Category: Families
Type: ExternalCommand and ExternalApplication

Subject: Validate Parameters
Summary: This sample will demonstrate if every type has valid values for certain parameters.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.UI.IExternalApplication
Autodesk.Revit.UI.UIDocument 
Autodesk.Revit.DB.Element
Autodesk.Revit.DB.FamilyManager
Autodesk.Revit.DB.ParameterSet

Project Files: 
Command.cs
This file contains a class Command which implements IExternalCommmand interface. The function of the class is to call API FamilyType.HasValue and methods FamilyType.AsDouble (Parameter), AsElementId(Parameter) to validate parameters.
Application.cs
This file contains a class Application which implements IExternalApplcation interface. The OnStartUp method will register DocumentSaving, DocumentSavingAs events when Revit starts. The pre-event handler will validate parameters when document is saving; the post-event handler will validate parameters when document is saving as another file. The OnShutdown method will get rid of the two events when Revit shuts down.
MessageForm.cs
This file contains a windows form, which shows the parameters validation result to user.

Description: 
This sample only can be used in family. The sample implements IExternalApplication interface and subscribes DocumentSaving, DocumentSavingAs, events in OnStartUp method; the registered event handlers will validate parameters when events are raised. It can also be launched by external command. If there is any parameter which cannot pass the validation, one warning message will show and list the invalid type and parameter. There is one log file that stores all information displayed in the form.
-	To register events to the application, use the event handler DocumentSaving and DocumentSavingAs of Controlled Application.
-	To get the family types, use the property FamilyManager.Types.
-	To get the family parameters, use the property FamilyManager.Parameters.
-	To check whether the type has value for certain parameter, use the method FamilyType.HasValue (FamilyParameter).
-	To check the Parameter’s storage type, use the property Parameter.StorageType.
-	To retrieve the parameter value, use the methods FamilyType.AsDouble (Parameter), AsElementId(Parameter) etc.

Instructions: 
1.	Update your Revit.ini by following lines: 
[ExternalApplications] 
EACount      = 1 

EAClassName1=Revit.SDK.Samples.ValidateParameters.CS.Application
EAAssembly1  = <your path>\ValidateParameters.dll 
[ExternalCommands]
ECCount        = 1
ECName1= Validate Parameters
ECClassName1   = Revit.SDK.Samples.ValidateParameters.CS.Command
ECAssembly1    = <your path>\ValidateParameters.dll 
ECDescription1   = Validate every type has valid values for certain parameters.
2.	Start Revit, DocumentSaving and DocumentSavingAs events will be registered automatically.
3.	In order to use a family, user should manually open a family document.
4.	Run the extern command ValidateParameters.
5.	Raise Save event by UI menu File\Save.
6.	Raise SaveAs event by UI menu File\SaveAs.