here is the full constructor in case needed :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Document = Autodesk.Revit.DB.Document;
namespace Tunnel
{
public class SheetPile
{
double meters = 3.28084;
public SheetPile(Document doc, double x, String PileName, Level Level, TunnelFloors tunnelFloors)
{
Options options = new Options();
Plane plane = Plane.CreateByNormalAndOrigin(new XYZ(0, 0, 1), new XYZ(0, 0, 0));
SketchPlane sketchPlane = SketchPlane.Create(doc, plane);
// Create a new view plan for Level 1
// Get the floor plan view family type
ViewFamilyType viewFamilyType = new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.Cast<ViewFamilyType>()
.FirstOrDefault(v => v.ViewFamily == ViewFamily.StructuralPlan);
// Create a new view plan for Level 1
ViewPlan viewPlan = ViewPlan.Create(doc, viewFamilyType.Id, Level.Id);
// Convert input values from feet to meters
x = x * meters;
// Define the family symbol and structural type
FamilySymbol symbol = new FilteredElementCollector(doc)
.OfClass(typeof(FamilySymbol))
.OfCategory(BuiltInCategory.OST_StructuralColumns)
.FirstOrDefault(e => e.Name == PileName) as FamilySymbol;
StructuralType structuralType = StructuralType.Column;
// Create a list of curves
List<Curve> curves = new List<Curve>();
foreach (Floor floor in tunnelFloors.Floors)
{
Sketch sketch = doc.GetElement(floor.SketchId) as Sketch;
foreach (CurveArray curveArray in sketch.Profile)
{
foreach (Curve curve in curveArray)
{
XYZ p0 = (new XYZ(curve.GetEndPoint(0).X, curve.GetEndPoint(0).Y, 0));
XYZ p1 = (new XYZ(curve.GetEndPoint(1).X, curve.GetEndPoint(1).Y, 0));
Curve c1 = Line.CreateBound(p0, p1);
curves.Add(curve);
}
}
}
foreach (Curve curve in curves)
{
ModelCurve m1 = doc.Create.NewModelCurve(curve, sketchPlane);
// Move the family instance along the curve by the distance variable
double length = curve.Length;
int count = (int)(length / x);
for (int j = 1; j <= count; j++)
{
XYZ point = curve.Evaluate((double)j * x / length, true);
FamilyInstance newPile = doc.Create.NewFamilyInstance(point, symbol, Level, structuralType);
newPile.LookupParameter("Top Level").Set("Level 2");
Reference s = newPile.GetReferenceByName("SS");
// Get the reference plane named "SS" from the family instance
//uidoc.Selection.PickObject(ObjectType.PointOnElement);
doc.Create.NewAlignment(viewPlan, s, curve.Reference);
}
}
}
}
}