public virtual Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Autodesk.Revit.Creation.Application ac
= app.Application.Create;
Transaction transaction = new Transaction( doc );
transaction.Start( "TestWall" );
XYZ[] pts = new XYZ[] {
new XYZ(5.675844469, 8.769334161, -5.537348007),
new XYZ(5.665137820, 8.771332255, 2.956630685),
new XYZ(7.672569880, 8.396698044, 2.959412671),
};
//CurveArray profile = new CurveArray(); // 2012
List<Curve> profile = new List<Curve>( pts.Length ); // 2013
XYZ q = pts[pts.Length - 1];
foreach( XYZ p in pts )
{
//profile.Append( CreateLine( ac, q, p, true ) ); // 2012
//profile.Add( CreateLine( ac, q, p, true ) ); // 2013
profile.Add( Line.CreateBound( q, p ) ); // 2014
q = p;
}
XYZ t1 = pts[0] - pts[1];
XYZ t2 = pts[1] - pts[2];
XYZ normal2 = t1.CrossProduct( t2 );
normal2 = normal2.Normalize();
// Verify this plane is vertical to plane XOY
if( !IsVertical( normal2, XYZ.BasisZ ) )
{
System.Windows.Forms.MessageBox.Show( "not vertical" );
}
SketchPlane sketchPlane = CreateSketchPlane(
doc, normal2, pts[0] );
//CreateModelCurveArray( // 2012
// doc, profile, sketchPlane );
foreach( Curve c in profile ) // 2013
{
doc.Create.NewModelCurve( c, sketchPlane );
}
WallType wallType
= new FilteredElementCollector( doc )
.OfClass( typeof( WallType ) )
.First<Element>() as WallType;
Level level
= new FilteredElementCollector( doc )
.OfClass( typeof( Level ) )
.First<Element>(
e => e.Name.Equals( "Level 1" ) ) as Level;
//Wall wall = doc.Create.NewWall( // 2012
// profile, wallType, level, true, normal2 );
Wall wall = Wall.Create( doc,
profile, wallType.Id, level.Id, true, normal2 );
transaction.Commit();
return Result.Succeeded;
}