Application: MultiplanarRebar
Revit Platform: Structure
Revit Version: 2012.0
First Released For: 2012.0
Programming Language: C#
Skill Level: High
Category: Structure
Type: ExternalCommand

Subject: Create multi-planar Rebar.
Summary: 
This sample is to demo multiplanar rebar creation in API. A user scenario of multiplanar rebar is corbel ‘s reinforcement. This sample is to reinforce sloped corbel(s).

Classes: 
Autodesk.Revit.UI.IExternalCommand 
Autodesk.Revit.Creation.Document
Autodesk.Revit.DB.FamilyInstance
Autodesk.Revit.DB.Structure.Rebar
Autodesk.Revit.DB.Structure.RebarShape
Autodesk.Revit.DB.Structure.RebarShapeDefinition
Autodesk.Revit.DB.Structure.RebarShapeDefinitionBySegments
Autodesk.Revit.DB.Structure.RebarShapeMultiplanarDefinition
Autodesk.Revit.DB.Structure.StructuralType
Autodesk.Revit.DB.Parameter
Autodesk.Revit.DB.DefinitionGroup
Autodesk.Revit.DB.ExternalDefinition
Autodesk.Revit.DB.Solid

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

CorbelFrame.cs
It represents the frame of Corbel, which is consisting of a trapezoid profile and an extrusion line. Corbel can be constructed by sweeping a trapezoid profile along the extrusion line.

CorbelReinforcementOptions.cs
This class represents the reinforcement options of corbel. options include bar type and bar counts which are collected from user via UI input.

CorbelReinforcementOptionsForm.cs
This class is a form which collects user’s options for corbel rebars creation.

GeometryUtil.cs
This class is to parse the geometry information of given Corbel FamilyInstance, and finally construct a CorbelFrame according to the parsed geometry information.

SharedParameterUtil.cs
This is a utility class used to create shared parameter in Revit Document. It simplifies the process of shared parameters creation.

Description: 
1.	This sample will focus on the corbel’s reinforcement, the reinforcement of corbel’s host (wall, column) is beyond this scope, except for the straight bar which is necessary to anchor the stirrup bars of corbel. 
2.	The corbel’s rebar consists of horizontal straight bars, stirrup bars and a multi-planar bar. There includes two vertical straight bars in corbel host to anchor corbel stirrup bars. 
3.	This sample will provide a simple UI to collect the rebar creation options, like bar type and bar counts.

Detail Design:
1.	The first step is corbel’s geometry analysis:
a)	Corbel is family instance, so its geometry can be got via Element.Geometry(). This sample needs to filter out the trapezoid face of corbel, so we have to get the Solid for deeper parsing.
b)	Iterating all the faces of Solid to filter out the trapezoid face, this face is rather critical for the whole sample, the multi-planar rebar shape and all rebars placements rely on this trapezoid face. 
2.	Multi-planar rebar shape creation:
The rebar shape consists of two straight segments; therefore, we should create RebarShapeDefinitionBySegments, and then add the geometry constraints according to trapezoid face. To create multi-planar shape, A RebarShapeMultiplanarDefinition has to be created. Finally, we call static method RebarShape.Create (…) to complete the rebar shape creation.
3.	Create rebars in corbel and its host:
a)	Corbel horizontal straight bars and corbel host vertical bars are created with Rebar.CreateFromCurves. The layout rule was set as fixed number with SetLayoutAsFixedNumber. 
b)	Stirrup bars are create with shape “T1” via method Rebar.CreateFromRebarShape, and the layout rule is set as fixed number with SetLayoutAsFixedNumber. (The stirrup bars filled in the triangular area was placed individually).  Rebar.ScaleToBox is used to place the stirrup bars to a bounding box calculated exactly. 
c)	To create multi-planar bar, the first step is to create the multi-planar shape and then use method Rebar.CreateFromRebarShape to create the rebar. Rebar.ScaleToBoxFor3D () is used to place the multi-planar in given bounding box. The bounding box is calculated according to the trapezoid face. 
4.	Challenges
The challenge of this sample is the location calculation for bars. There are several factors to be considered:
a)	Bar type – it contains the definition of bar model diameter and bend radius. 
b)	Corbel and corbel host cover distance.
c)	Out of plane bend diameter of multi-planar rebar shape.
d)	In this sample, we considered the bar model diameter and cover distance, but we do not consider the bend radius. In other word, we treat each bend radius as zero.

Instructions: 
1.	Set up addin file and let revit load this sample.
2.	Open the sample file “Reinforce Corbels.rvt”.
3.	Select the corbels in the document. It supports rectangular selection; the sample will filter out the corbels in the selection set.
4.	If the selection set contains corbels can be reinforced by this sample, a window will show and let user input simple options. If the selection is not satisfied the criteria, a warning message will tell what has happened.
5.	Click OK button on the window to reinforce the corbels.
6.	Check the rebars created by this sample in revit UI.
7.	End.