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

Subject: Create Rebar and ReabrShapes.
Summary: 
This sample will demonstrate how to create rebar via NewRebar (RebarShape rebarShape, RebarBarType rebarType, Element host, XYZ origin, XYZ xVec, XYZ yVec) and how to customize RebarShape (include straight segment and arc shape).

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.RebarShapeDefinitionByArc
Autodesk.Revit.DB.Structure.RebarShapeDefinitionBySegments
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.

RebarCreator.cs
Class RebarCreator is defined in this file and it wraps the creation of Rebar. Its "Execute" method shows the main dialog for user and after that a Rebar will be created if user click OK button on the main dialog.

RebarShapeDef.cs
Class RebarShapeDef is defined in this file and it wraps RebarShapeDefinition object. It will be inherited by two classes: RebarShapeDefByArc and RebarShapeDefBySegment.

RebarShapeDefByArc.cs
Class RebarShapeDefByArc is defined in this file and it wraps RebarShapeDefinitionByArc object.

RebarShapeDefBySegment.cs
Class RebarShapeDefBySegment is defined in this file and it wraps RebarShapeDefinitionBySegments object.

RebarShapeParameter.cs
Class RebarShapeParameter is defined in this file and it wraps an Autodesk.Revit.Parameter object which will be added to RebarShape definition. This is an abstract class and it will be inherited by two classes: RebarShapeParameterDouble and RebarShapeParameterFormula.

RebarShapeParameterDouble.cs
Class RebarShapeParameterDouble is defined in this file and it wraps a double parameter which will be added to RebarShape definition.

RebarShapeParameterFormula.cs
Class RebarShapeParameterFormula is defined in this file and it wraps a formula parameter which will be added to RebarShape definition.

ConstraintOnRebarShape.cs
Class ConstraintOnRebarShape is defined in this file and it wraps a constraint on Rebar Shape. It will be inherited by two classes: ConstraintOnSegmentShape and ConstraintOnArcShape.

ConstraintOnSegmentShape.cs
This file defines a series of classes which inherits from ConstraintOnSegmentShape. Each one can add a constraint to RebarShapeDefinitionBySegments.

ConstraintOnArcShape.cs
This file defines a series of classes which inherits from ConstraintOnArcShape. Each one can add a constraint to RebarShapeDefinitionByArc.

GeometrySupport.cs
Class GeometrySupport is defined in this file and it can be used to compute and store geometry information.

GeomUtil.cs
Class GeomUtil is defined in this file and it provides the basic geometry operations.

NewRebarForm.cs
This form is the main entrance for user to operate the Rebar creation.

NewRebarShapeForm.cs
This form is provided for user to define a new RebarShape.

AddParameterForm.cs
This form provides an entrance for user to add parameters to RebarShape.

AddConstraintForm.cs
This form provides an entrance for user to add constraints to RebarShape.

Description: 
This sample will demonstrate how to create rebar via NewRebar (RebarShape rebarShape, RebarBarType rebarType, Element host, XYZ origin, XYZ xVec, XYZ yVec) and how to customize RebarShape (include straight segment and arc shape). This sample will cover methods ScaleToBox and SetLayoutRuleWithoutExaminingHost of Rebar and almost all methods and properties of RebarShape. 

Instructions: 
1.	How to create a rebar?
1)	Open or new a Revit project and make sure some concrete Beams or Columns without any rebar and with a rectangular shape are placed. A sample project file NewRebar.rvt is available in the sample’s folder.
2)	Select a concrete Beam or Column without any rebar and with a rectangular shape.
3)	Invoke this command and the main dialog will be shown.
4)	In the main dialog, select a RebarShape and a RebarBarType from the ComboBox, then click OK button, a rebar will be created on the selected Beam or Column.
2.	How to customize a rebar shape by segments?
1)	In the main dialog, give a rebar shape name and click radio Button by segments and input the segments number in the Text Box, then click “Create Rebar Shape” button, a form named “Create RebarShape” will be shown.
2)	In the “Create RebarShape” form, parameters and constraints can be added to customize the rebar shape. Click button “Add parameter” will present a dialog to add parameter and click button “Add Constraint” will present a dialog to add constraint. After that, the parameter or the constraint will be displayed in the property grid, the parameter value and the constraints value can be changed from the property grid.
3)	As for how to add parameters and constraints, here are some advice: 
a)	Each edge must have a length constraint and a direction constraint.
b)	Each vertex must have a bend constraint.
c)	Listening constraints are not necessary.

4)	After parameters and constraints are added, click OK button to submit the customize rebar shape.
 
3.	How to customize a rebar shape by arc?
1)	In the main dialog, give a rebar shape name and click radio Button by arc and select the arc type from the ComboBox, then click “Create rebar shape” button, a form named “Create RebarShape” will be shown.
2)	In the “Create RebarShape” form, parameters and constraints can be added to customize the rebar shape. Click button “Add Parameter” will present a dialog to add parameter and click button “Add Constraint” will present a dialog to add constraint. After that, the parameter or the constraint will be displayed in the property grid, the parameter value and the constraints value can be changed from the property grid.
3)	After parameters and constraints are added, click OK button to submit the customize rebar shape.

Customize Rebar Shapes Step by step:
Under folder “Customize RebarShapes Step by step”, there are four help doc to help user customize Rebar Shapes step by step.