### Model Line Creation

In the previous post, we determined the slab boundary polygons and displayed the resulting polygon data graphically for debugging and better understanding by creating model line segments for them in the Revit database. We did not go into any detail about the code to create those model lines, which is an interesting little topic all in itself. It is packaged in a utility class named Creator, since it encapsulates a small subset of the functionality provided by the Autodesk.Revit.Creation namespace. This post presents and discusses this model line creator. Here is the code for it:

```class Creator
{
// these are
// Autodesk.Revit.Creation
// objects!
Application _app;
Document _doc;

public Creator(
Autodesk.Revit.Application app )
{
_app = app.Create;
_doc = app.ActiveDocument.Create;
}

SketchPlane NewSketchPlanePassLine(
Line line )
{
XYZ p = line.get_EndPoint( 0 );
XYZ q = line.get_EndPoint( 1 );
XYZ norm;
if( p.X == q.X )
{
norm = XYZ.BasisX;
}
else if( p.Y == q.Y )
{
norm = XYZ.BasisY;
}
else
{
norm = XYZ.BasisZ;
}
Plane plane = _app.NewPlane(
norm, p );

return _doc.NewSketchPlane( plane );
}

void CreateModelLine( XYZ p, XYZ q )
{
if( p.AlmostEqual( q ) )
{
throw new ArgumentException(
"Expected two different points." );
}
Line line = _app.NewLine( p, q, true );
if( null == line )
{
throw new Exception(
"Geometry line creation failed." );
}
_doc.NewModelCurve( line,
NewSketchPlanePassLine( line ) );
}

public void DrawPolygons(
List<List<XYZ>> loops )
{
XYZ p1 = XYZ.Zero;
XYZ q = XYZ.Zero;
bool first;
foreach( List<XYZ> loop in loops )
{
first = true;
foreach( XYZ p in loop )
{
if( first )
{
p1 = p;
first = false;
}
else
{
CreateModelLine( p, q );
}
q = p;
}
CreateModelLine( q, p1 );
}
}
}
```

This code and the idea to create these kind of model lines for debugging purposes is actually demonstrated by the Revit SDK sample Openings, in its module BoundingBox.cs, which implements the two methods NewSketchPlanePassLine() and NewModelLine(), upon which the methods defined above are based.