sorry for the late reply I was busy with other work
below the code
public FamilyInstance CreateNewDoor(Document doc, "M_Single-Flush", "Custom Door Type - 2 M", "Level 2", XYZ xyz, Wall wwall, Application app)
{
// LINQ to find the window's FamilySymbol by its type name.
FamilySymbol familySymbol = (from fs in new FilteredElementCollector(doc).
OfClass(typeof(FamilySymbol)).
Cast<FamilySymbol>()
where (fs.Family.Name == fsFamilyName && fs.Name == fsName)
select fs).First();
// LINQ to find the level by its name.
Level level = (from lvl in new FilteredElementCollector(doc).
OfClass(typeof(Level)).
Cast<Level>()
where (lvl.Name == levelName)
select lvl).First();
#region Find the hosting Wall (nearst wall to the insertion point)
#endregion
//Wall wall = null;
//double proximity = (wwall.Location as LocationCurve).Curve.Distance(xyz);
//double distance = double.MaxValue;
//if (proximity < distance)
//{
// distance = proximity;
// wall = wwall;
//}
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Wall));
List<Wall> walls = collector.Cast<Wall>().Where(wl => wl.LevelId == level.Id).ToList();
Wall wall = null;
double distance = double.MaxValue;
foreach (Wall w in walls)
{
double proximity = (w.Location as LocationCurve).Curve.Distance(xyz);
if (proximity < distance)
{
distance = proximity;
wall = w;
}
}
// Create door.
using (Transaction t = new Transaction(doc, "Create Door"))
{
t.Start();
if (!familySymbol.IsActive)
{
// Ensure the family symbol is activated.
familySymbol.Activate();
doc.Regenerate();
}
ViewPlan viewPlan = doc.ActiveView as ViewPlan;
Level nlevel = viewPlan.GenLevel;
XYZ levelPoint = new XYZ(xyz.X, xyz.Y, nlevel.Elevation);
//XYZ nxyz = new XYZ(xyz.X, xyz.Y, level.Elevation);
FamilyInstance door = doc.Create.NewFamilyInstance(levelPoint, familySymbol, wall, StructuralType.NonStructural);
doc.Regenerate();
// Category doorCategory = Category.GetCategory(doc, BuiltInCategory.OST_Doors);
//CreateProjectParameterFromSharedparameterAndAddValue(doc, app, "UnitName", door, "201", doorCategory);
t.Commit();
return door;
}
//string prompt = "The element was created!";
//TaskDialog.Show("Revit", prompt);
}