Application: CurtainWallGrid
Revit Platform: All
Revit Version: 2011.0
First Released For: 2009.0
Programming Language: C#
Skill Level: Medium
Category: Elements
Type: ExternalCommand

Subject: Create Curtain Wall and manipulate its curtain grid.
Summary: 
This sample demonstrates five main features:
1.	How to create curtain wall with specific level and wall type.
2.	How to retrieve the curtain grid information of the curtain wall.
3.	How to edit the data of the curtain grid.
4.	How to retrieve the grid lines of the curtain grid.
5.	How to edit the grid lines and mullions of the curtain grid.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB.Document
Autodesk.Revit.DB.Wall
Autodesk.Revit.DB.CurtainGrid
Autodesk.Revit.DB.CurtainGridLine
Autodesk.Revit.DB.CurtainCell
Autodesk.Revit.DB.Mullion

Project Files: 
Command.cs
This file contains the class “Command” which inherits from “IExternalCommand” interface and implements the “Execute” method.

MyDocument.cs
This file contains the class “MyDocument” which manages all the data used in this sample.

WallGeometry.cs
It contains a class named “WallGeometry” which is used to manage the curtain wall data. It can create a new curtain wall and get the data of the curtain wall.

WallDrawing.cs
It contains a class named “WallDrawing” which is used to specify the baseline of the curtain wall in the canvas.

GridGeometry.cs
It contains a class named “GridGeometry” which is used to manage the curtain grid and curtain grid line information in the curtain wall. It can retrieve the data of the curtain grid and curtain grid line; it can also edit the data of them.

GridDrawing.cs
It contains a class named “GridDrawing” which is used to manage the 2D view of the curtain grid and curtain grid line in the canvas.

GridCoordinates.cs
It contains a class named “GridCoordinates” which is used to manage the transform matrixes for the curtain grid between 3D and 2D format.

MathTools.cs
It contains a class named “MathTools” which is used to manage the mathematic classes used in the transform for curtain grid.

Description: 
Functionalities:
-	Create a curtain wall with specified level and wall type.
-	Retrieve the curtain grid of the curtain wall.
-	Retrieve all the properties of the curtain grid.
-	Retrieve all the curtain grid line of the curtain grid and edit them: add new grid line, lock/unlock gridline, move grid line, add/delete segment, add all segments. (Note: it mimics part of the UI operations on segments, such as panel auto merging feature and so on, but only supports simple cases. If complex operations are made to the curtain grid, the appearance of the sample may be different from UI.)
-	Retrieve all the mullions attached and manipulate them: add mullions to the curtain grid segments and remove mullions of the curtain grid. (Note: due to limitations of Mullion class, it’s only allowed to add mullions to segments of grid line, can’t add mullions to the edges of curtain grid.)

Implementations:
-	Using Element Filter to get all views in the active document.
-	Create curtain wall via Autodesk.Revit.Creation.Document.NewWall(Curve curve, WallType wallType, Level level, double height, double offset, bool flip, bool structural)method with the applicable curtain wall type.
-	Add curtain grid line via CurtainGridLine AddGridLine(bool isConstVisUGridLine, Revit.Geometry.XYZ position,bool oneSegmentOnly)
-	Move curtain grid line via bool Move (Revit.Geometry.XYZ moveVec);
-	Add a segment via void AddSegment(Revit.Geometry.Curve^ curve);
-	Remove a segment via void RemoveSegment(Revit.Geometry.Curve^ curve);
-	Add a mullion via ElementSet AddMullions(Curve segmentCurve, MullionType mullionType,bool oneSegmentOnly);

Instructions: 
1.	Open Revit Architecture 2009 and create a new document.
2.	Run this command.
3.	A “Curtain Wall” dialog will pop up with 2 tab pages, the 1st is “Create Curtain Wall” and the other “Curtain Grid”, and it’s limited to the 1st tab page at this time.
4.	All the views and wall types available in the document are listed in the 2 drop-down lists, specify them by selecting one from the lists, the specified view and wall type will be used in the curtain wall creation.
5.	The curtain wall creation needs a baseline. Left click in the canvas at the left side to specify the baseline. Press “ESC” key to stop the baseline drawing during the baseline drawing. Click the “Clear Baseline” button to re-draw the baseline, click the “Create Curtain Wall” button to create the curtain wall with the specified baseline, view and wall type. After that, it’s allowed to switch to the “Curtain Grid” tab page.
6.	All the properties of the curtain grid are listed in the property grid at the right side.
7.	The curtain grid of the curtain wall is drawn in the canvas at the left side.
8.	All the supported curtain grid and curtain grid line operations: Add horizontal grid line, Add vertical grid line, Lock or unlock grid line, Move grid line, Add segment, Delete segment and Add all segments
9.	All the curtain grid and curtain grid line operations are limited within the boundary of the curtain grid, which means the mouse cursor must move into the boundary and the operations can work. 
10.	Continuous operation: by default, the operation will be stopped and changed to “Waiting” after one operation finished. For example: after drawing one horizontal grid line, the user should specify another operation from combo box. If the user wants to draw several horizontal grid lines at one time, he/she should press down the “Ctrl” key and hold it to act the continuous operation. For example: select “Add horizontal grid line” from the drop-down list, press “Ctrl” key down, and draw a horizontal line in the canvas, after that, the user can draw another horizontal line without specifying the operation once more. If the user wants to stop the continuous operation, he/she can release the “Ctrl” key and do the last operation, after the last operation finished, the operation will be stopped and changed to “Waiting”; he/she can also press “ESC” key to force stopping the current operation and change the operation to “Waiting”.
11.	For “Add horizontal grid line”, move the mouse into the curtain grid area and a dash horizontal grid line will be shown, it’s the to-be-added new horizontal grid line, left-click to add it to the curtain grid. It’s not allowed to add a grid line overlap another one.  Ctrl key and ESC key supported.
12.	For “Add vertical grid line”, it’s similar to “Add horizontal grid line”, just the dash line is vertical. Ctrl key and ESC key supported.
13.	For “Lock or unlock grid line”, move the mouse cursor and hover it on a grid line, the lock status of the grid line will be shown with “Locked” or “Unlocked” hints, left-click to toggle the lock status and the hints will be updated.
14.	For “Move grid line”, only allowed to move unlocked grid lines, so be sure the grid line is unlocked before moving it. Left-click on an unlocked grid line to decide which grid line to be moved, then move the mouse to decide to move the grid line to which place. Left-click again to finish moving the grid line. Ctrl key and ESC key supported.
15.	For “Add segment”, it’s only allowed to add a segment to the place where a segment has been removed previously, so it’s not available to execute the “Add segment” operation by default, as there’s no segment removed. Remove some segments first and then use this operation to add them back. Ctrl key and ESC key supported.
16.	For “Delete segment”, a segment is not allowed to be deleted twice, which means we can only delete a segment which hasn’t been deleted previously. Ctrl key and ESC key supported.
17.	Delete one segment may make other “collinear-dangling” segments to be deleted automatically. For example, in Figure 1, delete “Segment A” (the horizontal, red-highlighted segment) will make “Segment B” (the horizontal, brown one) be deleted automatically, as “Segment B” is a “collinear-dangling” segment. 

Figure 1: automatic deletion for isolated segments
18.	For “Delete segment”, it’s not allowed to delete the last segment of the curtain grid line. It also works for the “automatic deletion”. For example, in Figure 2, “Segment B” is not allowed to be deleted, as it’s the last segment of the curtain grid line; 
Figure 2: not allowed to delete the last segment

In Figure 3, delete “Segment A” will make “Segment B” “collinear-dangling” and will attempt to delete “Segment B”, but as “Segment C” has been deleted previously, “Segment B” will be the last segment of its curtain grid line, so it’s not allowed to delete “Segment A”.

Figure 3: not allowed to delete the last segment in “automatic deletion”

19.	For “Delete Segment”, remove a segment may make other “crossed-dangling” segments hidden automatically. For example, in Figure 4, delete “Segment A” will make “Segment B” “crossed-dangling”, so “Segment B” will be marked as gray, indicating it’s hidden automatically (Figure 5), just as Revit UI does(in UI, it’s invisible and will only be visible if the mouse hovers on).

Figure 4: automatic-hiding in “Delete Segment” 

Figure 5: automatic-hiding result in “Delete Segment

20.	For “Add segments of entire grid line”, it’s similar to “Add segment”, only allow applying this operation to the grid lines which have removed segments. Ctrl key and ESC key supported.
21.	For “Add mullions to all segments”, it will cover all the visible segments of the curtain grid with mullions. (Notice: due to the limitations of Mullion class, it’s not available to add mullions to the edges of the curtain grid.)
22.	For “Delete all mullions”, it will delete all the mullions in the curtain grid.
23.	Click “Exit” button in either tab page will make the dialog closed.