Application: DoorSwing
Revit Platform: Architecture
Revit Version: 2011.0
First Released For: 2009.0
Programming Language: C#
Skill Level: Medium
Category: Rooms/Spaces
Type: ExternalCommand, ExternalApplication

Subject: Manage opening of the door and rooms relevant to the door.
Summary: 
This sample will demonstrate how to create and maintain door opening parameters, internal door parameter, From/To Room and how to schedule these parameters. Feature to customize to your country standard is also provided.
 
Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.UI.IExternalApplication
Autodesk.Revit.ApplicationServices.ControlledApplication
Autodesk.Revit.UI.RibbonPanel
Autodesk.Revit. UI.PushButton
Autodesk.Revit.DB.DocumentType.Family
Autodesk.Revit.DB.FamilyInstance
Autodesk.Revit.DB.GeometryElement
Autodesk.Revit.DB.BoundingBoxXYZ
Autodesk.Revit.DB.Options
Autodesk.Revit.DB.DefinitionFile
Autodesk.Revit.DB.Definition
Autodesk.Revit.DB.BindingMap
Autodesk.Revit.DB.ElementBinding
Autodesk.Revit.DB.InstanceBinding
Autodesk.Revit.DB.TypeBinding
Autodesk.Revit.DB.Parameter
Autodesk.Revit.DB.Events.DocumentSavingEventArgs
Autodesk.Revit.DB.Events.DocumentSavingAsEventArgs

Project Files: 
Command.cs
It contains three classes InitializeCommand, UpdateParamsCommand and UpdateGeometryCommand. All of them implement interface IExternalCommand. 

ExternalApplication.cs
This file contains one class ExternalApplication which implements interface IExternalApplication. This class will create one custom Ribbon panel contains three buttons to invoke the three external commands defined in Command.cs file. This class subscribes some application level events to update door parameters too. That can insure the doc is correct when it is about saved, saved as etc.

DoorSwingData.cs
This file contains one class DoorSwingData which prepares the needed data and updates door opening, Internal/External door and To/From Room information.

DoorFamily.cs
This file contains one class DoorFamily which maintains family name, family geometry and door opening expression information for each door family. And it also customizes the door opening expression according to each door family’s geometry and country's standard.

DoorFamilyGeometry.cs
This file contains one class DoorGeometry which is used to transform Revit geometry data to appropriate format for GDI.

DoorSharedParameters.cs
This file contains one Static class DoorSharedParameters which is used to add three shared parameters to door and named with BasalOpening, InstanceOpening and Internal Door.

InitializeForm.cs
This file contains a form class InitializeForm which consists of one DataGridView to show user all door families existent in current Revit project, and one pictureBox to show door family’s geometry. User can customize door opening expression according to each door family’s geometry and country's standard here.

DoorSwingResource.resx
A resource file which contains some strings to identify the door opening.

Description: 
For door’s opening functionality, user can invoke the external command "Customize Door Opening Expression" to add needed shared parameters and customize door opening expression according to their own country's standard and each door family’s geometry. When the door was flipped or mirrored, user can invoke the external command “Update Door Properties” to update parameters’ values. Schedule for these parameters will be done from Revit UI.

For door’s related room functionality, from Revit UI user can schedule the “To room” and “From room” information for Internal and external doors in two separate schedule tables and can change the direction of the door in schedule tables. User will then use “Update Door Geometry” command to update the geometry of the door after the direction of the door was changed in schedule tables. When the door was flipped or mirrored in view, user can invoke the external command “Update Door Properties” to update “To room” and “From room” information too.

Parameter updating process will also be invoked upon closing, save or save as of the project file.

Instructions: 
1.	Prepare your Revit project. 
Open or new a Revit project and make sure all needed rooms are placed. If your project file has any closed wall loop without a room being defined, the sample will have a dialog to ask you to confirm that you would consider doors bounding those areas as external doors.
A sample project file DoorSwing.rvt is available in the sample’s folder.

2.	Customize your door opening expression. 
Click "Customize Door Opening Expression" command (menu item or Ribbon button) to customize each door family’s opening expression based on the family’s geometry and your country’s standard. This is the first command of the sample. If the expressions which comply with your country standard are not available on the list, you can open the source code project and modify in the following 3 areas:

a.	Edit project resource file.
b.	Edit DoorSwingData static constructor in DoorSwingData.cs. Add more door opening expressions from resource file into OpeningTypes list.
c.	Edit UpdateOpeningFeatureOfOneDoor function in DoorSwingData.cs. Add more else if in “if (switchesOpeningValueFlag){…}” statement to deal with the added door opening expression.

Users who want to create a localized version of the sample can follow step 2.a above.

3.	Schedule the parameters.
Create door schedule from Revit UI. You can schedule “Opening” , “Internal Door” parameters and “Room number” of “From Room”/”To Room” or any others you need.

a.	Create Internal Door Schedule.
Revit Button: View Tab->Create Panel->Schedules Button->Schedule/Quantities;
Category: Doors; Name: Internal Door Schedule.

Add parameters which need to be scheduled.
·	Add existing parameters: Mark, Internal Door, InstanceOpening, FromRoom:Number, ToRoom:Number;
·	Add a Calculated value: Name: Opening, Select: Formula, Discipline: Common, Type: Text, Formula: InstanceOpening.
·	Move up Opening parameter before InstanceOpening parameter.

Modify the appearance of the schedule including visibility, sorting and so on.
·	Hide Internal Door and InstanceOpening column if you want: right click the “Internal Door” column, and then left click the Hide Column(s) menu; right click the “InstanceOpening” column, and then left click the Hide Column(s) menu;
·	Sort items by door’s Mark value: right click anywhere in the schedule, then left click View Properties… menu; Sorting/Grouping item in the Properties dialog box; Sort by: Mark.
·	Filter by Internal Door: Filter item in the Properties dialog; Filter by: Internal Door equals Yes.
b.	Create External Door Schedule.
Follow the same steps as creating Internal Door Schedule except the Filter setting. Filter by: Internal Door equals No.

4.	Update door parameter when flip/mirror the door
Flip/mirror any door, then click “Update Door Properties” command (menu item or Ribbon button). This command will update door parameters according to door’s geometry.

5.	Update door geometry when change the direction of the door in the schedule.
You can even change the room number of “From Room” / ”To Room” from the schedule. After that click the “Update Door Geometry” command will change the door’s geometry based on the changes you made in the schedule.