
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi. I'm new in Revit API.
I wanna create walls on some levels that i set the elevation at levels.
But there is a distance between walls.
I think the elevation is the cause.
How can i fix it?
Here is my code.
[TransactionAttribute(TransactionMode.Manual)]
public class CreateHome : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
//Get Document
Document doc = uidoc.Document;
//
XYZ p1 = new XYZ(-10, -10, 60);
XYZ p2 = new XYZ(10, -10, 60);
XYZ p3 = new XYZ(15, 0, 60);
XYZ p4 = new XYZ(10, 10, 60);
CurveArray lineList = new CurveArray();
List<Curve> curves = new List<Curve>();
Line line1 = Line.CreateBound(p1, p2);
Line line2 = Line.CreateBound(p2, p3);
Line line3 = Line.CreateBound(p3, p4);
Line line4 = Line.CreateBound(p4, p1);
lineList.Append(line1);
lineList.Append(line2);
lineList.Append(line3);
lineList.Append(line4);
curves.Add(line1);
curves.Add(line2);
curves.Add(line3);
curves.Add(line4);
XYZ normal = XYZ.BasisZ;
FilteredElementCollector Beamsymbolcol = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).OfClass(typeof(FloorType));
FloorType ft = null;
foreach (FloorType fs1 in Beamsymbolcol)
{
ft = fs1;
break;
}
try
{
using (Transaction trans = new Transaction(doc, "Place Family"))
{
trans.Start();
int cnt = 1;
double elevation = 0;
for(int i =1; i<=4;i++)
{
string levelName = "Level " + i;
elevation += 20;
Level level = Level.Create(doc, elevation);
level.Name = "Level " + i;
if (null == level)
{
throw new Exception("Create a new level failed.");
}
cnt += 20;
// Change the level name
}
//Level level1 = new FilteredElementCollector(doc)
// .OfCategory(BuiltInCategory.OST_Levels)
// .WhereElementIsNotElementType()
// .Cast<Level>()
// .First(x => x.Name == "Level 1");
FilteredElementCollector levels = new FilteredElementCollector(doc).OfClass(typeof(Level));
foreach (Level level in levels)
{
Floor newFloor = doc.Create.NewFloor(lineList, ft, level, false, normal);
foreach(Curve c in curves)
{
Wall.Create(doc, c, level.Id, false);
}
newFloor.get_Parameter(
BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM).Set(0);
}
//Floor floor = doc.Create.NewFloor(lineList, ft, level1, false, normal);
trans.Commit();
}
Solved! Go to Solution.