Application: NewHostedSweep
Revit Platform: Architecture
Revit Version: 2011.0
First Released For: 2009.0
Programming Language: C#
Skill Level: High
Category: Elements
Type: ExternalCommand

Subject: Create hosted sweep (Fascia, Gutter, and SlabEdge).
Summary: 
This sample will demonstrate how to create hosted sweep (includes Fascia, Gutter and SlabEdge), and how to modify their properties.

Classes: 
Autodesk.Revit.UI.IExternalCommand 
Autodesk.Revit.DB.Document
Autodesk.Revit.Creation.Document
Autodesk.Revit.DB.HostedSweep
Autodesk.Revit.DB.HostedSweepType
Autodesk.Revit.DB.SlabEdge
Autodesk.Revit.DB.SlabEdgeType
Autodesk.Revit.DB.Architecture.Fascia
Autodesk.Revit.DB.Architecture.Gutter
Autodesk.Revit.DB.Architecture.FasciaType
Autodesk.Revit.DB.Architecture.GutterType
Autodesk.Revit.DB.Solid
Autodesk.Revit.DB.Edge
Autodesk.Revit.DB.Reference
Autodesk.Revit.DB.Transform

Project Files: 
Command.cs
This is the entrance of this sample. It implements IExternalCommand Execute method.

HostedSweepCreator.cs
This is an abstract class and is the base class of FasciaCreator, GutterCreator, and SlabEdgeCreator.

FasciaCreator.cs
This class inherits base class HostedSweepCreator, and it is intent to create Fascia.

GutterCreator.cs
This class inherits base class HostedSweepCreator, and it is intent to create Gutter.

SlabEdgeCreator.cs
This class inherits base class HostedSweepCreator, and it is intent to create SlabEdge.

CreationMgr.cs
This is the manager of all hosted sweep creators, it contains all the creators and each creator can be used to create corresponding hosted sweep. Its "Execute” method will show the main dialog for user to create hosted sweeps.

CreationData.cs
This class contains the data for hosted sweep creation.

ModificationData.cs
This class contains the data for hosted sweep modification.

EdgeFetchForm.cs
This form is intent to fetch edges for hosted sweep creation or modification. It contains a picture box for geometry preview and a tree view to list all the edges which hosted sweep can be created on.

HostedSweepModifyForm.cs
This form contains a property grid control to modify the property of hosted sweep.

MainForm.cs
This is the main form. It is the entry to create a new hosted sweep or to modify a created hosted sweep.

ElementGeometry.cs
This class is intent to display element's wire-frame with C# GDI. It contains a solid and a bounding box of an element. It also contains transformation (translation, rotation and scale) to transform the geometry edges.

TrackBall.cs
This class is intent to facilitate the geometry transformations. It can produce rotation and scale transformations.

Description: 
This sample let user create hosted sweep and modify the created hosted sweep. 
Its Implementation lists as below:
Ø	Types can be gotten via Document properties FasciaTypes, GutterTypes, and SlabEdgeTypes. These types can be used to create Fascia, Gutter, and SlabEdge.
Ø	Fascia will be created with NewFascia (FasciaType, ReferenceArray), Gutter with NewGutter (GutterType, ReferenceArray) and SlabEdge with NewSlabEdge (SlabEdgeType, ReferenceArray). The first parameter can be null (the default type will be used) or the types from Document and the second parameter will be the edges’ references of a roof or a floor.
Ø	Segments can be added via method AddSegment (Reference) of each subclass of HostedSweep. 
Ø	Segments can be removed via method RemoveSegment (Reference) of HostedSweep.
Ø	Angle, HorizontalOffset and VerticalOffset are get/set properties of HostedSweep, and their value can be get and set easily. 
Ø	Flip states in horizontal or vertical direction of HostedSweep can be changed via method HorizontalFlip (), and VerticalFlip (). Properties of HorizontalFlipped and VerticalFlipped can query the flip states in horizontal or vertical direction.
Ø	Transaction will be used in each operation (eg. creating HostedSweep or changing HostedSweep properties) in order to see the result immediately in Revit after each operation. Methods of Document’s BeginTransaction (), EndTransaction () and AbortTransaction () will be used to do transaction operation.
Ø	The edges are filtered via method AddSegment (). If AddSegment () throws exception, then this edge will be discarded otherwise this edge will be treated as an eligible edge.

Limitations:
In order to filter out the edges which hosted sweep can be created on, this sample uses below methods which may not be supported in future version:
Fascia fascia = NewFascia (null, new ReferenceArray ());
Gutter gutter = NewGutter (null, new ReferenceArray ());
SlabEdge slabEdge = NewSlabEdge (null, new ReferenceArray ()).

Instructions: 
1.	Open or new a Revit project and make sure some Roofs or Floors are placed. A sample project file NewHostedSweep.rvt is available in the sample’s folder.
2.	Run this Command, the main dialog will be presented.
3.	In the main dialog, select a hosted sweep type in the combo-box list and click the button Create. A dialog will be presented for the user to fetch edges and select a type in the combo-box list for the hosted sweep creation. After fetching some edges and selecting a type, click OK button will create a hosted sweep, otherwise Cancel button will cancel this creation operation.
Edge fetching operation details:
Ø	If the user mouse-over an edge where a hosted sweep can be created, the edge will be highlighted in yellow.
Ø	If the user clicks on the highlighted edge, the edge will be selected with red color or click again to un-select. 
Ø	Edge selection from preview box will be reflected in the edge list and vice versa. 
Ø	The geometry displayed in the picture box can be rotated by holding down the left mouse button and turning, or zoom by holding down the right button to move. 
Ø	Pressing arrow keys will also rotate the geometry round X-axis or Y-axis.
4.	To modify, select a hosted sweep type in the combo-box list and select a created hosted sweep in the list box from the main dialog, then click the button Modify to popup the form to modify the properties of the selected sweep. In the modification form, user can change the value in the property grid and the changes will reflect in Revit immediately.
5.	User can create more than one hosted sweep, and each created hosted sweep will be listed in the list box based on category and grouped by their type. After user click OK button in the main form, this command will exit.